Skip to content

Commit 362da64

Browse files
authored
[SandboxIR][Bench] Test RAUW (#107440)
1 parent 9df592f commit 362da64

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

llvm/benchmarks/SandboxIRBench.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,40 @@ template <IR IRTy> static void GetType(benchmark::State &State) {
106106
benchmark::DoNotOptimize(I->getType());
107107
}
108108

109+
static std::string generateRAUWIR(unsigned Size) {
110+
std::stringstream SS;
111+
SS << "define void @foo(i32 %v1, i32 %v2) {\n";
112+
SS << " %def1 = add i32 %v1, %v2\n";
113+
SS << " %def2 = add i32 %v1, %v2\n";
114+
for (auto Cnt : seq<unsigned>(0, Size))
115+
SS << " %add" << Cnt << " = add i32 %def1, %def1\n";
116+
SS << "ret void";
117+
SS << "}";
118+
return SS.str();
119+
}
120+
121+
template <IR IRTy> static void RAUW(benchmark::State &State) {
122+
LLVMContext LLVMCtx;
123+
sandboxir::Context Ctx(LLVMCtx);
124+
std::unique_ptr<llvm::Module> LLVMM;
125+
unsigned NumInstrs = State.range(0);
126+
auto *BB = genIR<IRTy>(LLVMM, LLVMCtx, Ctx, generateRAUWIR, NumInstrs);
127+
auto It = BB->begin();
128+
auto *Def1 = &*It++;
129+
auto *Def2 = &*It++;
130+
for (auto _ : State) {
131+
Def1->replaceAllUsesWith(Def2);
132+
Def2->replaceAllUsesWith(Def1);
133+
}
134+
}
135+
109136
BENCHMARK(GetType<IR::LLVM>);
110137
BENCHMARK(GetType<IR::SBox>);
111138

112139
BENCHMARK(BBWalk<IR::LLVM>)->Args({1024});
113140
BENCHMARK(BBWalk<IR::SBox>)->Args({1024});
114141

142+
BENCHMARK(RAUW<IR::LLVM>)->Args({512});
143+
BENCHMARK(RAUW<IR::SBox>)->Args({512});
144+
115145
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)