diff --git a/include/llvm/CodeGen/FastISel.h b/include/llvm/CodeGen/FastISel.h index 20a923b1de9..364f82e0b48 100644 --- a/include/llvm/CodeGen/FastISel.h +++ b/include/llvm/CodeGen/FastISel.h @@ -52,10 +52,21 @@ public: /// the generated MachineInstrs. BasicBlock::iterator SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End, - DenseMap &ValueMap, - DenseMap &MBBMap, + DenseMap &ValueMap, + DenseMap &MBBMap, MachineBasicBlock *MBB); + /// TargetSelectInstruction - This method is called by target-independent + /// code when the normal FastISel process fails to select an instruction. + /// This gives targets a chance to emit code for anything that doesn't + /// fit into FastISel's framework. It returns true if it was successful. + /// + virtual bool + TargetSelectInstruction(Instruction *I, + DenseMap &ValueMap, + DenseMap &MBBMap, + MachineBasicBlock *MBB) = 0; + virtual ~FastISel(); protected: diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index f2246cac2c7..9b982f4fb4a 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -5757,10 +5757,15 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn, MachineFunction &MF) { Begin = F->SelectInstructions(Begin, End, FuncInfo->ValueMap, FuncInfo->MBBMap, BB); + // If the "fast" selector selected the entire block, we're done. if (Begin == End) - // The "fast" selector selected the entire block, so we're done. break; + // Next, try calling the target to attempt to handle the instruction. + if (F->TargetSelectInstruction(Begin, FuncInfo->ValueMap, + FuncInfo->MBBMap, BB)) + continue; + // Handle certain instructions as single-LLVM-Instruction blocks. if (isa(Begin) || isa(Begin) || isa(Begin)) { @@ -5783,7 +5788,7 @@ void SelectionDAGISel::SelectAllBasicBlocks(Function &Fn, MachineFunction &MF) { // The "fast" selector couldn't handle something and bailed. // For the purpose of debugging, just abort. #ifndef NDEBUG - Begin->dump(); + Begin->dump(); #endif assert(0 && "FastISel didn't select the entire block"); } diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index f049a4d363d..96bdb50fd69 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -19,3 +19,23 @@ #include "X86FastISel.h" #include "X86TargetMachine.h" #include "X86GenFastISel.inc" + +namespace llvm { + +namespace X86 { + +bool +FastISel::TargetSelectInstruction(Instruction *I, + DenseMap &ValueMap, + DenseMap &MBBMap, + MachineBasicBlock *MBB) { + switch (I->getOpcode()) { + default: break; + } + + return false; +} + +} + +} diff --git a/utils/TableGen/FastISelEmitter.cpp b/utils/TableGen/FastISelEmitter.cpp index 305158f4714..fedb44e4d0b 100644 --- a/utils/TableGen/FastISelEmitter.cpp +++ b/utils/TableGen/FastISelEmitter.cpp @@ -351,6 +351,14 @@ void FastISelMap::PrintClass(std::ostream &OS) { } OS << "\n"; + OS << "bool TargetSelectInstruction(Instruction *I,\n"; + OS << " " + "DenseMap &ValueMap,\n"; + OS << " " + "DenseMap &MBBMap,\n"; + OS << " " + "MachineBasicBlock *MBB);\n"; + // Declare the Subtarget member, which is used for predicate checks. OS << " const " << InstNS.substr(0, InstNS.size() - 2) << "Subtarget *Subtarget;\n";