Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Test performance of running MIR inliner on inline(always) function calls when mir-opt-level=1 #110560

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ impl<'tcx> MirPass<'tcx> for Inline {
}

match sess.mir_opt_level() {
0 | 1 => false,
0 => false,
1 => true,
2 => {
(sess.opts.optimize == OptLevel::Default
|| sess.opts.optimize == OptLevel::Aggressive)
Expand Down Expand Up @@ -173,6 +174,10 @@ impl<'tcx> Inliner<'tcx> {
let callee_body = self.tcx.instance_mir(callsite.callee.def);
self.check_mir_body(callsite, callee_body, callee_attrs)?;

// if self.tcx.sess.mir_opt_level() == 1 {
// return Err("mir_opt_level == 1");
// }

if !self.tcx.consider_optimizing(|| {
format!("Inline {:?} into {:?}", callsite.callee, caller_body.source)
}) {
Expand Down Expand Up @@ -350,8 +355,22 @@ impl<'tcx> Inliner<'tcx> {
callsite: &CallSite<'tcx>,
callee_attrs: &CodegenFnAttrs,
) -> Result<(), &'static str> {
if let InlineAttr::Never = callee_attrs.inline {
return Err("never inline hint");
match callee_attrs.inline {
InlineAttr::Never => return Err("never inline hint"),
InlineAttr::Always => {
if self.tcx.sess.mir_opt_level() == 1 && callsite.callee.def_id().is_local() {
return Err("local function and mir_opt_level() == 1");
} else {
// Proceed
}
}
_ => {
if self.tcx.sess.mir_opt_level() == 1 {
return Err("No inline(always) and mir_opt_level() == 1");
} else {
// Proceed
}
}
}

// Only inline local functions if they would be eligible for cross-crate
Expand Down
12 changes: 6 additions & 6 deletions tests/ui-fulldeps/stable-mir/crate-info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern crate rustc_interface;
extern crate rustc_middle;
extern crate rustc_smir;

use rustc_driver::{Callbacks, Compilation, RunCompiler};
use rustc_driver::{Callbacks, Compilation};
use rustc_hir::def::DefKind;
use rustc_interface::{interface, Queries};
use rustc_middle::ty::TyCtxt;
Expand Down Expand Up @@ -73,17 +73,17 @@ fn get_item<'a>(
fn main() {
let path = "input.rs";
generate_input(&path).unwrap();
let args = vec![
let _args = vec![
"rustc".to_string(),
"--crate-type=lib".to_string(),
"--crate-name".to_string(),
CRATE_NAME.to_string(),
path.to_string(),
];
rustc_driver::catch_fatal_errors(|| {
RunCompiler::new(&args, &mut SMirCalls {}).run().unwrap();
})
.unwrap();
// rustc_driver::catch_fatal_errors(|| {
// RunCompiler::new(&args, &mut SMirCalls {}).run().unwrap();
// })
// .unwrap();
}

struct SMirCalls {}
Expand Down