]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
Merge libc++ trunk r300890, and update build glue.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / AMDGPU / AMDGPUISelLowering.h
1 //===-- AMDGPUISelLowering.h - AMDGPU 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 /// \file
11 /// \brief Interface definition of the TargetLowering class that is common
12 /// to all AMD GPUs.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUISELLOWERING_H
17 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUISELLOWERING_H
18
19 #include "AMDGPU.h"
20 #include "llvm/CodeGen/CallingConvLower.h"
21 #include "llvm/Target/TargetLowering.h"
22
23 namespace llvm {
24
25 class AMDGPUMachineFunction;
26 class AMDGPUSubtarget;
27 class MachineRegisterInfo;
28
29 class AMDGPUTargetLowering : public TargetLowering {
30 private:
31   /// \returns AMDGPUISD::FFBH_U32 node if the incoming \p Op may have been
32   /// legalized from a smaller type VT. Need to match pre-legalized type because
33   /// the generic legalization inserts the add/sub between the select and
34   /// compare.
35   SDValue getFFBH_U32(SelectionDAG &DAG, SDValue Op, const SDLoc &DL) const;
36
37 protected:
38   const AMDGPUSubtarget *Subtarget;
39   AMDGPUAS AMDGPUASI;
40
41   SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
42   SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
43   /// \brief Split a vector store into multiple scalar stores.
44   /// \returns The resulting chain.
45
46   SDValue LowerFREM(SDValue Op, SelectionDAG &DAG) const;
47   SDValue LowerFCEIL(SDValue Op, SelectionDAG &DAG) const;
48   SDValue LowerFTRUNC(SDValue Op, SelectionDAG &DAG) const;
49   SDValue LowerFRINT(SDValue Op, SelectionDAG &DAG) const;
50   SDValue LowerFNEARBYINT(SDValue Op, SelectionDAG &DAG) const;
51
52   SDValue LowerFROUND32_16(SDValue Op, SelectionDAG &DAG) const;
53   SDValue LowerFROUND64(SDValue Op, SelectionDAG &DAG) const;
54   SDValue LowerFROUND(SDValue Op, SelectionDAG &DAG) const;
55   SDValue LowerFFLOOR(SDValue Op, SelectionDAG &DAG) const;
56
57   SDValue LowerCTLZ(SDValue Op, SelectionDAG &DAG) const;
58
59   SDValue LowerINT_TO_FP32(SDValue Op, SelectionDAG &DAG, bool Signed) const;
60   SDValue LowerINT_TO_FP64(SDValue Op, SelectionDAG &DAG, bool Signed) const;
61   SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
62   SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
63
64   SDValue LowerFP64_TO_INT(SDValue Op, SelectionDAG &DAG, bool Signed) const;
65   SDValue LowerFP_TO_FP16(SDValue Op, SelectionDAG &DAG) const;
66   SDValue LowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG) const;
67   SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const;
68
69   SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
70
71 protected:
72   bool shouldCombineMemoryType(EVT VT) const;
73   SDValue performLoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
74   SDValue performStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const;
75   SDValue performClampCombine(SDNode *N, DAGCombinerInfo &DCI) const;
76
77   SDValue splitBinaryBitConstantOpImpl(DAGCombinerInfo &DCI, const SDLoc &SL,
78                                        unsigned Opc, SDValue LHS,
79                                        uint32_t ValLo, uint32_t ValHi) const;
80   SDValue performShlCombine(SDNode *N, DAGCombinerInfo &DCI) const;
81   SDValue performSraCombine(SDNode *N, DAGCombinerInfo &DCI) const;
82   SDValue performSrlCombine(SDNode *N, DAGCombinerInfo &DCI) const;
83   SDValue performMulCombine(SDNode *N, DAGCombinerInfo &DCI) const;
84   SDValue performMulhsCombine(SDNode *N, DAGCombinerInfo &DCI) const;
85   SDValue performMulhuCombine(SDNode *N, DAGCombinerInfo &DCI) const;
86   SDValue performMulLoHi24Combine(SDNode *N, DAGCombinerInfo &DCI) const;
87   SDValue performCtlzCombine(const SDLoc &SL, SDValue Cond, SDValue LHS,
88                              SDValue RHS, DAGCombinerInfo &DCI) const;
89   SDValue performSelectCombine(SDNode *N, DAGCombinerInfo &DCI) const;
90   SDValue performFNegCombine(SDNode *N, DAGCombinerInfo &DCI) const;
91   SDValue performFAbsCombine(SDNode *N, DAGCombinerInfo &DCI) const;
92
93   static EVT getEquivalentMemType(LLVMContext &Context, EVT VT);
94
95   virtual SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
96                                      SelectionDAG &DAG) const;
97
98   /// Return 64-bit value Op as two 32-bit integers.
99   std::pair<SDValue, SDValue> split64BitValue(SDValue Op,
100                                               SelectionDAG &DAG) const;
101   SDValue getLoHalf64(SDValue Op, SelectionDAG &DAG) const;
102   SDValue getHiHalf64(SDValue Op, SelectionDAG &DAG) const;
103
104   /// \brief Split a vector load into 2 loads of half the vector.
105   SDValue SplitVectorLoad(SDValue Op, SelectionDAG &DAG) const;
106
107   /// \brief Split a vector store into 2 stores of half the vector.
108   SDValue SplitVectorStore(SDValue Op, SelectionDAG &DAG) const;
109
110   SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
111   SDValue LowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
112   SDValue LowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
113   SDValue LowerDIVREM24(SDValue Op, SelectionDAG &DAG, bool sign) const;
114   void LowerUDIVREM64(SDValue Op, SelectionDAG &DAG,
115                                     SmallVectorImpl<SDValue> &Results) const;
116   void analyzeFormalArgumentsCompute(CCState &State,
117                               const SmallVectorImpl<ISD::InputArg> &Ins) const;
118   void AnalyzeReturn(CCState &State,
119                      const SmallVectorImpl<ISD::OutputArg> &Outs) const;
120
121 public:
122   AMDGPUTargetLowering(const TargetMachine &TM, const AMDGPUSubtarget &STI);
123
124   bool mayIgnoreSignedZero(SDValue Op) const {
125     if (getTargetMachine().Options.NoSignedZerosFPMath)
126       return true;
127
128     if (const auto *BO = dyn_cast<BinaryWithFlagsSDNode>(Op))
129       return BO->Flags.hasNoSignedZeros();
130
131     return false;
132   }
133
134   bool isFAbsFree(EVT VT) const override;
135   bool isFNegFree(EVT VT) const override;
136   bool isTruncateFree(EVT Src, EVT Dest) const override;
137   bool isTruncateFree(Type *Src, Type *Dest) const override;
138
139   bool isZExtFree(Type *Src, Type *Dest) const override;
140   bool isZExtFree(EVT Src, EVT Dest) const override;
141   bool isZExtFree(SDValue Val, EVT VT2) const override;
142
143   bool isNarrowingProfitable(EVT VT1, EVT VT2) const override;
144
145   MVT getVectorIdxTy(const DataLayout &) const override;
146   bool isSelectSupported(SelectSupportKind) const override;
147
148   bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
149   bool ShouldShrinkFPConstant(EVT VT) const override;
150   bool shouldReduceLoadWidth(SDNode *Load,
151                              ISD::LoadExtType ExtType,
152                              EVT ExtVT) const override;
153
154   bool isLoadBitCastBeneficial(EVT, EVT) const final;
155
156   bool storeOfVectorConstantIsCheap(EVT MemVT,
157                                     unsigned NumElem,
158                                     unsigned AS) const override;
159   bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override;
160   bool isCheapToSpeculateCttz() const override;
161   bool isCheapToSpeculateCtlz() const override;
162
163   static CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg);
164   SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
165                       const SmallVectorImpl<ISD::OutputArg> &Outs,
166                       const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
167                       SelectionDAG &DAG) const override;
168   SDValue LowerCall(CallLoweringInfo &CLI,
169                     SmallVectorImpl<SDValue> &InVals) const override;
170
171   SDValue LowerDYNAMIC_STACKALLOC(SDValue Op,
172                                   SelectionDAG &DAG) const;
173
174   SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
175   SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
176   void ReplaceNodeResults(SDNode * N,
177                           SmallVectorImpl<SDValue> &Results,
178                           SelectionDAG &DAG) const override;
179
180   SDValue combineFMinMaxLegacy(const SDLoc &DL, EVT VT, SDValue LHS,
181                                SDValue RHS, SDValue True, SDValue False,
182                                SDValue CC, DAGCombinerInfo &DCI) const;
183
184   const char* getTargetNodeName(unsigned Opcode) const override;
185
186   bool isFsqrtCheap(SDValue Operand, SelectionDAG &DAG) const override {
187     return true;
188   }
189   SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
190                            int &RefinementSteps, bool &UseOneConstNR,
191                            bool Reciprocal) const override;
192   SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
193                            int &RefinementSteps) const override;
194
195   virtual SDNode *PostISelFolding(MachineSDNode *N,
196                                   SelectionDAG &DAG) const = 0;
197
198   /// \brief Determine which of the bits specified in \p Mask are known to be
199   /// either zero or one and return them in the \p KnownZero and \p KnownOne
200   /// bitsets.
201   void computeKnownBitsForTargetNode(const SDValue Op,
202                                      APInt &KnownZero,
203                                      APInt &KnownOne,
204                                      const APInt &DemandedElts,
205                                      const SelectionDAG &DAG,
206                                      unsigned Depth = 0) const override;
207
208   unsigned ComputeNumSignBitsForTargetNode(SDValue Op, const APInt &DemandedElts,
209                                            const SelectionDAG &DAG,
210                                            unsigned Depth = 0) const override;
211
212   /// \brief Helper function that adds Reg to the LiveIn list of the DAG's
213   /// MachineFunction.
214   ///
215   /// \returns a RegisterSDNode representing Reg.
216   virtual SDValue CreateLiveInRegister(SelectionDAG &DAG,
217                                        const TargetRegisterClass *RC,
218                                        unsigned Reg, EVT VT) const;
219
220   enum ImplicitParameter {
221     FIRST_IMPLICIT,
222     GRID_DIM = FIRST_IMPLICIT,
223     GRID_OFFSET,
224   };
225
226   /// \brief Helper function that returns the byte offset of the given
227   /// type of implicit parameter.
228   uint32_t getImplicitParameterOffset(const AMDGPUMachineFunction *MFI,
229                                       const ImplicitParameter Param) const;
230
231   AMDGPUAS getAMDGPUAS() const {
232     return AMDGPUASI;
233   }
234 };
235
236 namespace AMDGPUISD {
237
238 enum NodeType : unsigned {
239   // AMDIL ISD Opcodes
240   FIRST_NUMBER = ISD::BUILTIN_OP_END,
241   UMUL,        // 32bit unsigned multiplication
242   BRANCH_COND,
243   // End AMDIL ISD Opcodes
244
245   // Function call.
246   CALL,
247
248   // Masked control flow nodes.
249   IF,
250   ELSE,
251   LOOP,
252
253   // A uniform kernel return that terminates the wavefront.
254   ENDPGM,
255
256   // Return to a shader part's epilog code.
257   RETURN_TO_EPILOG,
258
259   // Return with values from a non-entry function.
260   RET_FLAG,
261
262   DWORDADDR,
263   FRACT,
264
265   /// CLAMP value between 0.0 and 1.0. NaN clamped to 0, following clamp output
266   /// modifier behavior with dx10_enable.
267   CLAMP,
268
269   // This is SETCC with the full mask result which is used for a compare with a
270   // result bit per item in the wavefront.
271   SETCC,
272   SETREG,
273   // FP ops with input and output chain.
274   FMA_W_CHAIN,
275   FMUL_W_CHAIN,
276
277   // SIN_HW, COS_HW - f32 for SI, 1 ULP max error, valid from -100 pi to 100 pi.
278   // Denormals handled on some parts.
279   COS_HW,
280   SIN_HW,
281   FMAX_LEGACY,
282   FMIN_LEGACY,
283   FMAX3,
284   SMAX3,
285   UMAX3,
286   FMIN3,
287   SMIN3,
288   UMIN3,
289   FMED3,
290   SMED3,
291   UMED3,
292   URECIP,
293   DIV_SCALE,
294   DIV_FMAS,
295   DIV_FIXUP,
296   // For emitting ISD::FMAD when f32 denormals are enabled because mac/mad is
297   // treated as an illegal operation.
298   FMAD_FTZ,
299   TRIG_PREOP, // 1 ULP max error for f64
300
301   // RCP, RSQ - For f32, 1 ULP max error, no denormal handling.
302   //            For f64, max error 2^29 ULP, handles denormals.
303   RCP,
304   RSQ,
305   RCP_LEGACY,
306   RSQ_LEGACY,
307   FMUL_LEGACY,
308   RSQ_CLAMP,
309   LDEXP,
310   FP_CLASS,
311   DOT4,
312   CARRY,
313   BORROW,
314   BFE_U32, // Extract range of bits with zero extension to 32-bits.
315   BFE_I32, // Extract range of bits with sign extension to 32-bits.
316   BFI, // (src0 & src1) | (~src0 & src2)
317   BFM, // Insert a range of bits into a 32-bit word.
318   FFBH_U32, // ctlz with -1 if input is zero.
319   FFBH_I32,
320   MUL_U24,
321   MUL_I24,
322   MULHI_U24,
323   MULHI_I24,
324   MAD_U24,
325   MAD_I24,
326   MUL_LOHI_I24,
327   MUL_LOHI_U24,
328   TEXTURE_FETCH,
329   EXPORT, // exp on SI+
330   EXPORT_DONE, // exp on SI+ with done bit set
331   R600_EXPORT,
332   CONST_ADDRESS,
333   REGISTER_LOAD,
334   REGISTER_STORE,
335   SAMPLE,
336   SAMPLEB,
337   SAMPLED,
338   SAMPLEL,
339
340   // These cvt_f32_ubyte* nodes need to remain consecutive and in order.
341   CVT_F32_UBYTE0,
342   CVT_F32_UBYTE1,
343   CVT_F32_UBYTE2,
344   CVT_F32_UBYTE3,
345
346   // Convert two float 32 numbers into a single register holding two packed f16
347   // with round to zero.
348   CVT_PKRTZ_F16_F32,
349
350   // Same as the standard node, except the high bits of the resulting integer
351   // are known 0.
352   FP_TO_FP16,
353
354   // Wrapper around fp16 results that are known to zero the high bits.
355   FP16_ZEXT,
356
357   /// This node is for VLIW targets and it is used to represent a vector
358   /// that is stored in consecutive registers with the same channel.
359   /// For example:
360   ///   |X  |Y|Z|W|
361   /// T0|v.x| | | |
362   /// T1|v.y| | | |
363   /// T2|v.z| | | |
364   /// T3|v.w| | | |
365   BUILD_VERTICAL_VECTOR,
366   /// Pointer to the start of the shader's constant data.
367   CONST_DATA_PTR,
368   SENDMSG,
369   SENDMSGHALT,
370   INTERP_MOV,
371   INTERP_P1,
372   INTERP_P2,
373   PC_ADD_REL_OFFSET,
374   KILL,
375   DUMMY_CHAIN,
376   FIRST_MEM_OPCODE_NUMBER = ISD::FIRST_TARGET_MEMORY_OPCODE,
377   STORE_MSKOR,
378   LOAD_CONSTANT,
379   TBUFFER_STORE_FORMAT,
380   ATOMIC_CMP_SWAP,
381   ATOMIC_INC,
382   ATOMIC_DEC,
383   BUFFER_LOAD,
384   BUFFER_LOAD_FORMAT,
385   LAST_AMDGPU_ISD_NUMBER
386 };
387
388
389 } // End namespace AMDGPUISD
390
391 } // End namespace llvm
392
393 #endif