Skip to content

Commit 3ca86f7

Browse files
committed
[EVM] Move the EVMFinalizeStackFrames pass to the end of the codegen pipeline
This allows other passes to modify or adjust frame indexes before finalization.
1 parent f26f9ce commit 3ca86f7

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

llvm/lib/Target/EVM/EVMCalculateModuleSize.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ static unsigned getInstSize(const MachineInstr &MI,
8989
// already exceeds the cap, so the push width is moot.
9090
Size += TII->get(EVM::PUSH2_S).getSize() + TII->get(EVM::JUMP_S).getSize();
9191
break;
92+
case EVM::PUSH_FRAME:
93+
// Typical frame index offsets can be encoded in a single byte, but to
94+
// be conservative, let’s assume 2 bytes per offset.
95+
LLVM_FALLTHROUGH;
9296
case EVM::PUSH_LABEL:
9397
// We emit PUSH4_S here. The linker usually relaxes it to PUSH2_S,
9498
// since a 16-bit immediate covers the 24,576-byte EVM runtime code cap

llvm/lib/Target/EVM/EVMTargetMachine.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,6 @@ void EVMPassConfig::addPreEmitPass() {
274274
addPass(createEVMOptimizeLiveIntervals());
275275
addPass(createEVMSingleUseExpression());
276276
addPass(createEVMBPStackification());
277-
addPass(&StackSlotColoringID);
278-
addPass(createEVMFinalizeStackFrames());
279277

280278
// Optimize branch instructions after stackification. This is done again
281279
// here, since EVMSplitCriticalEdges may introduce new BBs that could
@@ -289,9 +287,12 @@ void EVMPassConfig::addPreEmitPass() {
289287

290288
void EVMPassConfig::addPreEmitPass2() {
291289
addPass(createEVMLowerJumpUnless());
292-
addPass(createEVMConstantUnfolding());
293-
if (getOptLevel() != CodeGenOptLevel::None)
290+
addPass(&StackSlotColoringID);
291+
if (getOptLevel() != CodeGenOptLevel::None) {
292+
addPass(createEVMConstantUnfolding());
294293
addPass(createEVMPeepholePass());
294+
}
295+
addPass(createEVMFinalizeStackFrames());
295296
}
296297

297298
TargetPassConfig *EVMTargetMachine::createPassConfig(PassManagerBase &PM) {

llvm/test/CodeGen/EVM/O0-pipeline.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,18 @@ target triple = "evm"
6464
; CHECK-NEXT: Live Stack Slot Analysis
6565
; CHECK-NEXT: Machine Block Frequency Analysis
6666
; CHECK-NEXT: EVM backward propagation stackification
67-
; CHECK-NEXT: Stack Slot Coloring
68-
; CHECK-NEXT: EVM finalize stack frames
69-
; CHECK-NEXT: FunctionPass Manager
7067
; CHECK-NEXT: Machine Sanitizer Binary Metadata
7168
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
7269
; CHECK-NEXT: Machine Optimization Remark Emitter
7370
; CHECK-NEXT: Stack Frame Layout Analysis
7471
; CHECK-NEXT: EVM Lower jump_unless
75-
; CHECK-NEXT: EVM constant unfolding
72+
; CHECK-NEXT: Slot index numbering
73+
; CHECK-NEXT: Live Stack Slot Analysis
74+
; CHECK-NEXT: MachineDominator Tree Construction
75+
; CHECK-NEXT: Machine Natural Loop Construction
76+
; CHECK-NEXT: Machine Block Frequency Analysis
77+
; CHECK-NEXT: Stack Slot Coloring
78+
; CHECK-NEXT: EVM finalize stack frames
7679
; CHECK-NEXT: FunctionPass Manager
7780
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
7881
; CHECK-NEXT: Machine Optimization Remark Emitter

llvm/test/CodeGen/EVM/O3-pipeline.ll

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,6 @@ target triple = "evm"
133133
; CHECK-NEXT: Live Stack Slot Analysis
134134
; CHECK-NEXT: Machine Block Frequency Analysis
135135
; CHECK-NEXT: EVM backward propagation stackification
136-
; CHECK-NEXT: Stack Slot Coloring
137-
; CHECK-NEXT: EVM finalize stack frames
138-
; CHECK-NEXT: FunctionPass Manager
139-
; CHECK-NEXT: MachineDominator Tree Construction
140-
; CHECK-NEXT: Machine Natural Loop Construction
141-
; CHECK-NEXT: Machine Block Frequency Analysis
142136
; CHECK-NEXT: Control Flow Optimizer
143137
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
144138
; CHECK-NEXT: Tail Duplication
@@ -147,9 +141,17 @@ target triple = "evm"
147141
; CHECK-NEXT: Machine Optimization Remark Emitter
148142
; CHECK-NEXT: Stack Frame Layout Analysis
149143
; CHECK-NEXT: EVM Lower jump_unless
144+
; CHECK-NEXT: Slot index numbering
145+
; CHECK-NEXT: Live Stack Slot Analysis
146+
; CHECK-NEXT: MachineDominator Tree Construction
147+
; CHECK-NEXT: Machine Natural Loop Construction
148+
; CHECK-NEXT: Machine Block Frequency Analysis
149+
; CHECK-NEXT: Stack Slot Coloring
150150
; CHECK-NEXT: EVM constant unfolding
151151
; CHECK-NEXT: FunctionPass Manager
152152
; CHECK-NEXT: EVM Peephole
153+
; CHECK-NEXT: EVM finalize stack frames
154+
; CHECK-NEXT: FunctionPass Manager
153155
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
154156
; CHECK-NEXT: Machine Optimization Remark Emitter
155157
; CHECK-NEXT: EVM Assembly

llvm/test/CodeGen/EVM/branch-folding-clear-condition.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# RUN: llc -x mir -run-pass=branch-folder < %s | FileCheck %s
2-
# RUN: llc -x mir -start-after=evm-finalize-stack-frames < %s | FileCheck --check-prefix=ASM %s
2+
# RUN: llc -x mir -start-after=evm-backward-propagation-stackification < %s | FileCheck --check-prefix=ASM %s
33

44
# Test that after branch folding, the condition at the top of
55
# the stack is correctly cleared when a conditional branch is removed.

0 commit comments

Comments
 (0)