FastISel.h revision 83785c80968165b30fcdd111ceb2c28d38bcff86
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; 29b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass TargetRegisterClass; 30b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 3140610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// FastISel - This is a fast-path instruction selection class that 3240610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// generates poor code and doesn't support illegal types or non-trivial 3340610241d00e219341ff4b7106c5baff08ad407bDan Gohman/// lowering, but runs quickly. 34b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanclass FastISel { 35b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman MachineBasicBlock *MBB; 36bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman MachineFunction &MF; 37bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman MachineRegisterInfo &MRI; 3883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng const TargetData &TD; 39bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman const TargetInstrInfo &TII; 4083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng TargetLowering &TLI; 41b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 42b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanpublic: 43b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// SelectInstructions - Do "fast" instruction selection over the 44b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// LLVM IR instructions in the range [Begin, N) where N is either 45b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// End or the first unsupported instruction. Return N. 46b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// ValueMap is filled in with a mapping of LLVM IR Values to 47b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman /// register numbers. 48b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman BasicBlock::iterator 49b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End, 50bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman DenseMap<const Value*, unsigned> &ValueMap, 51bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman MachineBasicBlock *mbb); 52b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 53cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman virtual ~FastISel(); 54cc8430f742b0f1e567292c8a776e94fc1c930b2aDan Gohman 55b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohmanprotected: 56bb466331e7e50d03497ce40ee344870236fd9c32Dan Gohman explicit FastISel(MachineFunction &mf); 57e285a74f7cf9dd3ccf4fe758576cf83301f8a43eDan Gohman 58bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_r - This method is called by target-independent code 59bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type and opcode 60bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// be emitted. 61b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_(MVT::SimpleValueType VT, 62b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode); 63bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 64bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_r - This method is called by target-independent code 65bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type, opcode, and 66bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// register operand be emitted. 67bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 68b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_r(MVT::SimpleValueType VT, 69b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode, unsigned Op0); 70bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 71bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmit_rr - This method is called by target-independent code 72bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// to request that an instruction with the given type, opcode, and 73bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// register operands be emitted. 74bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 75b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman virtual unsigned FastEmit_rr(MVT::SimpleValueType VT, 76b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman ISD::NodeType Opcode, 77b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0, unsigned Op1); 78b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 7983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_i - This method is called by target-independent code 8083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to request that an instruction with the given type which materialize 8183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// the specified immediate value. 8283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng virtual unsigned FastEmit_i(MVT::SimpleValueType VT, uint64_t Imm); 8383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 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, 9083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng unsigned Op0, uint64_t Imm, 9183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng MVT::SimpleValueType ImmType); 9283785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 9383785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries 9483785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// to emit an instruction with an immediate operand using FastEmit_ri. 9583785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// If that fails, it materializes the immediate into a register and try 9683785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng /// FastEmit_rr instead. 9783785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng unsigned FastEmit_ri_(MVT::SimpleValueType VT, 9883785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng ISD::NodeType Opcode, 9983785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng unsigned Op0, uint64_t Imm, 10083785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng MVT::SimpleValueType ImmType); 10183785c80968165b30fcdd111ceb2c28d38bcff86Evan Cheng 102bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmitInst_ - Emit a MachineInstr with no operands and a 103bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// result register in the given register class. 104bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 105b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_(unsigned MachineInstOpcode, 106b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC); 107bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 108bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmitInst_ - Emit a MachineInstr with one register operand 109bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// and a result register in the given register class. 110bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 111b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_r(unsigned MachineInstOpcode, 112b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC, 113b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0); 114bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 115bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// FastEmitInst_ - Emit a MachineInstr with two register operands 116bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// and a result register in the given register class. 117bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman /// 118b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned FastEmitInst_rr(unsigned MachineInstOpcode, 119b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman const TargetRegisterClass *RC, 120b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman unsigned Op0, unsigned Op1); 121bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 122bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohmanprivate: 123bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman bool SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode, 124bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman DenseMap<const Value*, unsigned> &ValueMap); 125bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman 126bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman bool SelectGetElementPtr(Instruction *I, 127bdedd4477331b3b0d28d74658baf05f675f2d195Dan Gohman DenseMap<const Value*, unsigned> &ValueMap); 128b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman}; 129b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 130b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman} 131b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman 132b0cf29c5cfff797284b3660dc233e135feb65d9aDan Gohman#endif 133