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

Enable MIR inlinig for #[inline(always)] when mir-opt-level=1 #105278

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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to keep the incremental opt-out that existed for opt-level=2. So I think all that should be done here is to move the | 1 to the second match arm.

}

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