@@ -111,7 +111,7 @@ class SILGlobalOpt {
111
111
// / function.
112
112
llvm::DenseMap<SILFunction *, unsigned > InitializerCount;
113
113
114
- SmallSILInstructionWorklist< 4 > InstToRemove;
114
+ llvm::SmallVector<SILInstruction *, 4 > InstToRemove;
115
115
llvm::SmallVector<SILGlobalVariable *, 4 > GlobalsToRemove;
116
116
117
117
public:
@@ -868,7 +868,7 @@ bool SILGlobalOpt::tryRemoveGlobalAlloc(SILGlobalVariable *global,
868
868
if (GlobalAddrMap[global].size ())
869
869
return false ;
870
870
871
- InstToRemove.add (alloc);
871
+ InstToRemove.push_back (alloc);
872
872
return true ;
873
873
}
874
874
@@ -888,7 +888,7 @@ bool SILGlobalOpt::tryRemoveGlobalAddr(SILGlobalVariable *global) {
888
888
return false ;
889
889
}
890
890
891
- InstToRemove.add (addr);
891
+ InstToRemove.push_back (addr);
892
892
}
893
893
894
894
return true ;
@@ -901,38 +901,38 @@ bool SILGlobalOpt::tryRemoveUnusedGlobal(SILGlobalVariable *global) {
901
901
if (GlobalVarSkipProcessing.count (global))
902
902
return false ;
903
903
904
- if (GlobalVarSkipProcessing.count (global) || GlobalAddrMap[global].size () ||
905
- GlobalAccessMap[global].size () || GlobalLoadMap[global].size () ||
906
- AllocGlobalStore.count (global) || GlobalVarStore.count (global)) {
907
- SmallVector<SILInstruction *, 4 > deadInsts;
908
- while (!InstToRemove.isEmpty ()) {
909
- auto *inst = InstToRemove.pop_back_val ();
910
- deadInsts.push_back (inst);
911
- }
912
- InstToRemove.addInitialGroup (deadInsts);
904
+ if (AllocGlobalStore.count (global) &&
905
+ std::none_of (InstToRemove.begin (), InstToRemove.end (),
906
+ [=](SILInstruction *inst) {
907
+ return AllocGlobalStore[global] == inst;
908
+ }))
909
+ return false ;
910
+
911
+ if (GlobalVarStore.count (global) &&
912
+ std::none_of (
913
+ InstToRemove.begin (), InstToRemove.end (),
914
+ [=](SILInstruction *inst) { return GlobalVarStore[global] == inst; }))
915
+ return false ;
913
916
914
- for (auto *inst : deadInsts) {
917
+ // If this global is used, check if the user is going to be removed.
918
+ if (GlobalVarSkipProcessing.count (global) || GlobalAddrMap[global].size () ||
919
+ GlobalAccessMap[global].size () || GlobalLoadMap[global].size ()) {
920
+ for (auto *inst : InstToRemove) {
915
921
if (GlobalAddrMap[global].size () &&
916
- ! std::any_of (GlobalAddrMap[global].begin (),
922
+ std::none_of (GlobalAddrMap[global].begin (),
917
923
GlobalAddrMap[global].end (),
918
924
[&inst](SILInstruction *addr) { return inst == addr; }))
919
925
return false ;
920
926
if (GlobalAccessMap[global].size () &&
921
- ! std::any_of (
927
+ std::none_of (
922
928
GlobalAccessMap[global].begin (), GlobalAccessMap[global].end (),
923
929
[&inst](SILInstruction *access) { return inst == access; }))
924
930
return false ;
925
931
if (GlobalLoadMap[global].size () &&
926
- ! std::any_of (GlobalLoadMap[global].begin (),
932
+ std::none_of (GlobalLoadMap[global].begin (),
927
933
GlobalLoadMap[global].end (),
928
934
[&inst](SILInstruction *load) { return inst == load; }))
929
935
return false ;
930
-
931
- if (AllocGlobalStore.count (global) && AllocGlobalStore[global] != inst)
932
- return false ;
933
-
934
- if (GlobalVarStore.count (global) && GlobalVarStore[global] != inst)
935
- return false ;
936
936
}
937
937
}
938
938
@@ -1193,8 +1193,9 @@ bool SILGlobalOpt::run() {
1193
1193
}
1194
1194
1195
1195
// Erase the instructions that we have marked for deletion.
1196
- while (!InstToRemove.isEmpty ()) {
1197
- eraseUsesOfInstruction (InstToRemove.pop_back_val ());
1196
+ for (auto *inst : InstToRemove) {
1197
+ eraseUsesOfInstruction (inst);
1198
+ inst->eraseFromParent ();
1198
1199
}
1199
1200
1200
1201
for (auto &global : Module->getSILGlobals ()) {
0 commit comments