#include "llvm/BasicBlock.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/CodeGen/SelectionDAGNodes.h"
+#include <map>
namespace llvm {
BasicBlock::iterator
SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End,
DenseMap<const Value*, unsigned> &ValueMap,
+ std::map<const BasicBlock*, MachineBasicBlock *> &MBBMap,
MachineBasicBlock *MBB);
virtual ~FastISel();
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;
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.
+ const SmallVector<MachineOperand, 0> 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;
}
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