Fix rewriting of PHI nodes.
authorOwen Anderson <resistor@mac.com>
Mon, 12 Nov 2007 02:13:07 +0000 (02:13 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 12 Nov 2007 02:13:07 +0000 (02:13 +0000)
Could someone more familiar with machine-level stuff review this for me?

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

include/llvm/CodeGen/BreakCriticalMachineEdge.h

index 743cff3f2b81517c57d97ae0eb1b598ad44cfc35..b8bb2d209c8f04c613a990044f0b56ea05b73c5c 100644 (file)
@@ -52,16 +52,27 @@ MachineBasicBlock* SplitCriticalMachineEdge(MachineBasicBlock* src,
       break;
     }
     
-    // Scan the operands of this branch, replacing any uses of dst with
-    // crit_mbb.
+    // Scan the operands of this branch, finding all uses of this MBB
+    std::vector<unsigned> toRemove;
+    unsigned reg = 0;
     for (unsigned i = 0, e = mii->getNumOperands(); i != e; ++i) {
       MachineOperand & mo = mii->getOperand(i);
       if (mo.isMachineBasicBlock() &&
-          mo.getMachineBasicBlock() == dst) {
-        found_branch = true;
-        mo.setMachineBasicBlock(crit_mbb);
-      }
+          mo.getMachineBasicBlock() == dst)
+        reg = mii->getOperand(i-1).getReg();
+        toRemove.push_back(i-1);
     }
+    
+    // Remove all uses of this MBB
+    for (std::vector<unsigned>::reverse_iterator I = toRemove.rbegin(),
+         E = toRemove.rend(); I != E; ++I) {
+      mii->RemoveOperand(*I+1);
+      mii->RemoveOperand(*I);
+    }
+    
+    // Add a single use corresponding to the new MBB
+    mii->addRegOperand(reg, false);
+    mii->addMachineBasicBlockOperand(crit_mbb);
   }
 
   // TODO: This is tentative. It may be necessary to fix this code. Maybe