Now that we use an ilist of machine instructions, iterators are more robust
authorChris Lattner <sabre@nondot.org>
Mon, 10 May 2004 18:47:18 +0000 (18:47 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 10 May 2004 18:47:18 +0000 (18:47 +0000)
than before.  Because this is the case, we can compute the first non-phi
instruction once when de-phi'ing a block.  This shaves ~4s off of
phielimination of _Z7yyparsev in kimwitu++ from 109s -> 105s.  There are
still much more important gains to come.

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

lib/CodeGen/PHIElimination.cpp

index 180cb6d7935494f9f6366dbe799f24db615b2774..ffde4beaf0a221c12a867f78ff15cc65aa92a75b 100644 (file)
@@ -68,6 +68,13 @@ bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) {
   const TargetInstrInfo &MII = MF.getTarget().getInstrInfo();
   const MRegisterInfo *RegInfo = MF.getTarget().getRegisterInfo();
 
+  // Get an iterator to the first instruction after the last PHI node (this may
+  // allso be the end of the basic block).
+  MachineBasicBlock::iterator AfterPHIsIt = MBB.begin();
+  while (AfterPHIsIt != MBB.end() &&
+         AfterPHIsIt->getOpcode() == TargetInstrInfo::PHI)
+    ++AfterPHIsIt;    // Skip over all of the PHI nodes...
+
   while (MBB.front().getOpcode() == TargetInstrInfo::PHI) {
     // Unlink the PHI node from the basic block... but don't delete the PHI yet
     MachineInstr *MI = MBB.remove(MBB.begin());
@@ -85,15 +92,11 @@ bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) {
     // after any remaining phi nodes) which copies the new incoming register
     // into the phi node destination.
     //
-    MachineBasicBlock::iterator AfterPHIsIt = MBB.begin();
-    while (AfterPHIsIt != MBB.end() &&
-           AfterPHIsIt->getOpcode() == TargetInstrInfo::PHI)
-      ++AfterPHIsIt;    // Skip over all of the PHI nodes...
     RegInfo->copyRegToReg(MBB, AfterPHIsIt, DestReg, IncomingReg, RC);
     
     // Update live variable information if there is any...
     if (LV) {
-      MachineInstr *PHICopy = --AfterPHIsIt;
+      MachineInstr *PHICopy = prior(AfterPHIsIt);
 
       // Add information to LiveVariables to know that the incoming value is
       // killed.  Note that because the value is defined in several places (once