[llvm] [SandboxIR][Bench] SandboxIR creation (PR #108278)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 12:52:39 PDT 2024
https://github.com/vporpo updated https://github.com/llvm/llvm-project/pull/108278
>From ae914384ae1298d58fd1750f0679e970fc00647d Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Thu, 5 Sep 2024 12:41:01 -0700
Subject: [PATCH] [SandboxIR][Bench] SandboxIR creation
Adds a benchmark for the overhead of SandboxIR creation.
---
llvm/benchmarks/SandboxIRBench.cpp | 35 ++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/llvm/benchmarks/SandboxIRBench.cpp b/llvm/benchmarks/SandboxIRBench.cpp
index ca2cab664f91e5..923d9ada3b141d 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 <IR IRTy> static void SBoxIRCreation(benchmark::State &State) {
+ static_assert(IRTy != IR::LLVM, "Expected SBox and SBoxTr");
+ 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>);
More information about the llvm-commits
mailing list