[llvm-commits] CVS: llvm/lib/Target/X86/InstSelectSimple.cpp

Chris Lattner lattner at cs.uiuc.edu
Mon May 12 09:23:02 PDT 2003


Changes in directory llvm/lib/Target/X86:

InstSelectSimple.cpp updated: 1.95 -> 1.96

---
Log message:

Do not insert multiple initializations for the same value in a PHI node


---
Diffs of the changes:

Index: llvm/lib/Target/X86/InstSelectSimple.cpp
diff -u llvm/lib/Target/X86/InstSelectSimple.cpp:1.95 llvm/lib/Target/X86/InstSelectSimple.cpp:1.96
--- llvm/lib/Target/X86/InstSelectSimple.cpp:1.95	Thu May  8 15:49:25 2003
+++ llvm/lib/Target/X86/InstSelectSimple.cpp	Mon May 12 09:22:21 2003
@@ -493,18 +493,38 @@
 	MBB->insert(MBB->begin()+NumPHIs++, LongPhiMI);
       }
 
+      // PHIValues - Map of blocks to incoming virtual registers.  We use this
+      // so that we only initialize one incoming value for a particular block,
+      // even if the block has multiple entries in the PHI node.
+      //
+      std::map<MachineBasicBlock*, unsigned> PHIValues;
+
       for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
         MachineBasicBlock *PredMBB = MBBMap[PN->getIncomingBlock(i)];
+        unsigned ValReg;
+        std::map<MachineBasicBlock*, unsigned>::iterator EntryIt =
+          PHIValues.lower_bound(PredMBB);
+
+        if (EntryIt != PHIValues.end() && EntryIt->first == PredMBB) {
+          // We already inserted an initialization of the register for this
+          // predecessor.  Recycle it.
+          ValReg = EntryIt->second;
+
+        } else {        
+          // Get the incoming value into a virtual register.  If it is not
+          // already available in a virtual register, insert the computation
+          // code into PredMBB
+          //
+          MachineBasicBlock::iterator PI = PredMBB->end();
+          while (PI != PredMBB->begin() &&
+                 TII.isTerminatorInstr((*(PI-1))->getOpcode()))
+            --PI;
+          ValReg = getReg(PN->getIncomingValue(i), PredMBB, PI);
+
+          // Remember that we inserted a value for this PHI for this predecessor
+          PHIValues.insert(EntryIt, std::make_pair(PredMBB, ValReg));
+        }
 
-        // Get the incoming value into a virtual register.  If it is not already
-        // available in a virtual register, insert the computation code into
-        // PredMBB
-        //
-	MachineBasicBlock::iterator PI = PredMBB->end();
-	while (PI != PredMBB->begin() &&
-	       TII.isTerminatorInstr((*(PI-1))->getOpcode()))
-	  --PI;
-	unsigned ValReg = getReg(PN->getIncomingValue(i), PredMBB, PI);
 	PhiMI->addRegOperand(ValReg);
         PhiMI->addMachineBasicBlockOperand(PredMBB);
 	if (LongPhiMI) {





More information about the llvm-commits mailing list