mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-19 19:44:55 +00:00
Fix problems with empty basic blocks
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5326 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -50,7 +50,7 @@ const PassInfo *PHIEliminationID = X.getPassInfo();
|
|||||||
/// predecessor basic blocks.
|
/// predecessor basic blocks.
|
||||||
///
|
///
|
||||||
bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) {
|
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...
|
return false; // Quick exit for normal case...
|
||||||
|
|
||||||
LiveVariables *LV = getAnalysisToUpdate<LiveVariables>();
|
LiveVariables *LV = getAnalysisToUpdate<LiveVariables>();
|
||||||
@@ -76,7 +76,8 @@ bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) {
|
|||||||
// into the phi node destination.
|
// into the phi node destination.
|
||||||
//
|
//
|
||||||
MachineBasicBlock::iterator AfterPHIsIt = MBB.begin();
|
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);
|
RegInfo->copyRegToReg(MBB, AfterPHIsIt, DestReg, IncomingReg, RC);
|
||||||
|
|
||||||
// Add information to LiveVariables to know that the incoming value is dead
|
// Add information to LiveVariables to know that the incoming value is dead
|
||||||
@@ -108,16 +109,19 @@ bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (HaveNotEmitted) {
|
if (HaveNotEmitted) {
|
||||||
MachineBasicBlock::iterator I = opBlock.end()-1;
|
MachineBasicBlock::iterator I = opBlock.end();
|
||||||
|
if (I != opBlock.begin()) { // Handle empty blocks
|
||||||
// must backtrack over ALL the branches in the previous block
|
|
||||||
while (MII.isTerminatorInstr((*I)->getOpcode()) && I != opBlock.begin())
|
|
||||||
--I;
|
--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
|
// 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
|
// are inserted right in front of it and not in front of a non-branch
|
||||||
if (!MII.isTerminatorInstr((*I)->getOpcode()))
|
if (!MII.isTerminatorInstr((*I)->getOpcode()))
|
||||||
++I;
|
++I;
|
||||||
|
}
|
||||||
|
|
||||||
assert(opVal.isVirtualRegister() &&
|
assert(opVal.isVirtualRegister() &&
|
||||||
"Machine PHI Operands must all be virtual registers!");
|
"Machine PHI Operands must all be virtual registers!");
|
||||||
|
@@ -221,7 +221,7 @@ void PEI::insertPrologEpilogCode(MachineFunction &Fn) {
|
|||||||
const TargetInstrInfo &TII = Fn.getTarget().getInstrInfo();
|
const TargetInstrInfo &TII = Fn.getTarget().getInstrInfo();
|
||||||
for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
|
for (MachineFunction::iterator I = Fn.begin(), E = Fn.end(); I != E; ++I) {
|
||||||
// If last instruction is a return instruction, add an epilogue
|
// 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);
|
Fn.getTarget().getRegisterInfo()->emitEpilogue(Fn, *I);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -572,7 +572,7 @@ void RA::AllocateBasicBlock(MachineBasicBlock &MBB) {
|
|||||||
|
|
||||||
// Rewind the iterator to point to the first flow control instruction...
|
// Rewind the iterator to point to the first flow control instruction...
|
||||||
const TargetInstrInfo &TII = TM->getInstrInfo();
|
const TargetInstrInfo &TII = TM->getInstrInfo();
|
||||||
I = MBB.end()-1;
|
I = MBB.end();
|
||||||
while (I != MBB.begin() && TII.isTerminatorInstr((*(I-1))->getOpcode()))
|
while (I != MBB.begin() && TII.isTerminatorInstr((*(I-1))->getOpcode()))
|
||||||
--I;
|
--I;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user