@@ -34,15 +34,19 @@ static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
3434}
3535
3636enum class IR {
37- LLVM,
38- SBox,
37+ LLVM, // /> LLVM IR
38+ SBoxNoTracking, // /> Sandbox IR with tracking disabled
39+ SBoxTracking, // /> Sandbox IR with tracking enabled
3940};
4041// Traits to get llvm::BasicBlock/sandboxir::BasicBlock from IR::LLVM/IR::SBox.
4142template <IR IRTy> struct TypeSelect {};
4243template <> struct TypeSelect <IR::LLVM> {
4344 using BasicBlock = llvm::BasicBlock;
4445};
45- template <> struct TypeSelect <IR::SBox> {
46+ template <> struct TypeSelect <IR::SBoxNoTracking> {
47+ using BasicBlock = sandboxir::BasicBlock;
48+ };
49+ template <> struct TypeSelect <IR::SBoxTracking> {
4650 using BasicBlock = sandboxir::BasicBlock;
4751};
4852
@@ -59,12 +63,22 @@ genIR(std::unique_ptr<llvm::Module> &LLVMM, LLVMContext &LLVMCtx,
5963
6064 sandboxir::Function *F = Ctx.createFunction (LLVMF);
6165 sandboxir::BasicBlock *BB = &*F->begin ();
66+ // Start tracking if we are testing with tracking enabled.
67+ if constexpr (IRTy == IR::SBoxTracking)
68+ Ctx.save ();
69+
6270 if constexpr (IRTy == IR::LLVM)
6371 return LLVMBB;
6472 else
6573 return BB;
6674}
6775
76+ template <IR IRTy> static void finalize (sandboxir::Context &Ctx) {
77+ // Accept changes if we are tracking.
78+ if constexpr (IRTy == IR::SBoxTracking)
79+ Ctx.accept ();
80+ }
81+
6882static std::string generateBBWalkIR (unsigned Size) {
6983 std::stringstream SS;
7084 SS << " define void @foo(i32 %v1, i32 %v2) {\n " ;
@@ -132,6 +146,7 @@ template <IR IRTy> static void RAUW(benchmark::State &State) {
132146 Def1->replaceAllUsesWith (Def2);
133147 Def2->replaceAllUsesWith (Def1);
134148 }
149+ finalize<IRTy>(Ctx);
135150}
136151
137152static std::string generateRUOWIR (unsigned NumOperands) {
@@ -171,18 +186,21 @@ template <IR IRTy> static void RUOW(benchmark::State &State) {
171186 auto *Call = &*It++;
172187 for (auto _ : State)
173188 Call->replaceUsesOfWith (Arg0, Arg1);
189+ finalize<IRTy>(Ctx);
174190}
175191
176192BENCHMARK (GetType<IR::LLVM>);
177- BENCHMARK (GetType<IR::SBox >);
193+ BENCHMARK (GetType<IR::SBoxNoTracking >);
178194
179195BENCHMARK (BBWalk<IR::LLVM>)->Args({1024 });
180- BENCHMARK (BBWalk<IR::SBox >)->Args({1024 });
196+ BENCHMARK (BBWalk<IR::SBoxTracking >)->Args({1024 });
181197
182198BENCHMARK (RAUW<IR::LLVM>)->Args({512 });
183- BENCHMARK (RAUW<IR::SBox>)->Args({512 });
199+ BENCHMARK (RAUW<IR::SBoxNoTracking>)->Args({512 });
200+ BENCHMARK (RAUW<IR::SBoxTracking>)->Args({512 });
184201
185202BENCHMARK (RUOW<IR::LLVM>)->Args({4096 });
186- BENCHMARK (RUOW<IR::SBox>)->Args({4096 });
203+ BENCHMARK (RUOW<IR::SBoxNoTracking>)->Args({4096 });
204+ BENCHMARK (RUOW<IR::SBoxTracking>)->Args({4096 });
187205
188206BENCHMARK_MAIN ();
0 commit comments