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