Skip to content

Commit 7603797

Browse files
PavelKopylakiramenai
authored andcommitted
[EVM] Add an option to pass metadata size
1 parent d3be55e commit 7603797

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

llvm/lib/Target/EVM/EVMConstantUnfolding.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ static cl::opt<unsigned>
7171
CodeSizeLimit("evm-bytecode-sizelimit", cl::Hidden, cl::init(24576),
7272
cl::desc("EVM contract bytecode size limit"));
7373

74+
static cl::opt<unsigned> MetadataSize("evm-metadata-size", cl::Hidden,
75+
cl::init(0),
76+
cl::desc("EVM metadata size"));
77+
7478
namespace {
7579
using InstrsPerLoopDepthTy = SmallVector<SmallVector<MachineInstr *>>;
7680

@@ -626,7 +630,9 @@ static bool runImpl(Module &M, MachineModuleInfo &MMI) {
626630
bool Changed = false;
627631
ConstantUnfolder Unfolder(&M.getContext());
628632

629-
const unsigned ModuleCodeSize = EVM::calculateModuleCodeSize(M, MMI);
633+
// Metadata size is included into the bytecode size.
634+
const unsigned ModuleCodeSize =
635+
EVM::calculateModuleCodeSize(M, MMI) + MetadataSize;
630636

631637
// Collect PUSH instructions to process.
632638
DenseMap<MachineFunction *, std::unique_ptr<LoopDepthInstrCache>>

llvm/test/CodeGen/EVM/constant-unfolding-Oz-fallback.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
; RUN: llc -O3 --debug-only=evm-constant-unfolding -evm-bytecode-sizelimit=80 < %s 2>&1 | FileCheck %s
1+
; RUN: llc -O3 --debug-only=evm-constant-unfolding -evm-metadata-size=16 -evm-bytecode-sizelimit=96 < %s 2>&1 | FileCheck %s
22
; REQUIRES: asserts
33
target datalayout = "E-p:256:256-i256:256:256-S256-a:256:256"
44
target triple = "evm"
55

66
; CHECK: *** Running constant unfolding in the default mode ***
7-
; CHECK-NEXT: *** Initial module size: 136 ***
7+
; CHECK-NEXT: *** Initial module size: 152 ***
88
; CHECK: Checking PUSH32_S i256 35408467139433450592217433187231851964531694900788300625387963629091585785856
99
; CHECK: Checking PUSH27_S i256 52656145834278593348959013841835216134069776894924259991723442175
1010
; CHECK: Skipping identity transformation
1111
; CHECK: Checking PUSH27_S i256 52656145834278593348959013841835216132831836855638879716824317951
1212
; CHECK: Skipping identity transformation
1313

14-
; CHECK: *** Current module size is 111, which still exceeds the limit, falling back to size-minimization mode ***
14+
; CHECK: *** Current module size is 127, which still exceeds the limit, falling back to size-minimization mode ***
1515
; CHECK-NEXT: *** Running constant unfolding in size-minimization mode at loop depth 0 ***
1616

17-
; CHECK: *** Current module size is 111 ***
17+
; CHECK: *** Current module size is 127 ***
1818
; CHECK-NEXT: *** Running constant unfolding in size-minimization mode at loop depth 1 ***
1919
; CHECK: Checking PUSH27_S i256 52656145834278593348959013841835216134069776894924259991723442175
2020

21-
; CHECK: *** Current module size is 103 ***
21+
; CHECK: *** Current module size is 119 ***
2222
; CHECK-NEXT: *** Running constant unfolding in size-minimization mode at loop depth 2 ***
2323
; CHECK: Checking PUSH27_S i256 52656145834278593348959013841835216132831836855638879716824317951
2424

25-
; CHECK: *** Current module size is 95 ***
25+
; CHECK: *** Current module size is 111 ***
2626

2727
define i256 @test(i256 %p) {
2828

0 commit comments

Comments
 (0)