Skip to content

Commit 7df3859

Browse files
committed
perf improvement
1 parent bcb9b0c commit 7df3859

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
323323
return None;
324324
};
325325

326-
let no_expect = self.mir[bb].statements.iter().all(|stmt| {
327-
let is_expect =
328-
if let mir::StatementKind::Intrinsic(box mir::NonDivergingIntrinsic::Expect(..)) =
329-
stmt.kind
330-
{
331-
true
332-
} else {
333-
false
334-
};
335-
!is_expect
336-
});
337-
if no_expect {
326+
if let Some(ref blocks) = self.blocks_with_expect {
327+
if !blocks.contains(bb) {
328+
return None;
329+
}
330+
} else {
338331
return None;
339332
}
340333

@@ -1239,7 +1232,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12391232
debug!("codegen_block({:?}={:?})", bb, data);
12401233

12411234
for statement in &data.statements {
1242-
self.codegen_statement(bx, statement);
1235+
self.codegen_statement(bx, bb, statement);
12431236
}
12441237

12451238
let merging_succ = self.codegen_terminator(bx, bb, data.terminator());

compiler/rustc_codegen_ssa/src/mir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
110110

111111
/// Caller location propagated if this function has `#[track_caller]`.
112112
caller_location: Option<OperandRef<'tcx, Bx::Value>>,
113+
114+
/// The set of blocks that contain `expect` intrinsics.
115+
blocks_with_expect: Option<Box<BitSet<mir::BasicBlock>>>,
113116
}
114117

115118
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
@@ -207,6 +210,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
207210
debug_context,
208211
per_local_var_debug_info: None,
209212
caller_location: None,
213+
blocks_with_expect: None,
210214
};
211215

212216
// It may seem like we should iterate over `required_consts` to ensure they all successfully

compiler/rustc_codegen_ssa/src/mir/statement.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_index::bit_set::BitSet;
12
use rustc_middle::mir;
23
use rustc_middle::mir::NonDivergingIntrinsic;
34
use rustc_session::config::OptLevel;
@@ -8,7 +9,12 @@ use crate::traits::*;
89

910
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1011
#[instrument(level = "debug", skip(self, bx))]
11-
pub fn codegen_statement(&mut self, bx: &mut Bx, statement: &mir::Statement<'tcx>) {
12+
pub fn codegen_statement(
13+
&mut self,
14+
bx: &mut Bx,
15+
bb: mir::BasicBlock,
16+
statement: &mir::Statement<'tcx>,
17+
) {
1218
self.set_debug_loc(bx, statement.source_info);
1319
match statement.kind {
1420
mir::StatementKind::Assign(box (ref place, ref rvalue)) => {
@@ -75,7 +81,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
7581
}
7682
// The Expect intrinsic is processed with the BB terminator
7783
// in codegen_switchint_terminator()
78-
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Expect(..)) => {}
84+
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::Expect(..)) => {
85+
if !self.blocks_with_expect.is_some() {
86+
self.blocks_with_expect =
87+
Some(Box::new(BitSet::new_empty(self.mir.basic_blocks.len())));
88+
}
89+
self.blocks_with_expect.as_mut().unwrap().insert(bb);
90+
}
7991
mir::StatementKind::Intrinsic(box NonDivergingIntrinsic::CopyNonOverlapping(
8092
mir::CopyNonOverlapping { ref count, ref src, ref dst },
8193
)) => {

0 commit comments

Comments
 (0)