Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions llvm/benchmarks/SandboxIRBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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>);

Expand Down