[SandboxIR][Bench] SandboxIR creation (#108278)
Adds a benchmark for the overhead of SandboxIR creation.
This commit is contained in:
parent
07a7bdc806
commit
31d4837273
@ -89,6 +89,31 @@ static std::string generateBBWalkIR(unsigned Size) {
|
||||
return SS.str();
|
||||
}
|
||||
|
||||
template <IR IRTy> static void SBoxIRCreation(benchmark::State &State) {
|
||||
static_assert(IRTy != IR::LLVM, "Expected SBoxTracking or SBoxNoTracking");
|
||||
LLVMContext LLVMCtx;
|
||||
unsigned NumInstrs = State.range(0);
|
||||
std::unique_ptr<llvm::Module> LLVMM;
|
||||
std::string IRStr = generateBBWalkIR(NumInstrs);
|
||||
LLVMM = parseIR(LLVMCtx, IRStr.c_str());
|
||||
llvm::Function *LLVMF = &*LLVMM->getFunction("foo");
|
||||
|
||||
for (auto _ : State) {
|
||||
State.PauseTiming();
|
||||
sandboxir::Context Ctx(LLVMCtx);
|
||||
if constexpr (IRTy == IR::SBoxTracking)
|
||||
Ctx.save();
|
||||
State.ResumeTiming();
|
||||
|
||||
sandboxir::Function *F = Ctx.createFunction(LLVMF);
|
||||
benchmark::DoNotOptimize(F);
|
||||
State.PauseTiming();
|
||||
if constexpr (IRTy == IR::SBoxTracking)
|
||||
Ctx.accept();
|
||||
State.ResumeTiming();
|
||||
}
|
||||
}
|
||||
|
||||
template <IR IRTy> static void BBWalk(benchmark::State &State) {
|
||||
LLVMContext LLVMCtx;
|
||||
sandboxir::Context Ctx(LLVMCtx);
|
||||
@ -189,6 +214,16 @@ template <IR IRTy> static void RUOW(benchmark::State &State) {
|
||||
finalize<IRTy>(Ctx);
|
||||
}
|
||||
|
||||
// Measure the time it takes to create Sandbox IR without/with tracking.
|
||||
BENCHMARK(SBoxIRCreation<IR::SBoxNoTracking>)
|
||||
->Args({10})
|
||||
->Args({100})
|
||||
->Args({1000});
|
||||
BENCHMARK(SBoxIRCreation<IR::SBoxTracking>)
|
||||
->Args({10})
|
||||
->Args({100})
|
||||
->Args({1000});
|
||||
|
||||
BENCHMARK(GetType<IR::LLVM>);
|
||||
BENCHMARK(GetType<IR::SBoxNoTracking>);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user