OSDN Git Service

[unroll] Don't use a map from pointer to bool. Use a set.
authorChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 00:29:39 +0000 (00:29 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Fri, 13 Feb 2015 00:29:39 +0000 (00:29 +0000)
This is much more efficient. In particular, the query with the user
instruction has to insert a false for every missing instruction into the
set. This is just a cleanup a long the way to fixing the underlying
algorithm problems here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228994 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopUnrollPass.cpp

index a575c45..feebf1a 100644 (file)
@@ -499,12 +499,12 @@ public:
   unsigned estimateNumberOfDeadInsns() {
     NumberOfOptimizedInstructions = 0;
     SmallVector<Instruction *, 8> Worklist;
-    DenseMap<Instruction *, bool> DeadInstructions;
+    SmallPtrSet<Instruction *, 16> DeadInstructions;
     // Start by initializing worklist with simplified instructions.
     for (auto Folded : SimplifiedValues) {
       if (auto FoldedInsn = dyn_cast<Instruction>(Folded.first)) {
         Worklist.push_back(FoldedInsn);
-        DeadInstructions[FoldedInsn] = true;
+        DeadInstructions.insert(FoldedInsn);
       }
     }
     // If a definition of an insn is only used by simplified or dead
@@ -523,7 +523,7 @@ public:
           bool AllUsersFolded = true;
           for (auto U : I->users()) {
             Instruction *UI = dyn_cast<Instruction>(U);
-            if (!SimplifiedValues[UI] && !DeadInstructions[UI]) {
+            if (!SimplifiedValues[UI] && !DeadInstructions.count(UI)) {
               AllUsersFolded = false;
               break;
             }
@@ -531,7 +531,7 @@ public:
           if (AllUsersFolded) {
             NumberOfOptimizedInstructions += TTI.getUserCost(I);
             Worklist.push_back(I);
-            DeadInstructions[I] = true;
+            DeadInstructions.insert(I);
           }
         }
       }