Reapply r55191 and r55192.
authorDan Gohman <gohman@apple.com>
Fri, 22 Aug 2008 21:28:19 +0000 (21:28 +0000)
committerDan Gohman <gohman@apple.com>
Fri, 22 Aug 2008 21:28:19 +0000 (21:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55205 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/FastISel.h
lib/CodeGen/SelectionDAG/FastISel.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index 39395945b887f7b8b06b46aa96977c702c190ee8..43551134357011b4ca35fe33a195679ade3644dc 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/CodeGen/SelectionDAGNodes.h"
+#include <map>
 
 namespace llvm {
 
@@ -52,6 +53,7 @@ public:
   BasicBlock::iterator
   SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End,
                      DenseMap<const Value*, unsigned> &ValueMap,
+                     std::map<const BasicBlock*, MachineBasicBlock *> &MBBMap,
                      MachineBasicBlock *MBB);
 
   virtual ~FastISel();
index 1462472ea4aa49b7088568b254a58eca7ab82cfe..fb4de574a85f7db785ac05d5b21b1fef0d5aa2d6 100644 (file)
@@ -145,6 +145,8 @@ BasicBlock::iterator
 FastISel::SelectInstructions(BasicBlock::iterator Begin,
                              BasicBlock::iterator End,
                              DenseMap<const Value*, unsigned> &ValueMap,
+                             std::map<const BasicBlock*,
+                                      MachineBasicBlock *> &MBBMap,
                              MachineBasicBlock *mbb) {
   MBB = mbb;
   BasicBlock::iterator I = Begin;
@@ -195,19 +197,24 @@ FastISel::SelectInstructions(BasicBlock::iterator Begin,
     case Instruction::Br: {
       BranchInst *BI = cast<BranchInst>(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.
+          TII.InsertBranch(*MBB, MSucc, NULL, SmallVector<MachineOperand, 0>());
         }
+        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;
     }
 
index 9304c0e7a1624774ba892d1ef6067b7a7a83e4cb..e13cfc0fa034e0086db2919985e036b1dddf6f24 100644 (file)
@@ -5113,7 +5113,7 @@ void SelectionDAGISel::BuildSelectionDAG(SelectionDAG &DAG, BasicBlock *LLVMBB,
       cast<BranchInst>(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