This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
compiler/rustc_mir_transform/src Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ use rustc_middle:: mir:: * ;
2+ use rustc_middle:: ty:: TyCtxt ;
3+ use rustc_session:: config:: OptLevel ;
4+
5+ pub ( super ) struct CopyArgs ;
6+
7+ impl < ' tcx > crate :: MirPass < ' tcx > for CopyArgs {
8+ fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
9+ sess. opts . optimize != OptLevel :: No && sess. opts . incremental . is_none ( )
10+ }
11+
12+ fn run_pass ( & self , _: TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
13+ for ( _, block) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
14+ if let TerminatorKind :: Call { ref mut args, .. } = block. terminator_mut ( ) . kind {
15+ for arg in args {
16+ if let Operand :: Move ( place) = arg. node {
17+ if place. is_indirect ( ) {
18+ continue ;
19+ }
20+ let Some ( local) = place. as_local ( ) else {
21+ continue
22+ } ;
23+ if 1 <= local. index ( ) && local. index ( ) <= body. arg_count {
24+ arg. node = Operand :: Copy ( place) ;
25+ }
26+ }
27+ }
28+ } ;
29+ }
30+ }
31+
32+ fn is_required ( & self ) -> bool {
33+ false
34+ }
35+ }
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ declare_passes! {
127127 // This pass is public to allow external drivers to perform MIR cleanup
128128 pub mod cleanup_post_borrowck : CleanupPostBorrowck ;
129129
130+ mod copy_args : CopyArgs ;
130131 mod copy_prop : CopyProp ;
131132 mod coroutine : StateTransform ;
132133 mod coverage : InstrumentCoverage ;
@@ -725,6 +726,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
725726 & large_enums:: EnumSizeOpt { discrepancy : 128 } ,
726727 // Some cleanup necessary at least for LLVM and potentially other codegen backends.
727728 & add_call_guards:: CriticalCallEdges ,
729+ & copy_args:: CopyArgs ,
728730 // Cleanup for human readability, off by default.
729731 & prettify:: ReorderBasicBlocks ,
730732 & prettify:: ReorderLocals ,
You can’t perform that action at this time.
0 commit comments