Skip to content

Commit

Permalink
Make MIR inlining costs in build-std independent of config.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmcm committed Jun 23, 2024
1 parent 49d353b commit 2d8caf9
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions compiler/rustc_mir_transform/src/cost_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,20 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {

fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, _location: Location) {
match rvalue {
Rvalue::NullaryOp(NullOp::UbChecks, ..) if !self.tcx.sess.ub_checks() => {
Rvalue::NullaryOp(NullOp::UbChecks, ..)
if self
.tcx
.sess
.opts
.unstable_opts
.inline_mir_preserve_debug
.unwrap_or(!self.tcx.sess.ub_checks()) =>
{
// If this is in optimized MIR it's because it's used later,
// so if we don't need UB checks this session, give a bonus
// here to offset the cost of the call later.
// But if we're building std, give it the bonus regardless of the
// current configuration so we get consistent inlining.
self.bonus += CALL_PENALTY;
}
// These are essentially constants that didn't end up in an Operand,
Expand Down Expand Up @@ -111,12 +121,19 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
}
}
TerminatorKind::Assert { unwind, msg, .. } => {
self.penalty +=
if msg.is_optional_overflow_check() && !self.tcx.sess.overflow_checks() {
INSTR_COST
} else {
CALL_PENALTY
};
self.penalty += if msg.is_optional_overflow_check()
&& self
.tcx
.sess
.opts
.unstable_opts
.inline_mir_preserve_debug
.unwrap_or(!self.tcx.sess.overflow_checks())
{
INSTR_COST
} else {
CALL_PENALTY
};
if let UnwindAction::Cleanup(_) = unwind {
self.penalty += LANDINGPAD_PENALTY;
}
Expand Down

0 comments on commit 2d8caf9

Please sign in to comment.