From e0182ec0e473ae2cd23f6451d2539b7ec449f04e Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 22 Aug 2008 19:21:41 +0000 Subject: [PATCH] Support non-fallthrough unconditional branches in FastISel. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55191 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/FastISel.h | 2 ++ lib/CodeGen/SelectionDAG/FastISel.cpp | 24 ++++++++++++------- lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/llvm/CodeGen/FastISel.h b/include/llvm/CodeGen/FastISel.h index 39395945b88..43551134357 100644 --- a/include/llvm/CodeGen/FastISel.h +++ b/include/llvm/CodeGen/FastISel.h @@ -17,6 +17,7 @@ #include "llvm/BasicBlock.h" #include "llvm/ADT/DenseMap.h" #include "llvm/CodeGen/SelectionDAGNodes.h" +#include namespace llvm { @@ -52,6 +53,7 @@ public: BasicBlock::iterator SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End, DenseMap &ValueMap, + std::map &MBBMap, MachineBasicBlock *MBB); virtual ~FastISel(); diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index 1462472ea4a..74174519fb3 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/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; } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 9304c0e7a16..e13cfc0fa03 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -5113,7 +5113,7 @@ void SelectionDAGISel::BuildSelectionDAG(SelectionDAG &DAG, BasicBlock *LLVMBB, cast(LLVMBB->getTerminator())->isUnconditional()) { if (FastISel *F = TLI.createFastISel(FuncInfo.MF)) { Begin = F->SelectInstructions(Begin, LLVMBB->end(), - FuncInfo.ValueMap, BB); + FuncInfo.ValueMap, FuncInfo.MBBMap, BB); // Clean up the FastISel object. TODO: Reorganize what data is // stored in the FastISel class itself and what is merely passed -- 2.34.1