FastISel.h revision 6d0c25ec3a7ca822e68f73a4481eee43eb5c9485
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 51a794ef7f5d82c7f88d86932746cb9ae2c1c40200Owen Anderson /// the generated MachineInstrs. 52b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman BasicBlock::iterator 53b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End, 54bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman DenseMap<const Value*, unsigned> &ValueMap, 556ecf50908c78aae0feff1c378fbb75dcf013ed21Dan Gohman DenseMap<const BasicBlock*, MachineBasicBlock *> &MBBMap, 567f92ebddd27c8d099e04cc879cc8199dba88cec1Dan Gohman MachineBasicBlock *MBB); 57b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 58cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman virtual ~FastISel(); 59cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman 60b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanprotected: 61bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman explicit FastISel(MachineFunction &mf); 62e285a74f7cf9dd3ccf4fe758576cf83301f8a43eDan Gohman 63bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_r - This method is called by target-independent code 64bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type and opcode 65bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// be emitted. 66b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_(MVT::SimpleValueType VT, 67b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode); 68bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 69bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_r - This method is called by target-independent code 70bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type, opcode, and 71bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// register operand be emitted. 72bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 73b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_r(MVT::SimpleValueType VT, 74b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode, unsigned Op0); 75bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 76bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_rr - This method is called by target-independent code 77bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type, opcode, and 78bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// register operands be emitted. 79bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 80b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_rr(MVT::SimpleValueType VT, 81b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode, 82b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0, unsigned Op1); 83b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 8483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_ri - This method is called by target-independent code 8583785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to request that an instruction with the given type, opcode, and 8683785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// register and immediate operands be emitted. 8783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// 8883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng virtual unsigned FastEmit_ri(MVT::SimpleValueType VT, 8983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng ISD::NodeType Opcode, 90d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned Op0, uint64_t Imm); 91d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman 92d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmit_rri - This method is called by target-independent code 93d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// to request that an instruction with the given type, opcode, and 94d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// register and immediate operands be emitted. 95d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 96d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman virtual unsigned FastEmit_rri(MVT::SimpleValueType VT, 97d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman ISD::NodeType Opcode, 98d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned Op0, unsigned Op1, uint64_t Imm); 9983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 10083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries 10183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to emit an instruction with an immediate operand using FastEmit_ri. 10283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// If that fails, it materializes the immediate into a register and try 10383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_rr instead. 10483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng unsigned FastEmit_ri_(MVT::SimpleValueType VT, 10583785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng ISD::NodeType Opcode, 10683785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng unsigned Op0, uint64_t Imm, 10783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng MVT::SimpleValueType ImmType); 1086d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson 1096d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// FastEmit_i - This method is called by target-independent code 1106d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// to request that an instruction with the given type, opcode, and 1116d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// immediate operand be emitted. 1126d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson virtual unsigned FastEmit_i(MVT::SimpleValueType VT, 1136d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson ISD::NodeType Opcode, 1146d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson uint64_t Imm); 11583785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 116bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmitInst_ - Emit a MachineInstr with no operands and a 117bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// result register in the given register class. 118bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 119b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_(unsigned MachineInstOpcode, 120b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC); 121bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 122d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_r - Emit a MachineInstr with one register operand 123bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// and a result register in the given register class. 124bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 125b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_r(unsigned MachineInstOpcode, 126b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC, 127b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0); 128bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 129d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_rr - Emit a MachineInstr with two register operands 130bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// and a result register in the given register class. 131bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 132b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_rr(unsigned MachineInstOpcode, 133b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC, 134b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0, unsigned Op1); 135bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 136d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_ri - Emit a MachineInstr with two register operands 137d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// and a result register in the given register class. 138d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 139d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned FastEmitInst_ri(unsigned MachineInstOpcode, 140d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman const TargetRegisterClass *RC, 141d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned Op0, uint64_t Imm); 142d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman 143d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// FastEmitInst_rri - Emit a MachineInstr with two register operands, 144d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// an immediate, and a result register in the given register class. 145d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman /// 146d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned FastEmitInst_rri(unsigned MachineInstOpcode, 147d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman const TargetRegisterClass *RC, 148d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman unsigned Op0, unsigned Op1, uint64_t Imm); 1496d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson 1506d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// FastEmitInst_i - Emit a MachineInstr with a single immediate 1516d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson /// operand, and a result register in the given register class. 1526d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson unsigned FastEmitInst_i(unsigned MachineInstrOpcode, 1536d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson const TargetRegisterClass *RC, 1546d0c25ec3a7ca822e68f73a4481eee43eb5c9485Owen Anderson uint64_t Imm); 155d5fe57d2f980c6bd1a61450f99c254a76d0f1683Dan Gohman 156bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohmanprivate: 157c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman unsigned createResultReg(const TargetRegisterClass *RC); 158c7f72de3b4ef21828ea4780f0693bf0acd04e1c5Dan Gohman 159bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman bool SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode, 160bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman DenseMap<const Value*, unsigned> &ValueMap); 161bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 162bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman bool SelectGetElementPtr(Instruction *I, 163bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman DenseMap<const Value*, unsigned> &ValueMap); 164b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman}; 165b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 166b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman} 167b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 168b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#endif 169