12ae3a80e1b714bde928e5a297eeb279bec57dc1
[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                                MVT::SimpleValueType ImmType);
93
94   /// FastEmit_ri_ - This method is a wrapper of FastEmit_ri. It first tries
95   /// to emit an instruction with an immediate operand using FastEmit_ri.
96   /// If that fails, it materializes the immediate into a register and try
97   /// FastEmit_rr instead.
98   unsigned FastEmit_ri_(MVT::SimpleValueType VT,
99                         ISD::NodeType Opcode,
100                         unsigned Op0, uint64_t Imm,
101                         MVT::SimpleValueType ImmType);
102
103   /// FastEmitInst_ - Emit a MachineInstr with no operands and a
104   /// result register in the given register class.
105   ///
106   unsigned FastEmitInst_(unsigned MachineInstOpcode,
107                          const TargetRegisterClass *RC);
108
109   /// FastEmitInst_ - Emit a MachineInstr with one register operand
110   /// and a result register in the given register class.
111   ///
112   unsigned FastEmitInst_r(unsigned MachineInstOpcode,
113                           const TargetRegisterClass *RC,
114                           unsigned Op0);
115
116   /// FastEmitInst_ - Emit a MachineInstr with two register operands
117   /// and a result register in the given register class.
118   ///
119   unsigned FastEmitInst_rr(unsigned MachineInstOpcode,
120                            const TargetRegisterClass *RC,
121                            unsigned Op0, unsigned Op1);
122
123 private:
124   unsigned createResultReg(const TargetRegisterClass *RC);
125
126   bool SelectBinaryOp(Instruction *I, ISD::NodeType ISDOpcode,
127                       DenseMap<const Value*, unsigned> &ValueMap);
128
129   bool SelectGetElementPtr(Instruction *I,
130                            DenseMap<const Value*, unsigned> &ValueMap);
131 };
132
133 }
134
135 #endif