diff --git a/llvm/benchmarks/SandboxIRBench.cpp b/llvm/benchmarks/SandboxIRBench.cpp index 633de6db1f5e2..1a7f808af21f2 100644 --- a/llvm/benchmarks/SandboxIRBench.cpp +++ b/llvm/benchmarks/SandboxIRBench.cpp @@ -106,10 +106,40 @@ template 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(0, Size)) + SS << " %add" << Cnt << " = add i32 %def1, %def1\n"; + SS << "ret void"; + SS << "}"; + return SS.str(); +} + +template static void RAUW(benchmark::State &State) { + LLVMContext LLVMCtx; + sandboxir::Context Ctx(LLVMCtx); + std::unique_ptr LLVMM; + unsigned NumInstrs = State.range(0); + auto *BB = genIR(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); BENCHMARK(GetType); BENCHMARK(BBWalk)->Args({1024}); BENCHMARK(BBWalk)->Args({1024}); +BENCHMARK(RAUW)->Args({512}); +BENCHMARK(RAUW)->Args({512}); + BENCHMARK_MAIN();