Skip to content

Commit d6ac8bb

Browse files
committed
perf improvement
1 parent 3a0d6cd commit d6ac8bb

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

@@ -1234,7 +1227,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12341227
debug!("codegen_block({:?}={:?})", bb, data);
12351228

12361229
for statement in &data.statements {
1237-
self.codegen_statement(bx, statement);
1230+
self.codegen_statement(bx, bb, statement);
12381231
}
12391232

12401233
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

@@ -7,7 +8,12 @@ use crate::traits::*;
78

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

0 commit comments

Comments
 (0)