//===----------------------------------------------------------------------===//
#include "LLVMContextImpl.h"
+#include "llvm/ADT/SetVector.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/OptBisect.h"
#include "llvm/IR/Type.h"
}
void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
- bool Changed;
- do {
- Changed = false;
-
- for (auto I = ArrayConstants.begin(), E = ArrayConstants.end(); I != E;) {
- auto *C = *I++;
- if (C->use_empty()) {
- Changed = true;
- C->destroyConstant();
+ SmallSetVector<ConstantArray *, 4> WorkList(ArrayConstants.begin(),
+ ArrayConstants.end());
+
+ while (!WorkList.empty()) {
+ ConstantArray *C = WorkList.pop_back_val();
+ if (C->use_empty()) {
+ for (const Use &Op : C->operands()) {
+ if (auto *COp = dyn_cast<ConstantArray>(Op))
+ WorkList.insert(COp);
}
+ C->destroyConstant();
}
- } while (Changed);
+ }
}
void Module::dropTriviallyDeadConstantArrays() {