Do not clone body for ConstProp.
This commit is contained in:
parent
32fe00ae85
commit
108decec53
1 changed files with 8 additions and 25 deletions
|
@ -94,34 +94,21 @@ impl<'tcx> MirPass<'tcx> for ConstProp {
|
||||||
|
|
||||||
trace!("ConstProp starting for {:?}", def_id);
|
trace!("ConstProp starting for {:?}", def_id);
|
||||||
|
|
||||||
let dummy_body = &Body::new(
|
|
||||||
body.source,
|
|
||||||
(*body.basic_blocks).to_owned(),
|
|
||||||
body.source_scopes.clone(),
|
|
||||||
body.local_decls.clone(),
|
|
||||||
Default::default(),
|
|
||||||
body.arg_count,
|
|
||||||
Default::default(),
|
|
||||||
body.span,
|
|
||||||
body.generator_kind(),
|
|
||||||
body.tainted_by_errors,
|
|
||||||
);
|
|
||||||
|
|
||||||
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
|
// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
|
||||||
// constants, instead of just checking for const-folding succeeding.
|
// constants, instead of just checking for const-folding succeeding.
|
||||||
// That would require a uniform one-def no-mutation analysis
|
// That would require a uniform one-def no-mutation analysis
|
||||||
// and RPO (or recursing when needing the value of a local).
|
// and RPO (or recursing when needing the value of a local).
|
||||||
let mut optimization_finder = ConstPropagator::new(body, dummy_body, tcx);
|
let mut optimization_finder = ConstPropagator::new(body, tcx);
|
||||||
|
|
||||||
// Traverse the body in reverse post-order, to ensure that `FullConstProp` locals are
|
// Traverse the body in reverse post-order, to ensure that `FullConstProp` locals are
|
||||||
// assigned before being read.
|
// assigned before being read.
|
||||||
let rpo = body.basic_blocks.reverse_postorder().to_vec();
|
for &bb in body.basic_blocks.reverse_postorder() {
|
||||||
for bb in rpo {
|
let data = &body.basic_blocks[bb];
|
||||||
let data = &mut body.basic_blocks.as_mut_preserves_cfg()[bb];
|
|
||||||
optimization_finder.visit_basic_block_data(bb, data);
|
optimization_finder.visit_basic_block_data(bb, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
optimization_finder.patch.visit_body_preserves_cfg(body);
|
let mut patch = optimization_finder.patch;
|
||||||
|
patch.visit_body_preserves_cfg(body);
|
||||||
|
|
||||||
trace!("ConstProp done for {:?}", def_id);
|
trace!("ConstProp done for {:?}", def_id);
|
||||||
}
|
}
|
||||||
|
@ -339,11 +326,7 @@ impl<'tcx> ty::layout::HasParamEnv<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
fn new(
|
fn new(body: &'mir Body<'tcx>, tcx: TyCtxt<'tcx>) -> ConstPropagator<'mir, 'tcx> {
|
||||||
body: &Body<'tcx>,
|
|
||||||
dummy_body: &'mir Body<'tcx>,
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
) -> ConstPropagator<'mir, 'tcx> {
|
|
||||||
let def_id = body.source.def_id();
|
let def_id = body.source.def_id();
|
||||||
let args = &GenericArgs::identity_for_item(tcx, def_id);
|
let args = &GenericArgs::identity_for_item(tcx, def_id);
|
||||||
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
||||||
|
@ -374,7 +357,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
|
|
||||||
ecx.push_stack_frame(
|
ecx.push_stack_frame(
|
||||||
Instance::new(def_id, args),
|
Instance::new(def_id, args),
|
||||||
dummy_body,
|
body,
|
||||||
&ret,
|
&ret,
|
||||||
StackPopCleanup::Root { cleanup: false },
|
StackPopCleanup::Root { cleanup: false },
|
||||||
)
|
)
|
||||||
|
@ -390,7 +373,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let patch = Patch::new(tcx);
|
let patch = Patch::new(tcx);
|
||||||
ConstPropagator { ecx, tcx, param_env, local_decls: &dummy_body.local_decls, patch }
|
ConstPropagator { ecx, tcx, param_env, local_decls: &body.local_decls, patch }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
|
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue