add a top-level iteration loop to instcombine. This means that it will never
authorChris Lattner <sabre@nondot.org>
Sat, 3 Mar 2007 02:04:50 +0000 (02:04 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 3 Mar 2007 02:04:50 +0000 (02:04 +0000)
finish without combining something it is capable of.

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

lib/Transforms/Scalar/InstructionCombining.cpp

index 6eefac2033dab070526e3016768674e03823c440..b20ff9711d78f8f6157fe6f5c7af0184c5d3f8df 100644 (file)
@@ -141,6 +141,8 @@ namespace {
 
   public:
     virtual bool runOnFunction(Function &F);
+    
+    bool DoOneIteration(Function &F, unsigned ItNum);
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.addRequired<TargetData>();
@@ -9164,9 +9166,12 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
     AddReachableCodeToWorklist(TI->getSuccessor(i), Visited, IC, TD);
 }
 
-bool InstCombiner::runOnFunction(Function &F) {
+bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
   bool Changed = false;
   TD = &getAnalysis<TargetData>();
+  
+  DEBUG(DOUT << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
+             << F.getNameStr() << "\n");
 
   {
     // Do a depth-first traversal of the function, populate the worklist with
@@ -9295,24 +9300,36 @@ bool InstCombiner::runOnFunction(Function &F) {
         if (isInstructionTriviallyDead(I)) {
           // Make sure we process all operands now that we are reducing their
           // use counts.
-          AddUsesToWorkList(*I);;
+          AddUsesToWorkList(*I);
 
           // Instructions may end up in the worklist more than once.  Erase all
           // occurrences of this instruction.
           RemoveFromWorkList(I);
           I->eraseFromParent();
         } else {
-          AddToWorkList(Result);
-          AddUsersToWorkList(*Result);
+          AddToWorkList(I);
+          AddUsersToWorkList(*I);
         }
       }
       Changed = true;
     }
   }
 
+  assert(WorklistMap.empty() && "Worklist empty, but map not?");
   return Changed;
 }
 
+
+bool InstCombiner::runOnFunction(Function &F) {
+  bool EverMadeChange = false;
+
+  // Iterate while there is work to do.
+  unsigned Iteration = 0;
+  while (DoOneIteration(F, Iteration++)) 
+    EverMadeChange = true;
+  return EverMadeChange;
+}
+
 FunctionPass *llvm::createInstructionCombiningPass() {
   return new InstCombiner();
 }