1 //===-- AMDGPUISelLowering.h - AMDGPU Lowering Interface --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Interface definition of the TargetLowering class that is common
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUISELLOWERING_H
17 #define LLVM_LIB_TARGET_AMDGPU_AMDGPUISELLOWERING_H
20 #include "llvm/CodeGen/CallingConvLower.h"
21 #include "llvm/Target/TargetLowering.h"
25 class AMDGPUMachineFunction;
26 class AMDGPUSubtarget;
27 class MachineRegisterInfo;
29 class AMDGPUTargetLowering : public TargetLowering {
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
35 SDValue getFFBH_U32(SelectionDAG &DAG, SDValue Op, const SDLoc &DL) const;
38 const AMDGPUSubtarget *Subtarget;
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.
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;
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;
57 SDValue LowerCTLZ(SDValue Op, SelectionDAG &DAG) const;
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;
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;
69 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
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;
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;
93 static EVT getEquivalentMemType(LLVMContext &Context, EVT VT);
95 virtual SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
96 SelectionDAG &DAG) const;
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;
104 /// \brief Split a vector load into 2 loads of half the vector.
105 SDValue SplitVectorLoad(SDValue Op, SelectionDAG &DAG) const;
107 /// \brief Split a vector store into 2 stores of half the vector.
108 SDValue SplitVectorStore(SDValue Op, SelectionDAG &DAG) const;
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;
122 AMDGPUTargetLowering(const TargetMachine &TM, const AMDGPUSubtarget &STI);
124 bool mayIgnoreSignedZero(SDValue Op) const {
125 if (getTargetMachine().Options.NoSignedZerosFPMath)
128 const auto Flags = Op.getNode()->getFlags();
129 if (Flags.isDefined())
130 return Flags.hasNoSignedZeros();
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;
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;
146 bool isNarrowingProfitable(EVT VT1, EVT VT2) const override;
148 MVT getVectorIdxTy(const DataLayout &) const override;
149 bool isSelectSupported(SelectSupportKind) const override;
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;
157 bool isLoadBitCastBeneficial(EVT, EVT) const final;
159 bool storeOfVectorConstantIsCheap(EVT MemVT,
161 unsigned AS) const override;
162 bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override;
163 bool isCheapToSpeculateCttz() const override;
164 bool isCheapToSpeculateCtlz() const override;
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;
174 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op,
175 SelectionDAG &DAG) const;
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;
183 SDValue combineFMinMaxLegacy(const SDLoc &DL, EVT VT, SDValue LHS,
184 SDValue RHS, SDValue True, SDValue False,
185 SDValue CC, DAGCombinerInfo &DCI) const;
187 const char* getTargetNodeName(unsigned Opcode) const override;
189 bool isFsqrtCheap(SDValue Operand, SelectionDAG &DAG) const override {
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;
198 virtual SDNode *PostISelFolding(MachineSDNode *N,
199 SelectionDAG &DAG) const = 0;
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
204 void computeKnownBitsForTargetNode(const SDValue Op,
206 const APInt &DemandedElts,
207 const SelectionDAG &DAG,
208 unsigned Depth = 0) const override;
210 unsigned ComputeNumSignBitsForTargetNode(SDValue Op, const APInt &DemandedElts,
211 const SelectionDAG &DAG,
212 unsigned Depth = 0) const override;
214 /// \brief Helper function that adds Reg to the LiveIn list of the DAG's
217 /// \returns a RegisterSDNode representing Reg.
218 virtual SDValue CreateLiveInRegister(SelectionDAG &DAG,
219 const TargetRegisterClass *RC,
220 unsigned Reg, EVT VT) const;
222 enum ImplicitParameter {
224 GRID_DIM = FIRST_IMPLICIT,
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;
233 AMDGPUAS getAMDGPUAS() const {
237 MVT getFenceOperandTy(const DataLayout &DL) const override {
242 namespace AMDGPUISD {
244 enum NodeType : unsigned {
246 FIRST_NUMBER = ISD::BUILTIN_OP_END,
247 UMUL, // 32bit unsigned multiplication
249 // End AMDIL ISD Opcodes
255 // Masked control flow nodes.
260 // A uniform kernel return that terminates the wavefront.
263 // Return to a shader part's epilog code.
266 // Return with values from a non-entry function.
272 /// CLAMP value between 0.0 and 1.0. NaN clamped to 0, following clamp output
273 /// modifier behavior with dx10_enable.
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.
280 // FP ops with input and output chain.
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.
303 // For emitting ISD::FMAD when f32 denormals are enabled because mac/mad is
304 // treated as an illegal operation.
306 TRIG_PREOP, // 1 ULP max error for f64
308 // RCP, RSQ - For f32, 1 ULP max error, no denormal handling.
309 // For f64, max error 2^29 ULP, handles denormals.
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.
336 EXPORT, // exp on SI+
337 EXPORT_DONE, // exp on SI+ with done bit set
347 // These cvt_f32_ubyte* nodes need to remain consecutive and in order.
353 // Convert two float 32 numbers into a single register holding two packed f16
354 // with round to zero.
357 // Same as the standard node, except the high bits of the resulting integer
361 // Wrapper around fp16 results that are known to zero the high bits.
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.
372 BUILD_VERTICAL_VECTOR,
373 /// Pointer to the start of the shader's constant data.
376 INIT_EXEC_FROM_INPUT,
385 FIRST_MEM_OPCODE_NUMBER = ISD::FIRST_TARGET_MEMORY_OPCODE,
388 TBUFFER_STORE_FORMAT,
394 LAST_AMDGPU_ISD_NUMBER
398 } // End namespace AMDGPUISD
400 } // End namespace llvm