Skip to content

Commit 3e9e231

Browse files
PavelKopylakiramenai
authored andcommitted
[EVM] ConstantUnfolding: add fallback to size optimization mode when module bytecode exceeds the 24KB limit
Key changes introduced: - Transitioned from a MachineFunction pass to a Module-level pass - Implemented module-wide code size estimation (not 100% exact but sufficiently accurate for our purpose) - Applied transformations by iterating over functions within the module. For each function: - Handled both loop and non-loop basic blocks using the default heuristic (i.e., based on the presence of the OptSize attribute) - If the module size exceeds the defined limit, switched to a fallback mode that treats all functions as if they have OptSize flag. - Repeatedly traversed all functions, targeting only basic blocks at a specific loop nesting depth (starting from depth 0 for non-loop blocks), and re-evaluated module size. The process stops once the size drops below the limit, or reaching the loop depth limit. This enables a balanced distribution of runtime gas regressions across functions within the module, resulting from aggressive constant unfolding.
1 parent 46d99a0 commit 3e9e231

File tree

11 files changed

+550
-329
lines changed

11 files changed

+550
-329
lines changed

llvm/lib/Target/EVM/EVM.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,8 @@ namespace EVMCOST {
4242
unsigned constexpr SWAP = 3;
4343
unsigned constexpr DUP = 3;
4444
unsigned constexpr POP = 2;
45-
unsigned constexpr PUSH0 = 2;
4645
unsigned constexpr PUSH = 3;
4746
unsigned constexpr MLOAD = 3;
48-
unsigned constexpr SHIFT = 3;
49-
unsigned constexpr ADD = 3;
50-
unsigned constexpr SUB = 3;
51-
unsigned constexpr NOT = 3;
5247
} // namespace EVMCOST
5348

5449
// LLVM IR passes.
@@ -75,7 +70,7 @@ FunctionPass *createEVMBPStackification();
7570
FunctionPass *createEVMLowerJumpUnless();
7671
ModulePass *createEVMFinalizeStackFrames();
7772
ModulePass *createEVMMarkRecursiveFunctionsPass();
78-
FunctionPass *createEVMConstantUnfolding();
73+
ModulePass *createEVMConstantUnfolding();
7974

8075
// PassRegistry initialization declarations.
8176
void initializeEVMCodegenPreparePass(PassRegistry &);

0 commit comments

Comments
 (0)