[llvm] 31d4837 - [SandboxIR][Bench] SandboxIR creation (#108278)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 11 15:28:40 PDT 2024


Author: vporpo
Date: 2024-09-11T15:28:37-07:00
New Revision: 31d48372732bc3fd3606aeb9c5cceb7cce739b4e

URL: https://github.com/llvm/llvm-project/commit/31d48372732bc3fd3606aeb9c5cceb7cce739b4e
DIFF: https://github.com/llvm/llvm-project/commit/31d48372732bc3fd3606aeb9c5cceb7cce739b4e.diff

LOG: [SandboxIR][Bench] SandboxIR creation (#108278)

Adds a benchmark for the overhead of SandboxIR creation.

Added: 
    

Modified: 
    llvm/benchmarks/SandboxIRBench.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/benchmarks/SandboxIRBench.cpp b/llvm/benchmarks/SandboxIRBench.cpp
index ca2cab664f91e5..d4601d5f53d07a 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 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>);
 


        


More information about the llvm-commits mailing list