Add MIPS DSP register classes. Set actions of DSP vector operations and override
[oota-llvm.git] / lib / Target / Mips / MipsISelLowering.h
1 //===-- MipsISelLowering.h - Mips DAG Lowering Interface --------*- C++ -*-===//
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 interfaces that Mips uses to lower LLVM code into a
11 // selection DAG.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef MipsISELLOWERING_H
16 #define MipsISELLOWERING_H
17
18 #include "Mips.h"
19 #include "MipsSubtarget.h"
20 #include "llvm/CodeGen/SelectionDAG.h"
21 #include "llvm/Target/TargetLowering.h"
22
23 namespace llvm {
24   namespace MipsISD {
25     enum NodeType {
26       // Start the numbering from where ISD NodeType finishes.
27       FIRST_NUMBER = ISD::BUILTIN_OP_END,
28
29       // Jump and link (call)
30       JmpLink,
31
32       // Get the Higher 16 bits from a 32-bit immediate
33       // No relation with Mips Hi register
34       Hi,
35
36       // Get the Lower 16 bits from a 32-bit immediate
37       // No relation with Mips Lo register
38       Lo,
39
40       // Handle gp_rel (small data/bss sections) relocation.
41       GPRel,
42
43       // Thread Pointer
44       ThreadPointer,
45
46       // Floating Point Branch Conditional
47       FPBrcond,
48
49       // Floating Point Compare
50       FPCmp,
51
52       // Floating Point Conditional Moves
53       CMovFP_T,
54       CMovFP_F,
55
56       // Floating Point Rounding
57       FPRound,
58
59       // Return
60       Ret,
61
62       // MAdd/Sub nodes
63       MAdd,
64       MAddu,
65       MSub,
66       MSubu,
67
68       // DivRem(u)
69       DivRem,
70       DivRemU,
71
72       BuildPairF64,
73       ExtractElementF64,
74
75       Wrapper,
76
77       DynAlloc,
78
79       Sync,
80
81       Ext,
82       Ins,
83
84       // EXTR.W instrinsic nodes.
85       EXTP,
86       EXTPDP,
87       EXTR_S_H,
88       EXTR_W,
89       EXTR_R_W,
90       EXTR_RS_W,
91       SHILO,
92       MTHLIP,
93
94       // DPA.W intrinsic nodes.
95       MULSAQ_S_W_PH,
96       MAQ_S_W_PHL,
97       MAQ_S_W_PHR,
98       MAQ_SA_W_PHL,
99       MAQ_SA_W_PHR,
100       DPAU_H_QBL,
101       DPAU_H_QBR,
102       DPSU_H_QBL,
103       DPSU_H_QBR,
104       DPAQ_S_W_PH,
105       DPSQ_S_W_PH,
106       DPAQ_SA_L_W,
107       DPSQ_SA_L_W,
108       DPA_W_PH,
109       DPS_W_PH,
110       DPAQX_S_W_PH,
111       DPAQX_SA_W_PH,
112       DPAX_W_PH,
113       DPSX_W_PH,
114       DPSQX_S_W_PH,
115       DPSQX_SA_W_PH,
116       MULSA_W_PH,
117
118       MULT,
119       MULTU,
120       MADD_DSP,
121       MADDU_DSP,
122       MSUB_DSP,
123       MSUBU_DSP,
124
125       // Load/Store Left/Right nodes.
126       LWL = ISD::FIRST_TARGET_MEMORY_OPCODE,
127       LWR,
128       SWL,
129       SWR,
130       LDL,
131       LDR,
132       SDL,
133       SDR
134     };
135   }
136
137   //===--------------------------------------------------------------------===//
138   // TargetLowering Implementation
139   //===--------------------------------------------------------------------===//
140
141   class MipsTargetLowering : public TargetLowering  {
142   public:
143     explicit MipsTargetLowering(MipsTargetMachine &TM);
144
145     virtual MVT getShiftAmountTy(EVT LHSTy) const { return MVT::i32; }
146
147     virtual bool allowsUnalignedMemoryAccesses (EVT VT) const;
148
149     virtual void LowerOperationWrapper(SDNode *N,
150                                        SmallVectorImpl<SDValue> &Results,
151                                        SelectionDAG &DAG) const;
152
153     /// LowerOperation - Provide custom lowering hooks for some operations.
154     virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
155
156     /// ReplaceNodeResults - Replace the results of node with an illegal result
157     /// type with new values built out of custom code.
158     ///
159     virtual void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue>&Results,
160                                     SelectionDAG &DAG) const;
161
162     /// getTargetNodeName - This method returns the name of a target specific
163     //  DAG node.
164     virtual const char *getTargetNodeName(unsigned Opcode) const;
165
166     /// getSetCCResultType - get the ISD::SETCC result ValueType
167     EVT getSetCCResultType(EVT VT) const;
168
169     virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
170   private:
171     // Subtarget Info
172     const MipsSubtarget *Subtarget;
173
174     bool HasMips64, IsN64, IsO32;
175
176     // Lower Operand helpers
177     SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
178                             CallingConv::ID CallConv, bool isVarArg,
179                             const SmallVectorImpl<ISD::InputArg> &Ins,
180                             DebugLoc dl, SelectionDAG &DAG,
181                             SmallVectorImpl<SDValue> &InVals) const;
182
183     // Lower Operand specifics
184     SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
185     SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) const;
186     SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
187     SDValue LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const;
188     SDValue LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const;
189     SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
190     SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
191     SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const;
192     SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
193     SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) const;
194     SDValue LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
195     SDValue LowerFABS(SDValue Op, SelectionDAG &DAG) const;
196     SDValue LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const;
197     SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
198     SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG& DAG) const;
199     SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG& DAG) const;
200     SDValue LowerShiftLeftParts(SDValue Op, SelectionDAG& DAG) const;
201     SDValue LowerShiftRightParts(SDValue Op, SelectionDAG& DAG,
202                                  bool IsSRA) const;
203     SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
204     SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
205
206     virtual SDValue
207       LowerFormalArguments(SDValue Chain,
208                            CallingConv::ID CallConv, bool isVarArg,
209                            const SmallVectorImpl<ISD::InputArg> &Ins,
210                            DebugLoc dl, SelectionDAG &DAG,
211                            SmallVectorImpl<SDValue> &InVals) const;
212
213     virtual SDValue
214       LowerCall(TargetLowering::CallLoweringInfo &CLI,
215                 SmallVectorImpl<SDValue> &InVals) const;
216
217     virtual SDValue
218       LowerReturn(SDValue Chain,
219                   CallingConv::ID CallConv, bool isVarArg,
220                   const SmallVectorImpl<ISD::OutputArg> &Outs,
221                   const SmallVectorImpl<SDValue> &OutVals,
222                   DebugLoc dl, SelectionDAG &DAG) const;
223
224     virtual MachineBasicBlock *
225       EmitInstrWithCustomInserter(MachineInstr *MI,
226                                   MachineBasicBlock *MBB) const;
227
228     // Inline asm support
229     ConstraintType getConstraintType(const std::string &Constraint) const;
230
231     /// Examine constraint string and operand type and determine a weight value.
232     /// The operand object must already have been set up with the operand type.
233     ConstraintWeight getSingleConstraintMatchWeight(
234       AsmOperandInfo &info, const char *constraint) const;
235
236     std::pair<unsigned, const TargetRegisterClass*>
237               getRegForInlineAsmConstraint(const std::string &Constraint,
238               EVT VT) const;
239
240     /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops
241     /// vector.  If it is invalid, don't add anything to Ops. If hasMemory is
242     /// true it means one of the asm constraint of the inline asm instruction
243     /// being processed is 'm'.
244     virtual void LowerAsmOperandForConstraint(SDValue Op,
245                                               std::string &Constraint,
246                                               std::vector<SDValue> &Ops,
247                                               SelectionDAG &DAG) const;
248
249     virtual bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const;
250
251     virtual EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
252                                     unsigned SrcAlign, bool IsZeroVal,
253                                     bool MemcpyStrSrc,
254                                     MachineFunction &MF) const;
255
256     /// isFPImmLegal - Returns true if the target can instruction select the
257     /// specified FP immediate natively. If false, the legalizer will
258     /// materialize the FP immediate as a load from a constant pool.
259     virtual bool isFPImmLegal(const APFloat &Imm, EVT VT) const;
260
261     virtual unsigned getJumpTableEncoding() const;
262
263     MachineBasicBlock *EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB,
264                     unsigned Size, unsigned BinOpcode, bool Nand = false) const;
265     MachineBasicBlock *EmitAtomicBinaryPartword(MachineInstr *MI,
266                     MachineBasicBlock *BB, unsigned Size, unsigned BinOpcode,
267                     bool Nand = false) const;
268     MachineBasicBlock *EmitAtomicCmpSwap(MachineInstr *MI,
269                                   MachineBasicBlock *BB, unsigned Size) const;
270     MachineBasicBlock *EmitAtomicCmpSwapPartword(MachineInstr *MI,
271                                   MachineBasicBlock *BB, unsigned Size) const;
272   };
273 }
274
275 #endif // MipsISELLOWERING_H