Skip to content

Commit 1c046e5

Browse files
committed
Reimplement standard ConstProp using DataflowConstProp.
1 parent c06b2b9 commit 1c046e5

File tree

92 files changed

+345
-851
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+345
-851
lines changed

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,13 @@ impl<'tcx> PlaceRef<'tcx> {
17461746
}
17471747
}
17481748

1749+
impl From<Local> for PlaceRef<'_> {
1750+
#[inline]
1751+
fn from(local: Local) -> Self {
1752+
PlaceRef { local, projection: &[] }
1753+
}
1754+
}
1755+
17491756
impl Debug for Place<'_> {
17501757
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
17511758
for elem in self.projection.iter().rev() {

compiler/rustc_mir_dataflow/src/value_analysis.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,11 @@ impl Map {
632632
pub fn from_filter<'tcx>(
633633
tcx: TyCtxt<'tcx>,
634634
body: &Body<'tcx>,
635-
filter: impl Fn(Ty<'tcx>) -> bool,
635+
filter: impl Fn(Local) -> bool,
636636
value_limit: Option<usize>,
637637
) -> Self {
638638
let mut map = Self::new();
639-
let exclude = excluded_locals(body);
640-
map.register_with_filter(tcx, body, filter, exclude, value_limit);
639+
map.register_with_filter(tcx, body, filter, value_limit);
641640
debug!("registered {} places ({} nodes in total)", map.value_count, map.places.len());
642641
map
643642
}
@@ -647,16 +646,15 @@ impl Map {
647646
&mut self,
648647
tcx: TyCtxt<'tcx>,
649648
body: &Body<'tcx>,
650-
filter: impl Fn(Ty<'tcx>) -> bool,
651-
exclude: BitSet<Local>,
649+
filter: impl Fn(Local) -> bool,
652650
value_limit: Option<usize>,
653651
) {
654652
let mut worklist = VecDeque::with_capacity(value_limit.unwrap_or(body.local_decls.len()));
655653

656654
// Start by constructing the places for each bare local.
657655
self.locals = IndexVec::from_elem(None, &body.local_decls);
658656
for (local, decl) in body.local_decls.iter_enumerated() {
659-
if exclude.contains(local) {
657+
if !filter(local) {
660658
continue;
661659
}
662660

@@ -666,7 +664,7 @@ impl Map {
666664
self.locals[local] = Some(place);
667665

668666
// And push the eventual children places to the worklist.
669-
self.register_children(tcx, place, decl.ty, &filter, &mut worklist);
667+
self.register_children(tcx, place, decl.ty, &mut worklist);
670668
}
671669

672670
// `place.elem1.elem2` with type `ty`.
@@ -689,7 +687,7 @@ impl Map {
689687
}
690688

691689
// And push the eventual children places to the worklist.
692-
self.register_children(tcx, place, ty, &filter, &mut worklist);
690+
self.register_children(tcx, place, ty, &mut worklist);
693691
}
694692

695693
// Pre-compute the tree of ValueIndex nested in each PlaceIndex.
@@ -721,19 +719,18 @@ impl Map {
721719
tcx: TyCtxt<'tcx>,
722720
place: PlaceIndex,
723721
ty: Ty<'tcx>,
724-
filter: &impl Fn(Ty<'tcx>) -> bool,
725722
worklist: &mut VecDeque<(PlaceIndex, Option<TrackElem>, TrackElem, Ty<'tcx>)>,
726723
) {
727724
// Allocate a value slot if it doesn't have one, and the user requested one.
728-
if self.places[place].value_index.is_none() && filter(ty) {
725+
if self.places[place].value_index.is_none() && ty.is_scalar() {
729726
self.places[place].value_index = Some(self.value_count.into());
730727
self.value_count += 1;
731728
}
732729

733730
// For enums, directly create the `Discriminant`, as that's their main use.
734731
if ty.is_enum() {
735732
let discr_ty = ty.discriminant_ty(tcx);
736-
if filter(discr_ty) {
733+
if discr_ty.is_scalar() {
737734
let discr = *self
738735
.projections
739736
.entry((place, TrackElem::Discriminant))

0 commit comments

Comments
 (0)