Skip to content

Commit 81f385b

Browse files
committed
Make dropTriviallyDeadConstantArrays not quadratic
Only look at the operands of dead constant arrays instead of all constant arrays again.
1 parent d7032bc commit 81f385b

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

llvm/lib/IR/LLVMContextImpl.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "LLVMContextImpl.h"
14+
#include "llvm/ADT/SetVector.h"
1415
#include "llvm/IR/Module.h"
1516
#include "llvm/IR/OptBisect.h"
1617
#include "llvm/IR/Type.h"
@@ -142,18 +143,19 @@ LLVMContextImpl::~LLVMContextImpl() {
142143
}
143144

144145
void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
145-
bool Changed;
146-
do {
147-
Changed = false;
148-
149-
for (auto I = ArrayConstants.begin(), E = ArrayConstants.end(); I != E;) {
150-
auto *C = *I++;
151-
if (C->use_empty()) {
152-
Changed = true;
153-
C->destroyConstant();
146+
SmallSetVector<ConstantArray *, 4> WorkList(ArrayConstants.begin(),
147+
ArrayConstants.end());
148+
149+
while (!WorkList.empty()) {
150+
ConstantArray *C = WorkList.pop_back_val();
151+
if (C->use_empty()) {
152+
for (const Use &Op : C->operands()) {
153+
if (auto *COp = dyn_cast<ConstantArray>(Op))
154+
WorkList.insert(COp);
154155
}
156+
C->destroyConstant();
155157
}
156-
} while (Changed);
158+
}
157159
}
158160

159161
void Module::dropTriviallyDeadConstantArrays() {

0 commit comments

Comments
 (0)