cd6a6d61996e77cc550aeaceaf945450a3227781
[oota-llvm.git] / include / llvm / CodeGen / FastISel.h
1 //===-- FastISel.h - Definition of the FastISel class ---------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the FastISel class.
11 //  
12 //===----------------------------------------------------------------------===//
13   
14 #ifndef LLVM_CODEGEN_FASTISEL_H
15 #define LLVM_CODEGEN_FASTISEL_H
16
17 #include "llvm/BasicBlock.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/CodeGen/SelectionDAGNodes.h"
20
21 namespace llvm {
22
23 class MachineBasicBlock;
24 class MachineFunction;
25 class MachineRegisterInfo;
26 class TargetData;
27 class TargetInstrInfo;
28 class TargetLowering;
29 class TargetRegisterClass;
30
31 /// FastISel - This is a fast-path instruction selection class that
32 /// generates poor code and doesn't support illegal types or non-trivial
33 /// lowering, but runs quickly.
34 class FastISel {
35   MachineBasicBlock *MBB;
36   MachineFunction &MF;
37   MachineRegisterInfo &MRI;
38   const TargetData &TD;
39   const TargetInstrInfo &TII;
40   TargetLowering &TLI;
41
42 public:
43   /// SelectInstructions - Do "fast" instruction selection over the
44   /// LLVM IR instructions in the range [Begin, N) where N is either
45   /// End or the first unsupported instruction. Return N.
46   /// ValueMap is filled in with a mapping of LLVM IR Values to
47   /// virtual register numbers. MBB is a block to which to append
48   /// the enerated MachineInstrs.
49   BasicBlock::iterator
50   SelectInstructions(BasicBlock::iterator Begin, BasicBlock::iterator End,
51                      DenseMap<const Value*, unsigned> &ValueMap,
52                      MachineBasicBlock *MBB);
53
54   virtual ~FastISel();
55
56 protected:
57   explicit FastISel(MachineFunction &mf);
58
59   /// FastEmit_r - This method is called by target-independent code
60   /// to request that an instruction with the given type and opcode
61   /// be emitted.
62   virtual unsigned FastEmit_(MVT::SimpleValueType VT,
63                              ISD::NodeType Opcode);
64
65   /// FastEmit_r - This method is called by target-independent code
66   /// to request that an instruction with the given type, opcode, and
67   /// register operand be emitted.
68   ///
69   virtual unsigned FastEmit_r(MVT::SimpleValueType VT,
70                               ISD::NodeType Opcode, unsigned Op0);
71
72   /// FastEmit_rr - This method is called by target-independent code
73   /// to request that an instruction with the given type, opcode, and
74   /// register operands be emitted.
75   ///
76   virtual unsigned FastEmit_rr(MVT::SimpleValueType VT,
77                                ISD::NodeType Opcode,
78                                unsigned Op0, unsigned Op1);
79
80   /// FastEmit_i - This method is called by target-independent code
81   /// to request that an instruction with the given type which materialize
82   /// the specified immediate value.
83   virtual unsigned FastEmit_i(MVT::SimpleValueType VT, uint64_t Imm);
84
85   /// FastEmit_ri - This method is called by target-independent code
86   /// to request that an instruction with the given type, opcode, and
87   /// register and immediate operands be emitted.
88   ///
89   virtual unsigned FastEmit_ri(MVT::SimpleValueType VT,
90                                ISD::NodeType Opcode,
91                                unsigned Op0, uint64_t Imm);
92
93   /// FastEmit_rri - This method is called by target-independent code
94   /// to request that an instruction with the given type, opcode, and
95   /// register and immediate operands be emitted.
96   ///
97   virtual unsigned FastEmit_rri(MVT::SimpleValueType VT,
98                                 ISD::NodeType Opcode,
99                                 unsigned Op0, unsigned Op1, uint64_t Imm);
100
101   /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
102   /// to emit an instruction with an immediate operand using FastEmit_ri.
103   /// If that fails, it materializes the immediate into a register and try
104   /// FastEmit_rr instead.
105   unsigned FastEmit_ri_(MVT::SimpleValueType VT,
106                         ISD::NodeType Opcode,
107                         unsigned Op0, uint64_t Imm,
108                         MVT::SimpleValueType ImmType);
109
110   /// FastEmitInst_ - Emit a MachineInstr with no operands and a
111   /// result register in the given register class.
112   ///
113   unsigned FastEmitInst_(unsigned MachineInstOpcode,
114                          const TargetRegisterClass *RC);
115
116   /// FastEmitInst_r - Emit a MachineInstr with one register operand
117   /// and a result register in the given register class.
118   ///
119   unsigned FastEmitInst_r(unsigned MachineInstOpcode,
120                           const TargetRegisterClass *RC,
121                           unsigned Op0);
122
123   /// FastEmitInst_rr - Emit a MachineInstr with two register operands
124   /// and a result register in the given register class.
125   ///
126   unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
127                            const TargetRegisterClass *RC,
128                            unsigned Op0, unsigned Op1);
129
130   /// FastEmitInst_ri - Emit a MachineInstr with two register operands
131   /// and a result register in the given register class.
132   ///
133   unsigned FastEmitInst_ri(unsigned MachineInstOpcode,
134                            const TargetRegisterClass *RC,
135                            unsigned Op0, uint64_t Imm);
136
137   /// FastEmitInst_rri - Emit a MachineInstr with two register operands,
138   /// an immediate, and a result register in the given register class.
139   ///
140   unsigned FastEmitInst_rri(unsigned MachineInstOpcode,
141                             const TargetRegisterClass *RC,
142                             unsigned Op0, unsigned Op1, uint64_t Imm);
143
144 private:
145   unsigned createResultReg(const TargetRegisterClass *RC);
146
147   bool SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode,
148                       DenseMap<const Value*, unsigned> &ValueMap);
149
150   bool SelectGetElementPtr(Instruction *I,
151                            DenseMap<const Value*, unsigned> &ValueMap);
152 };
153
154 }
155
156 #endif