FastISel.h revision 22bb31103de3337f0bb74c7bee16d1817d4dca14
1b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===-- FastISel.h - Definition of the FastISel class ---------------------===// 2b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 3b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// The LLVM Compiler Infrastructure 4b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 5b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// This file is distributed under the University of Illinois Open Source 6b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// License. See LICENSE.TXT for details. 7b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 8b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===----------------------------------------------------------------------===// 9b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 10b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// This file defines the FastISel class. 11b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman// 12b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman//===----------------------------------------------------------------------===// 13b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 14b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#ifndef LLVM_CODEGEN_FASTISEL_H 15b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#define LLVM_CODEGEN_FASTISEL_H 16b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 17b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#include "llvm/BasicBlock.h" 18b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#include "llvm/ADT/DenseMap.h" 19b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#include "llvm/CodeGen/SelectionDAGNodes.h" 20b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 21b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmannamespace llvm { 22b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 23b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass MachineBasicBlock; 24b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass MachineFunction; 25bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohmanclass MachineRegisterInfo; 2683785c80968165b30fcdd111ceb2c28d38bcff86Evan Chengclass TargetData; 27b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetInstrInfo; 2883785c80968165b30fcdd111ceb2c28d38bcff86Evan Chengclass TargetLowering; 2922bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohmanclass TargetMachine; 30b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetRegisterClass; 31b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 3240610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// FastISel - This is a fast-path instruction selection class that 3340610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// generates poor code and doesn't support illegal types or non-trivial 3440610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// lowering, but runs quickly. 35b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass FastISel { 3622bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohmanprotected: 37b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman MachineBasicBlock *MBB; 38bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman MachineFunction &MF; 39bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman MachineRegisterInfo &MRI; 4022bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohman const TargetMachine &TM; 4183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng const TargetData &TD; 42bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman const TargetInstrInfo &TII; 4322bb31103de3337f0bb74c7bee16d1817d4dca14Dan Gohman const TargetLowering &TLI; 44b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 45b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanpublic: 46b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// SelectInstructions - Do "fast" instruction selection over the 47b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// LLVM IR instructions in the range [Begin, N) where N is either 48b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// End or the first unsupported instruction. Return N. 49b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// ValueMap is filled in with a mapping of LLVM IR Values to 507f92ebddd27c8d099e04cc879cc8199dba88cec1Dan Gohman /// virtual register numbers. MBB is a block to which to append 517f92ebddd27c8d099e04cc879cc8199dba88cec1Dan Gohman /// the enerated MachineInstrs. 52b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman BasicBlock::iterator 53b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End, 54bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman DenseMap<const Value*, unsigned> &ValueMap, 557f92ebddd27c8d099e04cc879cc8199dba88cec1Dan Gohman MachineBasicBlock *MBB); 56b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 57cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman virtual ~FastISel(); 58cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman 59b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanprotected: 60bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman explicit FastISel(MachineFunction &mf); 61e285a74f7cf9dd3ccf4fe758576cf83301f8a43eDan Gohman 62bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_r - This method is called by target-independent code 63bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type and opcode 64bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// be emitted. 65b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_(MVT::SimpleValueType VT, 66b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode); 67bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 68bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_r - This method is called by target-independent code 69bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type, opcode, and 70bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// register operand be emitted. 71bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 72b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_r(MVT::SimpleValueType VT, 73b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode, unsigned Op0); 74bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 75bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_rr - This method is called by target-independent code 76bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type, opcode, and 77bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// register operands be emitted. 78bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 79b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_rr(MVT::SimpleValueType VT, 80b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode, 81b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0, unsigned Op1); 82b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 8383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_i - This method is called by target-independent code 8483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to request that an instruction with the given type which materialize 8583785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// the specified immediate value. 8683785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng virtual unsigned FastEmit_i(MVT::SimpleValueType VT, uint64_t Imm); 8783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 8883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_ri - This method is called by target-independent code 8983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to request that an instruction with the given type, opcode, and 9083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// register and immediate operands be emitted. 9183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// 9283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng virtual unsigned FastEmit_ri(MVT::SimpleValueType VT, 9383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng ISD::NodeType Opcode, 94d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned Op0, uint64_t Imm); 95d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman 96d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmit_rri - This method is called by target-independent code 97d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// to request that an instruction with the given type, opcode, and 98d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// register and immediate operands be emitted. 99d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 100d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman virtual unsigned FastEmit_rri(MVT::SimpleValueType VT, 101d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman ISD::NodeType Opcode, 102d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned Op0, unsigned Op1, uint64_t Imm); 10383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 10483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries 10583785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to emit an instruction with an immediate operand using FastEmit_ri. 10683785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// If that fails, it materializes the immediate into a register and try 10783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_rr instead. 10883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng unsigned FastEmit_ri_(MVT::SimpleValueType VT, 10983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng ISD::NodeType Opcode, 11083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng unsigned Op0, uint64_t Imm, 11183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng MVT::SimpleValueType ImmType); 11283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 113bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmitInst_ - Emit a MachineInstr with no operands and a 114bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// result register in the given register class. 115bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 116b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_(unsigned MachineInstOpcode, 117b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC); 118bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 119d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_r - Emit a MachineInstr with one register operand 120bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// and a result register in the given register class. 121bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 122b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_r(unsigned MachineInstOpcode, 123b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC, 124b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0); 125bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 126d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_rr - Emit a MachineInstr with two register operands 127bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// and a result register in the given register class. 128bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 129b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_rr(unsigned MachineInstOpcode, 130b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC, 131b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0, unsigned Op1); 132bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 133d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_ri - Emit a MachineInstr with two register operands 134d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// and a result register in the given register class. 135d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 136d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned FastEmitInst_ri(unsigned MachineInstOpcode, 137d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman const TargetRegisterClass *RC, 138d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned Op0, uint64_t Imm); 139d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman 140d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_rri - Emit a MachineInstr with two register operands, 141d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// an immediate, and a result register in the given register class. 142d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 143d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned FastEmitInst_rri(unsigned MachineInstOpcode, 144d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman const TargetRegisterClass *RC, 145d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned Op0, unsigned Op1, uint64_t Imm); 146d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman 147bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohmanprivate: 148c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman unsigned createResultReg(const TargetRegisterClass *RC); 149c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman 150bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman bool SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode, 151bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman DenseMap<const Value*, unsigned> &ValueMap); 152bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 153bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman bool SelectGetElementPtr(Instruction *I, 154bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman DenseMap<const Value*, unsigned> &ValueMap); 155b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman}; 156b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 157b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman} 158b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 159b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#endif 160