Eliminate MarkVirtRegAliveInBlock recursion.
authorEvan Cheng <evan.cheng@apple.com>
Tue, 8 May 2007 19:00:00 +0000 (19:00 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Tue, 8 May 2007 19:00:00 +0000 (19:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36943 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/LiveVariables.h
lib/CodeGen/LiveVariables.cpp

index 3a5a583c4341640fdf7df0ac6578f60c73a192f2..c1a4f4e88133fb630f6c1f2b58a61c0b99da608b 100644 (file)
@@ -283,6 +283,8 @@ public:
   VarInfo &getVarInfo(unsigned RegIdx);
 
   void MarkVirtRegAliveInBlock(VarInfo &VRInfo, MachineBasicBlock *BB);
+  void MarkVirtRegAliveInBlock(VarInfo &VRInfo, MachineBasicBlock *BB,
+                               std::vector<MachineBasicBlock*> &WorkList);
   void HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,
                         MachineInstr *MI);
 };
index 4afeb28b1a5ecfa6110834b80f02fc426d38c656..9d2d29057d6f72cd2fa8521a481838d911bbd061 100644 (file)
@@ -112,7 +112,8 @@ bool LiveVariables::ModifiesRegister(MachineInstr *MI, unsigned Reg) const {
 }
 
 void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo,
-                                            MachineBasicBlock *MBB) {
+                                            MachineBasicBlock *MBB,
+                                    std::vector<MachineBasicBlock*> &WorkList) {
   unsigned BBNum = MBB->getNumber();
 
   // Check to see if this basic block is one of the killing blocks.  If so,
@@ -131,11 +132,23 @@ void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo,
   // Mark the variable known alive in this bb
   VRInfo.AliveBlocks[BBNum] = true;
 
-  for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(),
-         E = MBB->pred_end(); PI != E; ++PI)
-    MarkVirtRegAliveInBlock(VRInfo, *PI);
+  for (MachineBasicBlock::const_pred_reverse_iterator PI = MBB->pred_rbegin(),
+         E = MBB->pred_rend(); PI != E; ++PI)
+    WorkList.push_back(*PI);
+}
+
+void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo,
+                                            MachineBasicBlock *MBB) {
+  std::vector<MachineBasicBlock*> WorkList;
+  MarkVirtRegAliveInBlock(VRInfo, MBB, WorkList);
+  while (!WorkList.empty()) {
+    MachineBasicBlock *Pred = WorkList.back();
+    WorkList.pop_back();
+    MarkVirtRegAliveInBlock(VRInfo, Pred, WorkList);
+  }
 }
 
+
 void LiveVariables::HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB,
                                      MachineInstr *MI) {
   assert(VRInfo.DefInst && "Register use before def!");