@@ -31,36 +31,20 @@ static bool shouldAlwaysKeep(const Instruction &I) {
31
31
// / accordingly. It also removes allocations of out-of-chunk arguments.
32
32
static void extractInstrFromModule (Oracle &O, ReducerWorkItem &WorkItem) {
33
33
Module &Program = WorkItem.getModule ();
34
- std::vector<Instruction *> InitInstToKeep;
35
34
36
- for (auto &F : Program)
35
+ for (auto &F : Program) {
37
36
for (auto &BB : F) {
38
37
// Removing the terminator would make the block invalid. Only iterate over
39
38
// instructions before the terminator.
40
- InitInstToKeep.push_back (BB.getTerminator ());
41
- for (auto &Inst : make_range (BB.begin (), std::prev (BB.end ()))) {
42
- if (shouldAlwaysKeep (Inst) || O.shouldKeep ())
43
- InitInstToKeep.push_back (&Inst);
44
- }
45
- }
46
-
47
- // We create a vector first, then convert it to a set, so that we don't have
48
- // to pay the cost of rebalancing the set frequently if the order we insert
49
- // the elements doesn't match the order they should appear inside the set.
50
- std::set<Instruction *> InstToKeep (InitInstToKeep.begin (),
51
- InitInstToKeep.end ());
52
-
53
- std::vector<Instruction *> InstToDelete;
54
- for (auto &F : Program)
55
- for (auto &BB : F)
56
- for (auto &Inst : BB)
57
- if (!InstToKeep.count (&Inst)) {
39
+ for (auto &Inst :
40
+ make_early_inc_range (make_range (BB.begin (), std::prev (BB.end ())))) {
41
+ if (!shouldAlwaysKeep (Inst) && !O.shouldKeep ()) {
58
42
Inst.replaceAllUsesWith (getDefaultValue (Inst.getType ()));
59
- InstToDelete. push_back (&Inst );
43
+ Inst. eraseFromParent ( );
60
44
}
61
-
62
- for ( auto &I : InstToDelete)
63
- I-> eraseFromParent ();
45
+ }
46
+ }
47
+ }
64
48
}
65
49
66
50
void llvm::reduceInstructionsDeltaPass (TestRunner &Test) {
0 commit comments