Skip to content

Commit 31d4837

Browse files
authored
[SandboxIR][Bench] SandboxIR creation (#108278)
Adds a benchmark for the overhead of SandboxIR creation.
1 parent 07a7bdc commit 31d4837

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

llvm/benchmarks/SandboxIRBench.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,31 @@ static std::string generateBBWalkIR(unsigned Size) {
8989
return SS.str();
9090
}
9191

92+
template <IR IRTy> static void SBoxIRCreation(benchmark::State &State) {
93+
static_assert(IRTy != IR::LLVM, "Expected SBoxTracking or SBoxNoTracking");
94+
LLVMContext LLVMCtx;
95+
unsigned NumInstrs = State.range(0);
96+
std::unique_ptr<llvm::Module> LLVMM;
97+
std::string IRStr = generateBBWalkIR(NumInstrs);
98+
LLVMM = parseIR(LLVMCtx, IRStr.c_str());
99+
llvm::Function *LLVMF = &*LLVMM->getFunction("foo");
100+
101+
for (auto _ : State) {
102+
State.PauseTiming();
103+
sandboxir::Context Ctx(LLVMCtx);
104+
if constexpr (IRTy == IR::SBoxTracking)
105+
Ctx.save();
106+
State.ResumeTiming();
107+
108+
sandboxir::Function *F = Ctx.createFunction(LLVMF);
109+
benchmark::DoNotOptimize(F);
110+
State.PauseTiming();
111+
if constexpr (IRTy == IR::SBoxTracking)
112+
Ctx.accept();
113+
State.ResumeTiming();
114+
}
115+
}
116+
92117
template <IR IRTy> static void BBWalk(benchmark::State &State) {
93118
LLVMContext LLVMCtx;
94119
sandboxir::Context Ctx(LLVMCtx);
@@ -189,6 +214,16 @@ template <IR IRTy> static void RUOW(benchmark::State &State) {
189214
finalize<IRTy>(Ctx);
190215
}
191216

217+
// Measure the time it takes to create Sandbox IR without/with tracking.
218+
BENCHMARK(SBoxIRCreation<IR::SBoxNoTracking>)
219+
->Args({10})
220+
->Args({100})
221+
->Args({1000});
222+
BENCHMARK(SBoxIRCreation<IR::SBoxTracking>)
223+
->Args({10})
224+
->Args({100})
225+
->Args({1000});
226+
192227
BENCHMARK(GetType<IR::LLVM>);
193228
BENCHMARK(GetType<IR::SBoxNoTracking>);
194229

0 commit comments

Comments
 (0)