Add pass to ensure predecessors cache is generated after optimization
This commit is contained in:
parent
f534d9f8c4
commit
2b31456068
3 changed files with 20 additions and 15 deletions
|
|
@ -207,27 +207,14 @@ impl<'tcx> Body<'tcx> {
|
|||
}
|
||||
|
||||
pub fn basic_block_terminator_opt_mut(&mut self, bb: BasicBlock) -> &mut Option<Terminator<'tcx>> {
|
||||
// FIXME we should look into improving the cache invalidation
|
||||
self.predecessors_cache = None;
|
||||
&mut self.basic_blocks[bb].terminator
|
||||
}
|
||||
|
||||
pub fn basic_block_terminator_mut(&mut self, bb: BasicBlock) -> &mut Terminator<'tcx> {
|
||||
// FIXME we should look into improving the cache invalidation
|
||||
self.predecessors_cache = None;
|
||||
/*
|
||||
let data = &mut self.basic_blocks[bb];
|
||||
if let Some(cache) = self.predecessors_cache.as_mut() {
|
||||
for successor in data.terminator().successors() {
|
||||
let successor_vec = &mut cache[*successor];
|
||||
for i in (0..successor_vec.len()).rev() {
|
||||
if successor_vec[i] == bb {
|
||||
successor_vec.swap_remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
self.basic_blocks[bb].terminator_mut()
|
||||
}
|
||||
|
||||
|
|
@ -245,6 +232,7 @@ impl<'tcx> Body<'tcx> {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
/// This will recompute the predecessors cache if it is not available
|
||||
pub fn predecessors(&mut self) -> &IndexVec<BasicBlock, Vec<BasicBlock>> {
|
||||
if self.predecessors_cache.is_none() {
|
||||
self.predecessors_cache = Some(self.calculate_predecessors())
|
||||
|
|
|
|||
15
src/librustc_mir/transform/ensure_predecessors_cache.rs
Normal file
15
src/librustc_mir/transform/ensure_predecessors_cache.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
use rustc::mir::Body;
|
||||
use rustc::ty::TyCtxt;
|
||||
use crate::transform::{MirPass, MirSource};
|
||||
|
||||
pub struct EnsurePredecessorsCache;
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for EnsurePredecessorsCache {
|
||||
fn run_pass(&self, _: TyCtxt<'tcx>, _: MirSource<'tcx>, body: &mut Body<'tcx>) {
|
||||
// predecessors is lazily calculated. We want to ensure that the cache is properly filled
|
||||
// before the next stages of compilation, since thise following stages will only be allowed
|
||||
// to read the cache and not generate it. If the cache is already up to date, this line is
|
||||
// a nop.
|
||||
let _predecessors = body.predecessors();
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,7 @@ pub mod check_unsafety;
|
|||
pub mod simplify_branches;
|
||||
pub mod simplify_try;
|
||||
pub mod simplify;
|
||||
pub mod ensure_predecessors_cache;
|
||||
pub mod erase_regions;
|
||||
pub mod no_landing_pads;
|
||||
pub mod rustc_peek;
|
||||
|
|
@ -313,6 +314,7 @@ fn run_optimization_passes<'tcx>(
|
|||
&simplify::SimplifyLocals,
|
||||
|
||||
&add_call_guards::CriticalCallEdges,
|
||||
&ensure_predecessors_cache::EnsurePredecessorsCache,
|
||||
&dump_mir::Marker("PreCodegen"),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue