1313//!
1414
1515use rustc_index:: bit_set:: BitSet ;
16- use rustc_middle:: {
17- mir:: { visit:: Visitor , * } ,
18- ty:: TyCtxt ,
19- } ;
20- use rustc_mir_dataflow:: { impls:: MaybeTransitiveLiveLocals , Analysis } ;
16+ use rustc_middle:: mir:: * ;
17+ use rustc_middle:: ty:: TyCtxt ;
18+ use rustc_mir_dataflow:: impls:: { borrowed_locals, MaybeTransitiveLiveLocals } ;
19+ use rustc_mir_dataflow:: Analysis ;
2120
2221/// Performs the optimization on the body
2322///
2423/// The `borrowed` set must be a `BitSet` of all the locals that are ever borrowed in this body. It
25- /// can be generated via the [`get_borrowed_locals `] function.
24+ /// can be generated via the [`borrowed_locals `] function.
2625pub fn eliminate < ' tcx > ( tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > , borrowed : & BitSet < Local > ) {
2726 let mut live = MaybeTransitiveLiveLocals :: new ( borrowed)
2827 . into_engine ( tcx, body)
@@ -73,67 +72,6 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, borrowed: &BitS
7372 }
7473}
7574
76- pub fn get_borrowed_locals ( body : & Body < ' _ > ) -> BitSet < Local > {
77- let mut b = BorrowedLocals ( BitSet :: new_empty ( body. local_decls . len ( ) ) ) ;
78- b. visit_body ( body) ;
79- b. 0
80- }
81-
82- struct BorrowedLocals ( BitSet < Local > ) ;
83-
84- impl < ' tcx > Visitor < ' tcx > for BorrowedLocals {
85- fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , loc : Location ) {
86- self . super_rvalue ( rvalue, loc) ;
87- match rvalue {
88- Rvalue :: AddressOf ( _, borrowed_place) | Rvalue :: Ref ( _, _, borrowed_place) => {
89- if !borrowed_place. is_indirect ( ) {
90- self . 0 . insert ( borrowed_place. local ) ;
91- }
92- }
93-
94- Rvalue :: Cast ( ..)
95- | Rvalue :: ShallowInitBox ( ..)
96- | Rvalue :: Use ( ..)
97- | Rvalue :: Repeat ( ..)
98- | Rvalue :: Len ( ..)
99- | Rvalue :: BinaryOp ( ..)
100- | Rvalue :: CheckedBinaryOp ( ..)
101- | Rvalue :: NullaryOp ( ..)
102- | Rvalue :: UnaryOp ( ..)
103- | Rvalue :: Discriminant ( ..)
104- | Rvalue :: Aggregate ( ..)
105- | Rvalue :: ThreadLocalRef ( ..) => { }
106- }
107- }
108-
109- fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , location : Location ) {
110- self . super_terminator ( terminator, location) ;
111-
112- match terminator. kind {
113- TerminatorKind :: Drop { place : dropped_place, .. } => {
114- if !dropped_place. is_indirect ( ) {
115- self . 0 . insert ( dropped_place. local ) ;
116- }
117- }
118-
119- TerminatorKind :: Abort
120- | TerminatorKind :: DropAndReplace { .. }
121- | TerminatorKind :: Assert { .. }
122- | TerminatorKind :: Call { .. }
123- | TerminatorKind :: FalseEdge { .. }
124- | TerminatorKind :: FalseUnwind { .. }
125- | TerminatorKind :: GeneratorDrop
126- | TerminatorKind :: Goto { .. }
127- | TerminatorKind :: Resume
128- | TerminatorKind :: Return
129- | TerminatorKind :: SwitchInt { .. }
130- | TerminatorKind :: Unreachable
131- | TerminatorKind :: Yield { .. }
132- | TerminatorKind :: InlineAsm { .. } => { }
133- }
134- }
135- }
136-
13775pub struct DeadStoreElimination ;
13876
13977impl < ' tcx > MirPass < ' tcx > for DeadStoreElimination {
@@ -142,7 +80,7 @@ impl<'tcx> MirPass<'tcx> for DeadStoreElimination {
14280 }
14381
14482 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
145- let borrowed = get_borrowed_locals ( body) ;
83+ let borrowed = borrowed_locals ( body) ;
14684 eliminate ( tcx, body, & borrowed) ;
14785 }
14886}
0 commit comments