@@ -5,7 +5,8 @@ use rustc_middle::mir::*;
55use rustc_middle:: ty:: TyCtxt ;
66use tracing:: { debug, instrument} ;
77
8- use crate :: ssa:: SsaLocals ;
8+ use crate :: pass_manager as pm;
9+ use crate :: ssa:: { SsaAnalysis , SsaLocals } ;
910
1011/// Unify locals that copy each other.
1112///
@@ -17,21 +18,39 @@ use crate::ssa::SsaLocals;
1718/// where each of the locals is only assigned once.
1819///
1920/// We want to replace all those locals by `_a`, either copied or moved.
20- pub ( super ) struct CopyProp ;
21+ pub ( super ) enum CopyProp {
22+ Partial ,
23+ Full ,
24+ }
2125
2226impl < ' tcx > crate :: MirPass < ' tcx > for CopyProp {
23- fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
24- sess. mir_opt_level ( ) >= 1
27+ fn name ( & self ) -> & ' static str {
28+ match self {
29+ CopyProp :: Partial => "CopyProp-partial" ,
30+ CopyProp :: Full => "CopyProp" ,
31+ }
32+ }
33+
34+ fn is_enabled ( & self , tcx : TyCtxt < ' tcx > ) -> bool {
35+ match self {
36+ CopyProp :: Partial => {
37+ tcx. sess . mir_opt_level ( ) == 1
38+ && !pm:: should_run_pass ( tcx, & CopyProp :: Full , pm:: Optimizations :: Allowed )
39+ }
40+ CopyProp :: Full => tcx. sess . mir_opt_level ( ) >= 2 ,
41+ }
2542 }
2643
2744 #[ instrument( level = "trace" , skip( self , tcx, body) ) ]
2845 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
2946 debug ! ( def_id = ?body. source. def_id( ) ) ;
3047
3148 let typing_env = body. typing_env ( tcx) ;
32- let ssa = SsaLocals :: new ( tcx, body, typing_env) ;
33- debug ! ( borrowed_locals = ?ssa. borrowed_locals( ) ) ;
34- debug ! ( copy_classes = ?ssa. copy_classes( ) ) ;
49+ let ssa_analysis = match self {
50+ CopyProp :: Partial => SsaAnalysis :: Partial ,
51+ CopyProp :: Full => SsaAnalysis :: Full ,
52+ } ;
53+ let ssa = SsaLocals :: new ( tcx, body, typing_env, ssa_analysis) ;
3554
3655 let mut any_replacement = false ;
3756 let mut storage_to_remove = DenseBitSet :: new_empty ( body. local_decls . len ( ) ) ;
0 commit comments