diff options
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/MachineBasicBlock.cpp | 12 | ||||
-rw-r--r-- | lib/CodeGen/PHIElimination.cpp | 17 | ||||
-rw-r--r-- | lib/CodeGen/RegAllocLocal.cpp | 6 |
3 files changed, 14 insertions, 21 deletions
diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp index 9d65453edf..89763ba4f3 100644 --- a/lib/CodeGen/MachineBasicBlock.cpp +++ b/lib/CodeGen/MachineBasicBlock.cpp @@ -15,6 +15,8 @@ #include "llvm/BasicBlock.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstr.h" +#include "llvm/Target/TargetInstrInfo.h" +#include "llvm/Target/TargetMachine.h" #include "Support/LeakDetector.h" using namespace llvm; @@ -56,6 +58,16 @@ void ilist_traits<MachineInstr>::transferNodesFromList( first->parent = toList.parent; } +MachineBasicBlock::iterator MachineBasicBlock::getFirstTerminator() +{ + const TargetInstrInfo& TII = MachineFunction::get( + getBasicBlock()->getParent()).getTarget().getInstrInfo(); + iterator I = end(); + while (I != begin() && TII.isTerminatorInstr((--I)->getOpcode())); + if (I != end() && !TII.isTerminatorInstr(I->getOpcode())) ++I; + return I; +} + void MachineBasicBlock::dump() const { print(std::cerr); diff --git a/lib/CodeGen/PHIElimination.cpp b/lib/CodeGen/PHIElimination.cpp index 06305826e8..ea464c9423 100644 --- a/lib/CodeGen/PHIElimination.cpp +++ b/lib/CodeGen/PHIElimination.cpp @@ -143,22 +143,7 @@ bool PNE::EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB) { // source path the PHI. MachineBasicBlock &opBlock = *MI->getOperand(i).getMachineBasicBlock(); - // Figure out where to insert the copy, which is at the end of the - // predecessor basic block, but before any terminator/branch - // instructions... - 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; - } + MachineBasicBlock::iterator I = opBlock.getFirstTerminator(); // Check to make sure we haven't already emitted the copy for this block. // This can happen because PHI nodes may have multiple entries for the diff --git a/lib/CodeGen/RegAllocLocal.cpp b/lib/CodeGen/RegAllocLocal.cpp index 38e0073360..a3d66391cc 100644 --- a/lib/CodeGen/RegAllocLocal.cpp +++ b/lib/CodeGen/RegAllocLocal.cpp @@ -649,11 +649,7 @@ void RA::AllocateBasicBlock(MachineBasicBlock &MBB) { } } - // Rewind the iterator to point to the first flow control instruction... - const TargetInstrInfo &TII = TM->getInstrInfo(); - MI = MBB.end(); - while (MI != MBB.begin() && TII.isTerminatorInstr((--MI)->getOpcode())); - if (MI != MBB.end()) ++MI; + MI = MBB.getFirstTerminator(); // Spill all physical registers holding virtual registers now. for (unsigned i = 0, e = RegInfo->getNumRegs(); i != e; ++i) |