Skip to content

Commit

Permalink
Enable MIR inlinig for #[inline(always)] when mir-opt-level=1
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm committed Dec 4, 2022
1 parent 0f0d5d7 commit 8ea2dd0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
28 changes: 18 additions & 10 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ impl<'tcx> MirPass<'tcx> for Inline {
return enabled;
}

match sess.mir_opt_level() {
0 | 1 => false,
2 => {
(sess.opts.optimize == OptLevel::Default
|| sess.opts.optimize == OptLevel::Aggressive)
&& sess.opts.incremental == None
}
_ => true,
}
sess.mir_opt_level() > 0
}

fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
Expand Down Expand Up @@ -341,7 +333,23 @@ impl<'tcx> Inliner<'tcx> {
) -> Result<(), &'static str> {
match callee_attrs.inline {
InlineAttr::Never => return Err("never inline hint"),
InlineAttr::Always | InlineAttr::Hint => {}
InlineAttr::Always => {}
InlineAttr::Hint => match self.tcx.sess.mir_opt_level() {
0 | 1 => return Err("at mir-opt-level=1, only #[inline(always)] is inlined"),
2 if self.tcx.sess.opts.optimize != OptLevel::Default
&& self.tcx.sess.opts.optimize != OptLevel::Aggressive =>
{
return Err(
"at mir-opt-level=2, only #[inline(always)] is inlined when opt-level<2",
);
}
2 if self.tcx.sess.opts.incremental != None => {
return Err(
"at mir-opt-level=2, only #[inline(always)] is inlined when incremental compilation is enabled",
);
}
_ => {}
},
InlineAttr::None => {
if self.tcx.sess.mir_opt_level() <= 2 {
return Err("at mir-opt-level=2, only #[inline] is inlined");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// incremental
// compile-flags:-Zprint-mono-items=lazy
// compile-flags:-Zinline-in-all-cgus
// To keep mir from doing any inlining
// compile-flags:-Zmir-opt-level=0

#![crate_type="lib"]

Expand Down
2 changes: 2 additions & 0 deletions src/test/codegen-units/partitioning/local-inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// incremental
// compile-flags:-Zprint-mono-items=lazy
// compile-flags:-Zinline-in-all-cgus
// To keep mir from doing any inlining
// compile-flags:-Zmir-opt-level=0

#![allow(dead_code)]
#![crate_type="lib"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// incremental
// compile-flags:-Zprint-mono-items=lazy
// compile-flags:-Zinline-in-all-cgus
// To keep mir from doing any inlining
// compile-flags:-Zmir-opt-level=0

#![allow(dead_code)]
#![crate_type="rlib"]
Expand Down
2 changes: 2 additions & 0 deletions src/test/incremental/hashes/function_interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// build-pass (FIXME(62277): could be check-pass?)
// revisions: cfail1 cfail2 cfail3 cfail4 cfail5 cfail6
// compile-flags: -Z query-dep-graph -O
// To keep mir from doing any inlining
// compile-flags: -Z mir-opt-level=0
// [cfail1]compile-flags: -Zincremental-ignore-spans
// [cfail2]compile-flags: -Zincremental-ignore-spans
// [cfail3]compile-flags: -Zincremental-ignore-spans
Expand Down

0 comments on commit 8ea2dd0

Please sign in to comment.