]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.h
Merge ^/head r318380 through r318559.
[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     const auto Flags = Op.getNode()->getFlags();
129     if (Flags.isDefined())
130       return Flags.hasNoSignedZeros();
131
132     return false;
133   }
134
135   static bool allUsesHaveSourceMods(const SDNode *N,
136                                     unsigned CostThreshold = 4);
137   bool isFAbsFree(EVT VT) const override;
138   bool isFNegFree(EVT VT) const override;
139   bool isTruncateFree(EVT Src, EVT Dest) const override;
140   bool isTruncateFree(Type *Src, Type *Dest) const override;
141
142   bool isZExtFree(Type *Src, Type *Dest) const override;
143   bool isZExtFree(EVT Src, EVT Dest) const override;
144   bool isZExtFree(SDValue Val, EVT VT2) const override;
145
146   bool isNarrowingProfitable(EVT VT1, EVT VT2) const override;
147
148   MVT getVectorIdxTy(const DataLayout &) const override;
149   bool isSelectSupported(SelectSupportKind) const override;
150
151   bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
152   bool ShouldShrinkFPConstant(EVT VT) const override;
153   bool shouldReduceLoadWidth(SDNode *Load,
154                              ISD::LoadExtType ExtType,
155                              EVT ExtVT) const override;
156
157   bool isLoadBitCastBeneficial(EVT, EVT) const final;
158
159   bool storeOfVectorConstantIsCheap(EVT MemVT,
160                                     unsigned NumElem,
161                                     unsigned AS) const override;
162   bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override;
163   bool isCheapToSpeculateCttz() const override;
164   bool isCheapToSpeculateCtlz() const override;
165
166   static CCAssignFn *CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg);
167   SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
168                       const SmallVectorImpl<ISD::OutputArg> &Outs,
169                       const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
170                       SelectionDAG &DAG) const override;
171   SDValue LowerCall(CallLoweringInfo &CLI,
172                     SmallVectorImpl<SDValue> &InVals) const override;
173
174   SDValue LowerDYNAMIC_STACKALLOC(SDValue Op,
175                                   SelectionDAG &DAG) const;
176
177   SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
178   SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
179   void ReplaceNodeResults(SDNode * N,
180                           SmallVectorImpl<SDValue> &Results,
181                           SelectionDAG &DAG) const override;
182
183   SDValue combineFMinMaxLegacy(const SDLoc &DL, EVT VT, SDValue LHS,
184                                SDValue RHS, SDValue True, SDValue False,
185                                SDValue CC, DAGCombinerInfo &DCI) const;
186
187   const char* getTargetNodeName(unsigned Opcode) const override;
188
189   bool isFsqrtCheap(SDValue Operand, SelectionDAG &DAG) const override {
190     return true;
191   }
192   SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
193                            int &RefinementSteps, bool &UseOneConstNR,
194                            bool Reciprocal) const override;
195   SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
196                            int &RefinementSteps) const override;
197
198   virtual SDNode *PostISelFolding(MachineSDNode *N,
199                                   SelectionDAG &DAG) const = 0;
200
201   /// \brief Determine which of the bits specified in \p Mask are known to be
202   /// either zero or one and return them in the \p KnownZero and \p KnownOne
203   /// bitsets.
204   void computeKnownBitsForTargetNode(const SDValue Op,
205                                      KnownBits &Known,
206                                      const APInt &DemandedElts,
207                                      const SelectionDAG &DAG,
208                                      unsigned Depth = 0) const override;
209
210   unsigned ComputeNumSignBitsForTargetNode(SDValue Op, const APInt &DemandedElts,
211                                            const SelectionDAG &DAG,
212                                            unsigned Depth = 0) const override;
213
214   /// \brief Helper function that adds Reg to the LiveIn list of the DAG's
215   /// MachineFunction.
216   ///
217   /// \returns a RegisterSDNode representing Reg.
218   virtual SDValue CreateLiveInRegister(SelectionDAG &DAG,
219                                        const TargetRegisterClass *RC,
220                                        unsigned Reg, EVT VT) const;
221
222   enum ImplicitParameter {
223     FIRST_IMPLICIT,
224     GRID_DIM = FIRST_IMPLICIT,
225     GRID_OFFSET,
226   };
227
228   /// \brief Helper function that returns the byte offset of the given
229   /// type of implicit parameter.
230   uint32_t getImplicitParameterOffset(const AMDGPUMachineFunction *MFI,
231                                       const ImplicitParameter Param) const;
232
233   AMDGPUAS getAMDGPUAS() const {
234     return AMDGPUASI;
235   }
236
237   MVT getFenceOperandTy(const DataLayout &DL) const override {
238     return MVT::i32;
239   }
240 };
241
242 namespace AMDGPUISD {
243
244 enum NodeType : unsigned {
245   // AMDIL ISD Opcodes
246   FIRST_NUMBER = ISD::BUILTIN_OP_END,
247   UMUL,        // 32bit unsigned multiplication
248   BRANCH_COND,
249   // End AMDIL ISD Opcodes
250
251   // Function call.
252   CALL,
253   TRAP,
254
255   // Masked control flow nodes.
256   IF,
257   ELSE,
258   LOOP,
259
260   // A uniform kernel return that terminates the wavefront.
261   ENDPGM,
262
263   // Return to a shader part's epilog code.
264   RETURN_TO_EPILOG,
265
266   // Return with values from a non-entry function.
267   RET_FLAG,
268
269   DWORDADDR,
270   FRACT,
271
272   /// CLAMP value between 0.0 and 1.0. NaN clamped to 0, following clamp output
273   /// modifier behavior with dx10_enable.
274   CLAMP,
275
276   // This is SETCC with the full mask result which is used for a compare with a
277   // result bit per item in the wavefront.
278   SETCC,
279   SETREG,
280   // FP ops with input and output chain.
281   FMA_W_CHAIN,
282   FMUL_W_CHAIN,
283
284   // SIN_HW, COS_HW - f32 for SI, 1 ULP max error, valid from -100 pi to 100 pi.
285   // Denormals handled on some parts.
286   COS_HW,
287   SIN_HW,
288   FMAX_LEGACY,
289   FMIN_LEGACY,
290   FMAX3,
291   SMAX3,
292   UMAX3,
293   FMIN3,
294   SMIN3,
295   UMIN3,
296   FMED3,
297   SMED3,
298   UMED3,
299   URECIP,
300   DIV_SCALE,
301   DIV_FMAS,
302   DIV_FIXUP,
303   // For emitting ISD::FMAD when f32 denormals are enabled because mac/mad is
304   // treated as an illegal operation.
305   FMAD_FTZ,
306   TRIG_PREOP, // 1 ULP max error for f64
307
308   // RCP, RSQ - For f32, 1 ULP max error, no denormal handling.
309   //            For f64, max error 2^29 ULP, handles denormals.
310   RCP,
311   RSQ,
312   RCP_LEGACY,
313   RSQ_LEGACY,
314   FMUL_LEGACY,
315   RSQ_CLAMP,
316   LDEXP,
317   FP_CLASS,
318   DOT4,
319   CARRY,
320   BORROW,
321   BFE_U32, // Extract range of bits with zero extension to 32-bits.
322   BFE_I32, // Extract range of bits with sign extension to 32-bits.
323   BFI, // (src0 & src1) | (~src0 & src2)
324   BFM, // Insert a range of bits into a 32-bit word.
325   FFBH_U32, // ctlz with -1 if input is zero.
326   FFBH_I32,
327   MUL_U24,
328   MUL_I24,
329   MULHI_U24,
330   MULHI_I24,
331   MAD_U24,
332   MAD_I24,
333   MUL_LOHI_I24,
334   MUL_LOHI_U24,
335   TEXTURE_FETCH,
336   EXPORT, // exp on SI+
337   EXPORT_DONE, // exp on SI+ with done bit set
338   R600_EXPORT,
339   CONST_ADDRESS,
340   REGISTER_LOAD,
341   REGISTER_STORE,
342   SAMPLE,
343   SAMPLEB,
344   SAMPLED,
345   SAMPLEL,
346
347   // These cvt_f32_ubyte* nodes need to remain consecutive and in order.
348   CVT_F32_UBYTE0,
349   CVT_F32_UBYTE1,
350   CVT_F32_UBYTE2,
351   CVT_F32_UBYTE3,
352
353   // Convert two float 32 numbers into a single register holding two packed f16
354   // with round to zero.
355   CVT_PKRTZ_F16_F32,
356
357   // Same as the standard node, except the high bits of the resulting integer
358   // are known 0.
359   FP_TO_FP16,
360
361   // Wrapper around fp16 results that are known to zero the high bits.
362   FP16_ZEXT,
363
364   /// This node is for VLIW targets and it is used to represent a vector
365   /// that is stored in consecutive registers with the same channel.
366   /// For example:
367   ///   |X  |Y|Z|W|
368   /// T0|v.x| | | |
369   /// T1|v.y| | | |
370   /// T2|v.z| | | |
371   /// T3|v.w| | | |
372   BUILD_VERTICAL_VECTOR,
373   /// Pointer to the start of the shader's constant data.
374   CONST_DATA_PTR,
375   INIT_EXEC,
376   INIT_EXEC_FROM_INPUT,
377   SENDMSG,
378   SENDMSGHALT,
379   INTERP_MOV,
380   INTERP_P1,
381   INTERP_P2,
382   PC_ADD_REL_OFFSET,
383   KILL,
384   DUMMY_CHAIN,
385   FIRST_MEM_OPCODE_NUMBER = ISD::FIRST_TARGET_MEMORY_OPCODE,
386   STORE_MSKOR,
387   LOAD_CONSTANT,
388   TBUFFER_STORE_FORMAT,
389   ATOMIC_CMP_SWAP,
390   ATOMIC_INC,
391   ATOMIC_DEC,
392   BUFFER_LOAD,
393   BUFFER_LOAD_FORMAT,
394   LAST_AMDGPU_ISD_NUMBER
395 };
396
397
398 } // End namespace AMDGPUISD
399
400 } // End namespace llvm
401
402 #endif