[llvm] [SandboxIR][Bench] Benchmark RUOW (PR #107456)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 12:47:16 PDT 2024
https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/107456
This patch adds a benchmark for ReplaceUsesOfWith().
>From 0b681c6e0eecdbf145a10af339a7f465281dad89 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Wed, 4 Sep 2024 14:50:45 -0700
Subject: [PATCH] [SandboxIR][Bench] Benchmark RUOW
This patch adds a benchmark for ReplaceUsesOfWith().
---
llvm/benchmarks/SandboxIRBench.cpp | 42 ++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/llvm/benchmarks/SandboxIRBench.cpp b/llvm/benchmarks/SandboxIRBench.cpp
index 1a7f808af21f2b..04e32c439d196a 100644
--- a/llvm/benchmarks/SandboxIRBench.cpp
+++ b/llvm/benchmarks/SandboxIRBench.cpp
@@ -133,6 +133,45 @@ template <IR IRTy> static void RAUW(benchmark::State &State) {
}
}
+static std::string generateRUOWIR(unsigned NumOperands) {
+ std::stringstream SS;
+ auto GenOps = [&SS, NumOperands]() {
+ for (auto Cnt : seq<unsigned>(0, NumOperands)) {
+ SS << "i8 %arg" << Cnt;
+ bool IsLast = Cnt + 1 == NumOperands;
+ if (!IsLast)
+ SS << ", ";
+ }
+ };
+
+ SS << "define void @foo(";
+ GenOps();
+ SS << ") {\n";
+
+ SS << " call void @foo(";
+ GenOps();
+ SS << ")\n";
+ SS << "ret void";
+ SS << "}";
+ return SS.str();
+}
+
+template <IR IRTy> static void RUOW(benchmark::State &State) {
+ LLVMContext LLVMCtx;
+ sandboxir::Context Ctx(LLVMCtx);
+ std::unique_ptr<llvm::Module> LLVMM;
+ unsigned NumOperands = State.range(0);
+ auto *BB = genIR<IRTy>(LLVMM, LLVMCtx, Ctx, generateRUOWIR, NumOperands);
+
+ auto It = BB->begin();
+ auto *F = BB->getParent();
+ auto *Arg0 = F->getArg(0);
+ auto *Arg1 = F->getArg(1);
+ auto *Call = &*It++;
+ for (auto _ : State)
+ Call->replaceUsesOfWith(Arg0, Arg1);
+}
+
BENCHMARK(GetType<IR::LLVM>);
BENCHMARK(GetType<IR::SBox>);
@@ -142,4 +181,7 @@ BENCHMARK(BBWalk<IR::SBox>)->Args({1024});
BENCHMARK(RAUW<IR::LLVM>)->Args({512});
BENCHMARK(RAUW<IR::SBox>)->Args({512});
+BENCHMARK(RUOW<IR::LLVM>)->Args({4096});
+BENCHMARK(RUOW<IR::SBox>)->Args({4096});
+
BENCHMARK_MAIN();
More information about the llvm-commits
mailing list