diff --git a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceArguments.cpp @@ -24,7 +24,7 @@ static void replaceFunctionCalls(Function &OldF, Function &NewF, const std::set &ArgIndexesToKeep) { const auto &Users = OldF.users(); - for (auto I = Users.begin(), E = Users.end(); I != E; ) + for (auto I = Users.begin(), E = Users.end(); I != E;) if (auto *CI = dyn_cast(*I++)) { // Skip uses in call instructions where OldF isn't the called function // (e.g. if OldF is an argument of the call). @@ -54,7 +54,7 @@ /// Removes out-of-chunk arguments from functions, and modifies their calls /// accordingly. It also removes allocations of out-of-chunk arguments. static void extractArgumentsFromModule(Oracle &O, Module &Program) { - std::set ArgsToKeep; + std::vector InitArgsToKeep; std::vector Funcs; // Get inside-chunk arguments, as well as their parent function for (auto &F : Program) @@ -62,9 +62,11 @@ Funcs.push_back(&F); for (auto &A : F.args()) if (O.shouldKeep()) - ArgsToKeep.insert(&A); + InitArgsToKeep.push_back(&A); } + std::set ArgsToKeep(InitArgsToKeep.begin(), InitArgsToKeep.end()); + for (auto *F : Funcs) { ValueToValueMapTy VMap; std::vector InstToDelete; diff --git a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp @@ -25,7 +25,7 @@ /// Replaces BB Terminator with one that only contains Chunk BBs static void replaceBranchTerminator(BasicBlock &BB, - std::set BBsToKeep) { + const std::set &BBsToKeep) { auto *Term = BB.getTerminator(); std::vector ChunkSucessors; for (auto *Succ : successors(&BB)) @@ -66,8 +66,9 @@ /// Removes uninteresting BBs from switch, if the default case ends up being /// uninteresting, the switch is replaced with a void return (since it has to be /// replace with something) -static void removeUninterestingBBsFromSwitch(SwitchInst &SwInst, - std::set BBsToKeep) { +static void +removeUninterestingBBsFromSwitch(SwitchInst &SwInst, + const std::set &BBsToKeep) { if (!BBsToKeep.count(SwInst.getDefaultDest())) { auto *FnRetTy = SwInst.getParent()->getParent()->getReturnType(); ReturnInst::Create(SwInst.getContext(), @@ -88,12 +89,14 @@ /// Removes out-of-chunk arguments from functions, and modifies their calls /// accordingly. It also removes allocations of out-of-chunk arguments. static void extractBasicBlocksFromModule(Oracle &O, Module &Program) { - std::set BBsToKeep; + std::vector InitBBsToKeep; for (auto &F : Program) for (auto &BB : F) if (O.shouldKeep()) - BBsToKeep.insert(&BB); + InitBBsToKeep.push_back(&BB); + + std::set BBsToKeep(InitBBsToKeep.begin(), InitBBsToKeep.end()); std::vector BBsToDelete; for (auto &F : Program) diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp @@ -20,10 +20,13 @@ /// Removes all the GVs that aren't inside the desired Chunks. static void extractGVsFromModule(Oracle &O, Module &Program) { // Get GVs inside desired chunks - std::set GVsToKeep; + std::vector InitGVsToKeep; for (auto &GV : Program.globals()) if (O.shouldKeep()) - GVsToKeep.insert(&GV); + InitGVsToKeep.push_back(&GV); + + std::set GVsToKeep(InitGVsToKeep.begin(), + InitGVsToKeep.end()); // Delete out-of-chunk GVs and their uses std::vector ToRemove; diff --git a/llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp b/llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceInstructions.cpp @@ -18,18 +18,21 @@ /// Removes out-of-chunk arguments from functions, and modifies their calls /// accordingly. It also removes allocations of out-of-chunk arguments. static void extractInstrFromModule(Oracle &O, Module &Program) { - std::set InstToKeep; + std::vector InitInstToKeep; for (auto &F : Program) for (auto &BB : F) { // Removing the terminator would make the block invalid. Only iterate over // instructions before the terminator. - InstToKeep.insert(BB.getTerminator()); + InitInstToKeep.push_back(BB.getTerminator()); for (auto &Inst : make_range(BB.begin(), std::prev(BB.end()))) if (O.shouldKeep()) - InstToKeep.insert(&Inst); + InitInstToKeep.push_back(&Inst); } + std::set InstToKeep(InitInstToKeep.begin(), + InitInstToKeep.end()); + std::vector InstToDelete; for (auto &F : Program) for (auto &BB : F)