From 87ff7058e78a5fce93625a2adecd2a6398326a54 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 22 Aug 2008 19:21:41 +0000 Subject: Support non-fallthrough unconditional branches in FastISel. llvm-svn: 55191 --- llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'llvm/lib/CodeGen/SelectionDAG/FastISel.cpp') diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp index 1462472ea4a..74174519fb3 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -145,6 +145,8 @@ BasicBlock::iterator FastISel::SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End, DenseMap &ValueMap, + std::map &MBBMap, MachineBasicBlock *mbb) { MBB = mbb; BasicBlock::iterator I = Begin; @@ -195,19 +197,25 @@ FastISel::SelectInstructions(BasicBlock::iterator Begin, case Instruction::Br: { BranchInst *BI = cast(I); - // For now, check for and handle just the most trivial case: an - // unconditional fall-through branch. if (BI->isUnconditional()) { - MachineFunction::iterator NextMBB = + MachineFunction::iterator NextMBB = next(MachineFunction::iterator(MBB)); - if (NextMBB != MF.end() && - NextMBB->getBasicBlock() == BI->getSuccessor(0)) { - MBB->addSuccessor(NextMBB); - break; + BasicBlock *LLVMSucc = BI->getSuccessor(0); + MachineBasicBlock *MSucc = MBBMap[LLVMSucc]; + + if (NextMBB != MF.end() && MSucc == NextMBB) { + // The unconditional fall-through case, which needs no instructions. + } else { + // The unconditional branch case. + const SmallVector NoCond(0); + TII.InsertBranch(*MBB, MSucc, NULL, NoCond); } + MBB->addSuccessor(MSucc); + break; } - // Something more complicated. Halt "fast" selection and bail. + // Conditional branches are not handed yet. + // Halt "fast" selection and bail. return I; } -- cgit v1.2.3