diff --git a/llvm/benchmarks/SandboxIRBench.cpp b/llvm/benchmarks/SandboxIRBench.cpp index ca2cab664f91..d4601d5f53d0 100644 --- a/llvm/benchmarks/SandboxIRBench.cpp +++ b/llvm/benchmarks/SandboxIRBench.cpp @@ -89,6 +89,31 @@ static std::string generateBBWalkIR(unsigned Size) { return SS.str(); } +template 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 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 static void BBWalk(benchmark::State &State) { LLVMContext LLVMCtx; sandboxir::Context Ctx(LLVMCtx); @@ -189,6 +214,16 @@ template static void RUOW(benchmark::State &State) { finalize(Ctx); } +// Measure the time it takes to create Sandbox IR without/with tracking. +BENCHMARK(SBoxIRCreation) + ->Args({10}) + ->Args({100}) + ->Args({1000}); +BENCHMARK(SBoxIRCreation) + ->Args({10}) + ->Args({100}) + ->Args({1000}); + BENCHMARK(GetType); BENCHMARK(GetType);