From 7e572eb37f1ddb4c9c165354f48692d4cd66affa Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 7 Dec 2009 03:07:01 +0000 Subject: [PATCH] If BB is empty, insert PHI before end() instead of front(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90744 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineSSAUpdater.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/MachineSSAUpdater.cpp b/lib/CodeGen/MachineSSAUpdater.cpp index b7711f9f8cc..069c3c281f8 100644 --- a/lib/CodeGen/MachineSSAUpdater.cpp +++ b/lib/CodeGen/MachineSSAUpdater.cpp @@ -157,8 +157,9 @@ unsigned MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB) { return SingularValue; // Otherwise, we do need a PHI: insert one now. + MachineBasicBlock::iterator Loc = BB->empty() ? BB->end() : BB->front(); MachineInstr *InsertedPHI = InsertNewDef(TargetInstrInfo::PHI, BB, - BB->front(), VRC, MRI, TII); + Loc, VRC, MRI, TII); // Fill in all the predecessors of the PHI. MachineInstrBuilder MIB(InsertedPHI); @@ -231,7 +232,8 @@ unsigned MachineSSAUpdater::GetValueAtEndOfBlockInternal(MachineBasicBlock *BB){ // that we have a cycle. Handle this by inserting a PHI node and returning // it. When we get back to the first instance of the recursion we will fill // in the PHI node. - MachineInstr *NewPHI = InsertNewDef(TargetInstrInfo::PHI, BB, BB->front(), + MachineBasicBlock::iterator Loc = BB->empty() ? BB->end() : BB->front(); + MachineInstr *NewPHI = InsertNewDef(TargetInstrInfo::PHI, BB, Loc, VRC, MRI,TII); unsigned NewVR = NewPHI->getOperand(0).getReg(); InsertRes.first->second = NewVR; @@ -311,7 +313,8 @@ unsigned MachineSSAUpdater::GetValueAtEndOfBlockInternal(MachineBasicBlock *BB){ // Otherwise, we do need a PHI: insert one now if we don't already have one. MachineInstr *InsertedPHI; if (InsertedVal == 0) { - InsertedPHI = InsertNewDef(TargetInstrInfo::PHI, BB, BB->front(), + MachineBasicBlock::iterator Loc = BB->empty() ? BB->end() : BB->front(); + InsertedPHI = InsertNewDef(TargetInstrInfo::PHI, BB, Loc, VRC, MRI, TII); InsertedVal = InsertedPHI->getOperand(0).getReg(); } else {