Skip to content

Commit 2434235

Browse files
committed
Fix issues with worklist
1 parent b81e47b commit 2434235

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

lib/SILOptimizer/IPO/GlobalOpt.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class SILGlobalOpt {
111111
/// function.
112112
llvm::DenseMap<SILFunction *, unsigned> InitializerCount;
113113

114-
SmallSILInstructionWorklist<4> InstToRemove;
114+
llvm::SmallVector<SILInstruction *, 4> InstToRemove;
115115
llvm::SmallVector<SILGlobalVariable *, 4> GlobalsToRemove;
116116

117117
public:
@@ -868,7 +868,7 @@ bool SILGlobalOpt::tryRemoveGlobalAlloc(SILGlobalVariable *global,
868868
if (GlobalAddrMap[global].size())
869869
return false;
870870

871-
InstToRemove.add(alloc);
871+
InstToRemove.push_back(alloc);
872872
return true;
873873
}
874874

@@ -888,7 +888,7 @@ bool SILGlobalOpt::tryRemoveGlobalAddr(SILGlobalVariable *global) {
888888
return false;
889889
}
890890

891-
InstToRemove.add(addr);
891+
InstToRemove.push_back(addr);
892892
}
893893

894894
return true;
@@ -901,38 +901,38 @@ bool SILGlobalOpt::tryRemoveUnusedGlobal(SILGlobalVariable *global) {
901901
if (GlobalVarSkipProcessing.count(global))
902902
return false;
903903

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;
913916

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) {
915921
if (GlobalAddrMap[global].size() &&
916-
!std::any_of(GlobalAddrMap[global].begin(),
922+
std::none_of(GlobalAddrMap[global].begin(),
917923
GlobalAddrMap[global].end(),
918924
[&inst](SILInstruction *addr) { return inst == addr; }))
919925
return false;
920926
if (GlobalAccessMap[global].size() &&
921-
!std::any_of(
927+
std::none_of(
922928
GlobalAccessMap[global].begin(), GlobalAccessMap[global].end(),
923929
[&inst](SILInstruction *access) { return inst == access; }))
924930
return false;
925931
if (GlobalLoadMap[global].size() &&
926-
!std::any_of(GlobalLoadMap[global].begin(),
932+
std::none_of(GlobalLoadMap[global].begin(),
927933
GlobalLoadMap[global].end(),
928934
[&inst](SILInstruction *load) { return inst == load; }))
929935
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;
936936
}
937937
}
938938

@@ -1193,8 +1193,9 @@ bool SILGlobalOpt::run() {
11931193
}
11941194

11951195
// 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();
11981199
}
11991200

12001201
for (auto &global : Module->getSILGlobals()) {

0 commit comments

Comments
 (0)