[llvm] 81f385b - Make dropTriviallyDeadConstantArrays not quadratic

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 21 07:09:28 PST 2020


Author: Benjamin Kramer
Date: 2020-01-21T16:06:46+01:00
New Revision: 81f385b0c6ea37dd7195a65be162c75bbdef29d2

URL: https://github.com/llvm/llvm-project/commit/81f385b0c6ea37dd7195a65be162c75bbdef29d2
DIFF: https://github.com/llvm/llvm-project/commit/81f385b0c6ea37dd7195a65be162c75bbdef29d2.diff

LOG: Make dropTriviallyDeadConstantArrays not quadratic

Only look at the operands of dead constant arrays instead of all
constant arrays again.

Added: 
    

Modified: 
    llvm/lib/IR/LLVMContextImpl.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index 5f9782714170..ca2ee588d15d 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -11,6 +11,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "LLVMContextImpl.h"
+#include "llvm/ADT/SetVector.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/OptBisect.h"
 #include "llvm/IR/Type.h"
@@ -142,18 +143,19 @@ LLVMContextImpl::~LLVMContextImpl() {
 }
 
 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() {


        


More information about the llvm-commits mailing list