Skip to content

Commit

Permalink
[SandboxIR][Bench] Benchmark RUOW (llvm#107456)
Browse files Browse the repository at this point in the history
This patch adds a benchmark for ReplaceUsesOfWith().
  • Loading branch information
vporpo committed Sep 11, 2024
1 parent 666a3f4 commit bd4e0df
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions llvm/benchmarks/SandboxIRBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,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>);

Expand All @@ -143,4 +182,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();

0 comments on commit bd4e0df

Please sign in to comment.