1 //===-- FastISel.h - Definition of the FastISel class ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the FastISel class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_FASTISEL_H
15 #define LLVM_CODEGEN_FASTISEL_H
17 #include "llvm/BasicBlock.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/CodeGen/SelectionDAGNodes.h"
23 class MachineBasicBlock;
24 class MachineFunction;
25 class MachineRegisterInfo;
27 class TargetInstrInfo;
30 class TargetRegisterClass;
32 /// FastISel - This is a fast-path instruction selection class that
33 /// generates poor code and doesn't support illegal types or non-trivial
34 /// lowering, but runs quickly.
37 MachineBasicBlock *MBB;
39 MachineRegisterInfo &MRI;
40 const TargetMachine &TM;
42 const TargetInstrInfo &TII;
43 const TargetLowering &TLI;
46 /// SelectInstructions - Do "fast" instruction selection over the
47 /// LLVM IR instructions in the range [Begin, N) where N is either
48 /// End or the first unsupported instruction. Return N.
49 /// ValueMap is filled in with a mapping of LLVM IR Values to
50 /// virtual register numbers. MBB is a block to which to append
51 /// the generated MachineInstrs.
53 SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End,
54 DenseMap<const Value*, unsigned> &ValueMap,
55 DenseMap<const BasicBlock*, MachineBasicBlock *> &MBBMap,
56 MachineBasicBlock *MBB);
61 explicit FastISel(MachineFunction &mf);
63 /// FastEmit_r - This method is called by target-independent code
64 /// to request that an instruction with the given type and opcode
66 virtual unsigned FastEmit_(MVT::SimpleValueType VT,
67 ISD::NodeType Opcode);
69 /// FastEmit_r - This method is called by target-independent code
70 /// to request that an instruction with the given type, opcode, and
71 /// register operand be emitted.
73 virtual unsigned FastEmit_r(MVT::SimpleValueType VT,
74 ISD::NodeType Opcode, unsigned Op0);
76 /// FastEmit_rr - This method is called by target-independent code
77 /// to request that an instruction with the given type, opcode, and
78 /// register operands be emitted.
80 virtual unsigned FastEmit_rr(MVT::SimpleValueType VT,
82 unsigned Op0, unsigned Op1);
84 /// FastEmit_i - This method is called by target-independent code
85 /// to request that an instruction with the given type which materialize
86 /// the specified immediate value.
87 virtual unsigned FastEmit_i(MVT::SimpleValueType VT, uint64_t Imm);
89 /// FastEmit_ri - This method is called by target-independent code
90 /// to request that an instruction with the given type, opcode, and
91 /// register and immediate operands be emitted.
93 virtual unsigned FastEmit_ri(MVT::SimpleValueType VT,
95 unsigned Op0, uint64_t Imm);
97 /// FastEmit_rri - This method is called by target-independent code
98 /// to request that an instruction with the given type, opcode, and
99 /// register and immediate operands be emitted.
101 virtual unsigned FastEmit_rri(MVT::SimpleValueType VT,
102 ISD::NodeType Opcode,
103 unsigned Op0, unsigned Op1, uint64_t Imm);
105 /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
106 /// to emit an instruction with an immediate operand using FastEmit_ri.
107 /// If that fails, it materializes the immediate into a register and try
108 /// FastEmit_rr instead.
109 unsigned FastEmit_ri_(MVT::SimpleValueType VT,
110 ISD::NodeType Opcode,
111 unsigned Op0, uint64_t Imm,
112 MVT::SimpleValueType ImmType);
114 /// FastEmitInst_ - Emit a MachineInstr with no operands and a
115 /// result register in the given register class.
117 unsigned FastEmitInst_(unsigned MachineInstOpcode,
118 const TargetRegisterClass *RC);
120 /// FastEmitInst_r - Emit a MachineInstr with one register operand
121 /// and a result register in the given register class.
123 unsigned FastEmitInst_r(unsigned MachineInstOpcode,
124 const TargetRegisterClass *RC,
127 /// FastEmitInst_rr - Emit a MachineInstr with two register operands
128 /// and a result register in the given register class.
130 unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
131 const TargetRegisterClass *RC,
132 unsigned Op0, unsigned Op1);
134 /// FastEmitInst_ri - Emit a MachineInstr with two register operands
135 /// and a result register in the given register class.
137 unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
138 const TargetRegisterClass *RC,
139 unsigned Op0, uint64_t Imm);
141 /// FastEmitInst_rri - Emit a MachineInstr with two register operands,
142 /// an immediate, and a result register in the given register class.
144 unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
145 const TargetRegisterClass *RC,
146 unsigned Op0, unsigned Op1, uint64_t Imm);
149 unsigned createResultReg(const TargetRegisterClass *RC);
151 bool SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode,
152 DenseMap<const Value*, unsigned> &ValueMap);
154 bool SelectGetElementPtr(Instruction *I,
155 DenseMap<const Value*, unsigned> &ValueMap);