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