@@ -5,97 +5,13 @@ use rustc_index::bit_set::SparseBitMatrix;
55use rustc_index:: interval:: IntervalSet ;
66use rustc_index:: interval:: SparseIntervalMatrix ;
77use rustc_index:: Idx ;
8- use rustc_index:: IndexVec ;
9- use rustc_middle:: mir:: { BasicBlock , Body , Location } ;
8+ use rustc_middle:: mir:: { BasicBlock , Location } ;
109use rustc_middle:: ty:: { self , RegionVid } ;
10+ use rustc_mir_dataflow:: points:: { DenseLocationMap , PointIndex } ;
1111use std:: fmt:: Debug ;
1212use std:: rc:: Rc ;
1313
14- use crate :: dataflow:: BorrowIndex ;
15-
16- /// Maps between a `Location` and a `PointIndex` (and vice versa).
17- pub ( crate ) struct RegionValueElements {
18- /// For each basic block, how many points are contained within?
19- statements_before_block : IndexVec < BasicBlock , usize > ,
20-
21- /// Map backward from each point to the basic block that it
22- /// belongs to.
23- basic_blocks : IndexVec < PointIndex , BasicBlock > ,
24-
25- num_points : usize ,
26- }
27-
28- impl RegionValueElements {
29- pub ( crate ) fn new ( body : & Body < ' _ > ) -> Self {
30- let mut num_points = 0 ;
31- let statements_before_block: IndexVec < BasicBlock , usize > = body
32- . basic_blocks
33- . iter ( )
34- . map ( |block_data| {
35- let v = num_points;
36- num_points += block_data. statements . len ( ) + 1 ;
37- v
38- } )
39- . collect ( ) ;
40- debug ! ( "RegionValueElements: statements_before_block={:#?}" , statements_before_block) ;
41- debug ! ( "RegionValueElements: num_points={:#?}" , num_points) ;
42-
43- let mut basic_blocks = IndexVec :: with_capacity ( num_points) ;
44- for ( bb, bb_data) in body. basic_blocks . iter_enumerated ( ) {
45- basic_blocks. extend ( ( 0 ..=bb_data. statements . len ( ) ) . map ( |_| bb) ) ;
46- }
47-
48- Self { statements_before_block, basic_blocks, num_points }
49- }
50-
51- /// Total number of point indices
52- pub ( crate ) fn num_points ( & self ) -> usize {
53- self . num_points
54- }
55-
56- /// Converts a `Location` into a `PointIndex`. O(1).
57- pub ( crate ) fn point_from_location ( & self , location : Location ) -> PointIndex {
58- let Location { block, statement_index } = location;
59- let start_index = self . statements_before_block [ block] ;
60- PointIndex :: new ( start_index + statement_index)
61- }
62-
63- /// Converts a `Location` into a `PointIndex`. O(1).
64- pub ( crate ) fn entry_point ( & self , block : BasicBlock ) -> PointIndex {
65- let start_index = self . statements_before_block [ block] ;
66- PointIndex :: new ( start_index)
67- }
68-
69- /// Return the PointIndex for the block start of this index.
70- pub ( crate ) fn to_block_start ( & self , index : PointIndex ) -> PointIndex {
71- PointIndex :: new ( self . statements_before_block [ self . basic_blocks [ index] ] )
72- }
73-
74- /// Converts a `PointIndex` back to a location. O(1).
75- pub ( crate ) fn to_location ( & self , index : PointIndex ) -> Location {
76- assert ! ( index. index( ) < self . num_points) ;
77- let block = self . basic_blocks [ index] ;
78- let start_index = self . statements_before_block [ block] ;
79- let statement_index = index. index ( ) - start_index;
80- Location { block, statement_index }
81- }
82-
83- /// Sometimes we get point-indices back from bitsets that may be
84- /// out of range (because they round up to the nearest 2^N number
85- /// of bits). Use this function to filter such points out if you
86- /// like.
87- pub ( crate ) fn point_in_range ( & self , index : PointIndex ) -> bool {
88- index. index ( ) < self . num_points
89- }
90- }
91-
92- rustc_index:: newtype_index! {
93- /// A single integer representing a `Location` in the MIR control-flow
94- /// graph. Constructed efficiently from `RegionValueElements`.
95- #[ orderable]
96- #[ debug_format = "PointIndex({})" ]
97- pub struct PointIndex { }
98- }
14+ use crate :: BorrowIndex ;
9915
10016rustc_index:: newtype_index! {
10117 /// A single integer representing a `ty::Placeholder`.
@@ -123,7 +39,7 @@ pub(crate) enum RegionElement {
12339/// an interval matrix storing liveness ranges for each region-vid.
12440pub ( crate ) struct LivenessValues {
12541 /// The map from locations to points.
126- elements : Rc < RegionValueElements > ,
42+ elements : Rc < DenseLocationMap > ,
12743
12844 /// For each region: the points where it is live.
12945 points : SparseIntervalMatrix < RegionVid , PointIndex > ,
@@ -155,9 +71,9 @@ impl LiveLoans {
15571
15672impl LivenessValues {
15773 /// Create an empty map of regions to locations where they're live.
158- pub ( crate ) fn new ( elements : Rc < RegionValueElements > ) -> Self {
74+ pub ( crate ) fn new ( elements : Rc < DenseLocationMap > ) -> Self {
15975 LivenessValues {
160- points : SparseIntervalMatrix :: new ( elements. num_points ) ,
76+ points : SparseIntervalMatrix :: new ( elements. num_points ( ) ) ,
16177 elements,
16278 loans : None ,
16379 }
@@ -298,7 +214,7 @@ impl PlaceholderIndices {
298214/// it would also contain various points from within the function.
299215#[ derive( Clone ) ]
300216pub ( crate ) struct RegionValues < N : Idx > {
301- elements : Rc < RegionValueElements > ,
217+ elements : Rc < DenseLocationMap > ,
302218 placeholder_indices : Rc < PlaceholderIndices > ,
303219 points : SparseIntervalMatrix < N , PointIndex > ,
304220 free_regions : SparseBitMatrix < N , RegionVid > ,
@@ -313,14 +229,14 @@ impl<N: Idx> RegionValues<N> {
313229 /// Each of the regions in num_region_variables will be initialized with an
314230 /// empty set of points and no causal information.
315231 pub ( crate ) fn new (
316- elements : & Rc < RegionValueElements > ,
232+ elements : & Rc < DenseLocationMap > ,
317233 num_universal_regions : usize ,
318234 placeholder_indices : & Rc < PlaceholderIndices > ,
319235 ) -> Self {
320236 let num_placeholders = placeholder_indices. len ( ) ;
321237 Self {
322238 elements : elements. clone ( ) ,
323- points : SparseIntervalMatrix :: new ( elements. num_points ) ,
239+ points : SparseIntervalMatrix :: new ( elements. num_points ( ) ) ,
324240 placeholder_indices : placeholder_indices. clone ( ) ,
325241 free_regions : SparseBitMatrix :: new ( num_universal_regions) ,
326242 placeholders : SparseBitMatrix :: new ( num_placeholders) ,
@@ -486,7 +402,7 @@ impl ToElementIndex for ty::PlaceholderRegion {
486402
487403/// For debugging purposes, returns a pretty-printed string of the given points.
488404pub ( crate ) fn pretty_print_points (
489- elements : & RegionValueElements ,
405+ elements : & DenseLocationMap ,
490406 points : impl IntoIterator < Item = PointIndex > ,
491407) -> String {
492408 pretty_print_region_elements (
0 commit comments