Skip to content

Commit d7e95b0

Browse files
committed
codegen_mir has mir body monomorphized so no need to use mono_reachable logic
1 parent f05ea11 commit d7e95b0

File tree

5 files changed

+5
-47
lines changed

5 files changed

+5
-47
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1318,16 +1318,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
13181318
}
13191319
}
13201320

1321-
pub(crate) fn codegen_block_as_unreachable(&mut self, bb: mir::BasicBlock) {
1322-
let llbb = match self.try_llbb(bb) {
1323-
Some(llbb) => llbb,
1324-
None => return,
1325-
};
1326-
let bx = &mut Bx::build(self.cx, llbb);
1327-
debug!("codegen_block_as_unreachable({:?})", bb);
1328-
bx.unreachable();
1329-
}
1330-
13311321
fn codegen_terminator(
13321322
&mut self,
13331323
bx: &mut Bx,

compiler/rustc_codegen_ssa/src/mir/mod.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
242242
fx.compute_per_local_var_debug_info(&mut start_bx).unzip();
243243
fx.per_local_var_debug_info = per_local_var_debug_info;
244244

245-
let traversal_order = traversal::mono_reachable_reverse_postorder(mir, tcx, instance);
245+
let traversal_order: Vec<_> =
246+
traversal::reverse_postorder(mir).map(|(block, _data)| block).collect();
246247
let memory_locals = analyze::non_ssa_locals(&fx, &traversal_order);
247248

248249
// Allocate variable and temp allocas
@@ -302,20 +303,9 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
302303
// So drop the builder of `start_llbb` to avoid having two at the same time.
303304
drop(start_bx);
304305

305-
let mut unreached_blocks = DenseBitSet::new_filled(mir.basic_blocks.len());
306306
// Codegen the body of each reachable block using our reverse postorder list.
307307
for bb in traversal_order {
308308
fx.codegen_block(bb);
309-
unreached_blocks.remove(bb);
310-
}
311-
312-
// FIXME: These empty unreachable blocks are *mostly* a waste. They are occasionally
313-
// targets for a SwitchInt terminator, but the reimplementation of the mono-reachable
314-
// simplification in SwitchInt lowering sometimes misses cases that
315-
// mono_reachable_reverse_postorder manages to figure out.
316-
// The solution is to do something like post-mono GVN. But for now we have this hack.
317-
for bb in unreached_blocks.iter() {
318-
fx.codegen_block_as_unreachable(bb);
319309
}
320310
}
321311

compiler/rustc_middle/src/mir/basic_blocks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> BasicBlocks<'tcx> {
8080
#[inline]
8181
pub fn reverse_postorder(&self) -> &[BasicBlock] {
8282
self.cache.reverse_postorder.get_or_init(|| {
83-
let mut rpo: Vec<_> = Postorder::new(&self.basic_blocks, START_BLOCK, None).collect();
83+
let mut rpo: Vec<_> = Postorder::new(&self.basic_blocks, START_BLOCK).collect();
8484
rpo.reverse();
8585
rpo
8686
})

compiler/rustc_middle/src/mir/traversal.rs

+1-23
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,17 @@ pub struct Postorder<'a, 'tcx> {
9898
basic_blocks: &'a IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
9999
visited: DenseBitSet<BasicBlock>,
100100
visit_stack: Vec<(BasicBlock, Successors<'a>)>,
101-
/// A non-empty `extra` allows for a precise calculation of the successors.
102-
extra: Option<(TyCtxt<'tcx>, Instance<'tcx>)>,
103101
}
104102

105103
impl<'a, 'tcx> Postorder<'a, 'tcx> {
106104
pub fn new(
107105
basic_blocks: &'a IndexSlice<BasicBlock, BasicBlockData<'tcx>>,
108106
root: BasicBlock,
109-
extra: Option<(TyCtxt<'tcx>, Instance<'tcx>)>,
110107
) -> Postorder<'a, 'tcx> {
111108
let mut po = Postorder {
112109
basic_blocks,
113110
visited: DenseBitSet::new_empty(basic_blocks.len()),
114111
visit_stack: Vec::new(),
115-
extra,
116112
};
117113

118114
po.visit(root);
@@ -126,11 +122,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
126122
return;
127123
}
128124
let data = &self.basic_blocks[bb];
129-
let successors = if let Some(extra) = self.extra {
130-
data.mono_successors(extra.0, extra.1)
131-
} else {
132-
data.terminator().successors()
133-
};
125+
let successors = data.terminator().successors();
134126
self.visit_stack.push((bb, successors));
135127
}
136128

@@ -225,20 +217,6 @@ pub fn postorder<'a, 'tcx>(
225217
reverse_postorder(body).rev()
226218
}
227219

228-
pub fn mono_reachable_reverse_postorder<'a, 'tcx>(
229-
body: &'a Body<'tcx>,
230-
tcx: TyCtxt<'tcx>,
231-
instance: Instance<'tcx>,
232-
) -> Vec<BasicBlock> {
233-
let mut iter = Postorder::new(&body.basic_blocks, START_BLOCK, Some((tcx, instance)));
234-
let mut items = Vec::with_capacity(body.basic_blocks.len());
235-
while let Some(block) = iter.next() {
236-
items.push(block);
237-
}
238-
items.reverse();
239-
items
240-
}
241-
242220
/// Returns an iterator over all basic blocks reachable from the `START_BLOCK` in no particular
243221
/// order.
244222
///

src/tools/clippy/clippy_utils/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn visit_local_usage(locals: &[Local], mir: &Body<'_>, location: Location) -
3030
locals.len()
3131
];
3232

33-
traversal::Postorder::new(&mir.basic_blocks, location.block, None)
33+
traversal::Postorder::new(&mir.basic_blocks, location.block)
3434
.collect::<Vec<_>>()
3535
.into_iter()
3636
.rev()

0 commit comments

Comments
 (0)