[llvm] [SandboxIR][Bench] Test RAUW (PR #107440)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 11:11:08 PDT 2024
https://github.com/vporpo created https://github.com/llvm/llvm-project/pull/107440
None
>From 7672abbabcd61ea056d66169f928d26d08ea4435 Mon Sep 17 00:00:00 2001
From: Vasileios Porpodas <vporpodas at google.com>
Date: Wed, 4 Sep 2024 14:45:55 -0700
Subject: [PATCH] [SandboxIR][Bench] Test RAUW
---
llvm/benchmarks/SandboxIRBench.cpp | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/llvm/benchmarks/SandboxIRBench.cpp b/llvm/benchmarks/SandboxIRBench.cpp
index 633de6db1f5e24..1a7f808af21f2b 100644
--- a/llvm/benchmarks/SandboxIRBench.cpp
+++ b/llvm/benchmarks/SandboxIRBench.cpp
@@ -106,10 +106,40 @@ template <IR IRTy> static void GetType(benchmark::State &State) {
benchmark::DoNotOptimize(I->getType());
}
+static std::string generateRAUWIR(unsigned Size) {
+ std::stringstream SS;
+ SS << "define void @foo(i32 %v1, i32 %v2) {\n";
+ SS << " %def1 = add i32 %v1, %v2\n";
+ SS << " %def2 = add i32 %v1, %v2\n";
+ for (auto Cnt : seq<unsigned>(0, Size))
+ SS << " %add" << Cnt << " = add i32 %def1, %def1\n";
+ SS << "ret void";
+ SS << "}";
+ return SS.str();
+}
+
+template <IR IRTy> static void RAUW(benchmark::State &State) {
+ LLVMContext LLVMCtx;
+ sandboxir::Context Ctx(LLVMCtx);
+ std::unique_ptr<llvm::Module> LLVMM;
+ unsigned NumInstrs = State.range(0);
+ auto *BB = genIR<IRTy>(LLVMM, LLVMCtx, Ctx, generateRAUWIR, NumInstrs);
+ auto It = BB->begin();
+ auto *Def1 = &*It++;
+ auto *Def2 = &*It++;
+ for (auto _ : State) {
+ Def1->replaceAllUsesWith(Def2);
+ Def2->replaceAllUsesWith(Def1);
+ }
+}
+
BENCHMARK(GetType<IR::LLVM>);
BENCHMARK(GetType<IR::SBox>);
BENCHMARK(BBWalk<IR::LLVM>)->Args({1024});
BENCHMARK(BBWalk<IR::SBox>)->Args({1024});
+BENCHMARK(RAUW<IR::LLVM>)->Args({512});
+BENCHMARK(RAUW<IR::SBox>)->Args({512});
+
BENCHMARK_MAIN();
More information about the llvm-commits
mailing list