Auto merge of #110820 - cjgillot:faster-dcp, r=oli-obk
Optimize dataflow-const-prop place-tracking infra Optimization opportunities found while investigating https://github.com/rust-lang/rust/pull/110719 Computing places breadth-first ensures that we create short projections before deep projections, since the former are more likely to be propagated. The most relevant is the pre-computation of flooded places. Callgrind showed `flood_*` methods and especially `preorder_preinvoke` were especially hot. This PR attempts to pre-compute the set of `ValueIndex` that `preorder_invoke` would visit. Using this information, we make some `PlaceIndex` inaccessible when they contain no `ValueIndex`, allowing to skip computations for those places. cc `@jachris` as original author
This commit is contained in:
commit
9a767b6b9e
3 changed files with 183 additions and 141 deletions
|
@ -79,22 +79,22 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
|
|||
&self.map
|
||||
}
|
||||
|
||||
fn handle_statement(&self, statement: &Statement<'tcx>, state: &mut State<Self::Value>) {
|
||||
match statement.kind {
|
||||
StatementKind::SetDiscriminant { box ref place, variant_index } => {
|
||||
state.flood_discr(place.as_ref(), &self.map);
|
||||
if self.map.find_discr(place.as_ref()).is_some() {
|
||||
let enum_ty = place.ty(self.local_decls, self.tcx).ty;
|
||||
if let Some(discr) = self.eval_discriminant(enum_ty, variant_index) {
|
||||
state.assign_discr(
|
||||
place.as_ref(),
|
||||
ValueOrPlace::Value(FlatSet::Elem(discr)),
|
||||
&self.map,
|
||||
);
|
||||
}
|
||||
}
|
||||
fn handle_set_discriminant(
|
||||
&self,
|
||||
place: Place<'tcx>,
|
||||
variant_index: VariantIdx,
|
||||
state: &mut State<Self::Value>,
|
||||
) {
|
||||
state.flood_discr(place.as_ref(), &self.map);
|
||||
if self.map.find_discr(place.as_ref()).is_some() {
|
||||
let enum_ty = place.ty(self.local_decls, self.tcx).ty;
|
||||
if let Some(discr) = self.eval_discriminant(enum_ty, variant_index) {
|
||||
state.assign_discr(
|
||||
place.as_ref(),
|
||||
ValueOrPlace::Value(FlatSet::Elem(discr)),
|
||||
&self.map,
|
||||
);
|
||||
}
|
||||
_ => self.super_statement(statement, state),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,8 +208,8 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
.map(|result| ValueOrPlace::Value(self.wrap_immediate(result, *ty)))
|
||||
.unwrap_or(ValueOrPlace::top()),
|
||||
_ => ValueOrPlace::top(),
|
||||
.unwrap_or(ValueOrPlace::TOP),
|
||||
_ => ValueOrPlace::TOP,
|
||||
},
|
||||
Rvalue::BinaryOp(op, box (left, right)) => {
|
||||
// Overflows must be ignored here.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue