[llvm-commits] CVS: llvm/lib/CodeGen/PHIElimination.cpp PrologEpilogInserter.cpp RegAllocLocal.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Jan 16 12:07:01 PST 2003


Changes in directory llvm/lib/CodeGen:

PHIElimination.cpp updated: 1.2 -> 1.3
PrologEpilogInserter.cpp updated: 1.8 -> 1.9
RegAllocLocal.cpp updated: 1.12 -> 1.13

---
Log message:

Fix problems with empty basic blocks


---
Diffs of the changes:

Index: llvm/lib/CodeGen/PHIElimination.cpp
diff -u llvm/lib/CodeGen/PHIElimination.cpp:1.2 llvm/lib/CodeGen/PHIElimination.cpp:1.3
--- llvm/lib/CodeGen/PHIElimination.cpp:1.2	Tue Jan 14 15:58:41 2003
+++ llvm/lib/CodeGen/PHIElimination.cpp	Thu Jan 16 12:06:43 2003
@@ -50,7 +50,7 @@
 /// predecessor basic blocks.
 ///
 bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) {
-  if (MBB.front()->getOpcode() != TargetInstrInfo::PHI)
+  if (MBB.empty() || MBB.front()->getOpcode() != TargetInstrInfo::PHI)
     return false;   // Quick exit for normal case...
 
   LiveVariables *LV = getAnalysisToUpdate<LiveVariables>();
@@ -76,7 +76,8 @@
     // into the phi node destination.
     //
     MachineBasicBlock::iterator AfterPHIsIt = MBB.begin();
-    while ((*AfterPHIsIt)->getOpcode() == TargetInstrInfo::PHI) ++AfterPHIsIt;
+    if (AfterPHIsIt != MBB.end())
+      while ((*AfterPHIsIt)->getOpcode() == TargetInstrInfo::PHI) ++AfterPHIsIt;
     RegInfo->copyRegToReg(MBB, AfterPHIsIt, DestReg, IncomingReg, RC);
 
     // Add information to LiveVariables to know that the incoming value is dead
@@ -108,16 +109,19 @@
         }
 
       if (HaveNotEmitted) {
-        MachineBasicBlock::iterator I = opBlock.end()-1;
-        
-        // must backtrack over ALL the branches in the previous block
-        while (MII.isTerminatorInstr((*I)->getOpcode()) && I != opBlock.begin())
+        MachineBasicBlock::iterator I = opBlock.end();
+        if (I != opBlock.begin()) {  // Handle empty blocks
           --I;
+          // must backtrack over ALL the branches in the previous block
+          while (MII.isTerminatorInstr((*I)->getOpcode()) &&
+                 I != opBlock.begin())
+            --I;
         
-        // move back to the first branch instruction so new instructions
-        // are inserted right in front of it and not in front of a non-branch
-        if (!MII.isTerminatorInstr((*I)->getOpcode()))
-          ++I;
+          // move back to the first branch instruction so new instructions
+          // are inserted right in front of it and not in front of a non-branch
+          if (!MII.isTerminatorInstr((*I)->getOpcode()))
+            ++I;
+        }
 
 	assert(opVal.isVirtualRegister() &&
 	       "Machine PHI Operands must all be virtual registers!");


Index: llvm/lib/CodeGen/PrologEpilogInserter.cpp
diff -u llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.8 llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.9
--- llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.8	Wed Jan 15 20:24:20 2003
+++ llvm/lib/CodeGen/PrologEpilogInserter.cpp	Thu Jan 16 12:06:43 2003
@@ -221,7 +221,7 @@
   const TargetInstrInfo &TII = Fn.getTarget().getInstrInfo();
   for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
     // If last instruction is a return instruction, add an epilogue
-    if (TII.isReturn(I->back()->getOpcode()))
+    if (!I->empty() && TII.isReturn(I->back()->getOpcode()))
       Fn.getTarget().getRegisterInfo()->emitEpilogue(Fn, *I);
   }
 }


Index: llvm/lib/CodeGen/RegAllocLocal.cpp
diff -u llvm/lib/CodeGen/RegAllocLocal.cpp:1.12 llvm/lib/CodeGen/RegAllocLocal.cpp:1.13
--- llvm/lib/CodeGen/RegAllocLocal.cpp:1.12	Tue Jan 14 15:58:41 2003
+++ llvm/lib/CodeGen/RegAllocLocal.cpp	Thu Jan 16 12:06:43 2003
@@ -572,7 +572,7 @@
 
   // Rewind the iterator to point to the first flow control instruction...
   const TargetInstrInfo &TII = TM->getInstrInfo();
-  I = MBB.end()-1;
+  I = MBB.end();
   while (I != MBB.begin() && TII.isTerminatorInstr((*(I-1))->getOpcode()))
     --I;
 





More information about the llvm-commits mailing list