Test enabling MIR inliner

This commit is contained in:
Wesley Wiser 2021-09-30 22:03:49 -04:00 committed by Camille GILLOT
parent b33c6e1bd8
commit d1d9092e3c
2 changed files with 24 additions and 11 deletions

View File

@ -9,6 +9,7 @@ use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
use rustc_session::config::OptLevel;
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
use rustc_target::spec::abi::Abi;
@ -43,7 +44,15 @@ impl<'tcx> MirPass<'tcx> for Inline {
return enabled;
}
sess.opts.mir_opt_level() >= 3
match sess.mir_opt_level() {
0 | 1 => false,
2 => {
(sess.opts.optimize == OptLevel::Default
|| sess.opts.optimize == OptLevel::Aggressive)
&& sess.opts.incremental == None
}
_ => true,
}
}
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@ -321,8 +330,14 @@ 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() <= 2 {
return Err("at mir-opt-level=2, only #[inline(always)] is inlined");
}
}
}
// Only inline local functions if they would be eligible for cross-crate
@ -505,14 +520,12 @@ impl<'tcx> Inliner<'tcx> {
if let InlineAttr::Always = callee_attrs.inline {
debug!("INLINING {:?} because inline(always) [cost={}]", callsite, cost);
Ok(())
} else if cost <= threshold {
debug!("INLINING {:?} [cost={} <= threshold={}]", callsite, cost, threshold);
Ok(())
} else {
if cost <= threshold {
debug!("INLINING {:?} [cost={} <= threshold={}]", callsite, cost, threshold);
Ok(())
} else {
debug!("NOT inlining {:?} [cost={} > threshold={}]", callsite, cost, threshold);
Err("cost above threshold")
}
debug!("NOT inlining {:?} [cost={} > threshold={}]", callsite, cost, threshold);
Err("cost above threshold")
}
}

View File

@ -1,5 +1,5 @@
// build-fail
// compile-flags:-Zpolymorphize=on
// compile-flags:-Zpolymorphize=on -Zinline-mir=off
#![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)]
//~^ WARN the feature `generic_const_exprs` is incomplete