Skip to content

Commit ca3105c

Browse files
committed
use an iterator when visiting MIR basic blocks
I saw MIR cache invalidation somewhat hot on my profiler when per-BB indexin was used. That shouldn't matter much, but there is no good reason not to use an iterator.
1 parent 85c1027 commit ca3105c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/librustc/mir/visit.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use ty::subst::Substs;
1414
use ty::{ClosureSubsts, Region, Ty};
1515
use mir::*;
1616
use rustc_const_math::ConstUsize;
17-
use rustc_data_structures::indexed_vec::Idx;
1817
use syntax_pos::Span;
1918

2019
// # The MIR Visitor
@@ -260,9 +259,15 @@ macro_rules! make_mir_visitor {
260259

261260
fn super_mir(&mut self,
262261
mir: & $($mutability)* Mir<'tcx>) {
263-
for index in 0..mir.basic_blocks().len() {
264-
let block = BasicBlock::new(index);
265-
self.visit_basic_block_data(block, &$($mutability)* mir[block]);
262+
// for best performance, we want to use an iterator rather
263+
// than a for-loop, to avoid calling Mir::invalidate for
264+
// each basic block.
265+
macro_rules! basic_blocks {
266+
(mut) => (mir.basic_blocks_mut().iter_enumerated_mut());
267+
() => (mir.basic_blocks().iter_enumerated());
268+
};
269+
for (bb, data) in basic_blocks!($($mutability)*) {
270+
self.visit_basic_block_data(bb, data);
266271
}
267272

268273
for scope in &$($mutability)* mir.visibility_scopes {

0 commit comments

Comments
 (0)