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
19 #include "llvm/Target/TargetLowering.h"
23 class AMDGPUMachineFunction;
24 class AMDGPUSubtarget;
25 class MachineRegisterInfo;
27 class AMDGPUTargetLowering : public TargetLowering {
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
33 SDValue getFFBH_U32(SelectionDAG &DAG, SDValue Op, const SDLoc &DL) const;
36 const AMDGPUSubtarget *Subtarget;
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.
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;
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;
55 SDValue LowerCTLZ(SDValue Op, SelectionDAG &DAG) const;
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;
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;
67 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
70 bool shouldCombineMemoryType(EVT VT) const;
71 SDValue performLoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
72 SDValue performStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const;
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;
88 static EVT getEquivalentMemType(LLVMContext &Context, EVT VT);
90 virtual SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
91 SelectionDAG &DAG) const;
93 /// Return 64-bit value Op as two 32-bit integers.
94 std::pair<SDValue, SDValue> split64BitValue(SDValue Op,
95 SelectionDAG &DAG) const;
96 SDValue getLoHalf64(SDValue Op, SelectionDAG &DAG) const;
97 SDValue getHiHalf64(SDValue Op, SelectionDAG &DAG) const;
99 /// \brief Split a vector load into 2 loads of half the vector.
100 SDValue SplitVectorLoad(SDValue Op, SelectionDAG &DAG) const;
102 /// \brief Split a vector store into 2 stores of half the vector.
103 SDValue SplitVectorStore(SDValue Op, SelectionDAG &DAG) const;
105 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
106 SDValue LowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
107 SDValue LowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
108 SDValue LowerDIVREM24(SDValue Op, SelectionDAG &DAG, bool sign) const;
109 void LowerUDIVREM64(SDValue Op, SelectionDAG &DAG,
110 SmallVectorImpl<SDValue> &Results) const;
111 void analyzeFormalArgumentsCompute(CCState &State,
112 const SmallVectorImpl<ISD::InputArg> &Ins) const;
113 void AnalyzeFormalArguments(CCState &State,
114 const SmallVectorImpl<ISD::InputArg> &Ins) const;
115 void AnalyzeReturn(CCState &State,
116 const SmallVectorImpl<ISD::OutputArg> &Outs) const;
119 AMDGPUTargetLowering(const TargetMachine &TM, const AMDGPUSubtarget &STI);
121 bool isFAbsFree(EVT VT) const override;
122 bool isFNegFree(EVT VT) const override;
123 bool isTruncateFree(EVT Src, EVT Dest) const override;
124 bool isTruncateFree(Type *Src, Type *Dest) const override;
126 bool isZExtFree(Type *Src, Type *Dest) const override;
127 bool isZExtFree(EVT Src, EVT Dest) const override;
128 bool isZExtFree(SDValue Val, EVT VT2) const override;
130 bool isNarrowingProfitable(EVT VT1, EVT VT2) const override;
132 MVT getVectorIdxTy(const DataLayout &) const override;
133 bool isSelectSupported(SelectSupportKind) const override;
135 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
136 bool ShouldShrinkFPConstant(EVT VT) const override;
137 bool shouldReduceLoadWidth(SDNode *Load,
138 ISD::LoadExtType ExtType,
139 EVT ExtVT) const override;
141 bool isLoadBitCastBeneficial(EVT, EVT) const final;
143 bool storeOfVectorConstantIsCheap(EVT MemVT,
145 unsigned AS) const override;
146 bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override;
147 bool isCheapToSpeculateCttz() const override;
148 bool isCheapToSpeculateCtlz() const override;
150 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
151 const SmallVectorImpl<ISD::OutputArg> &Outs,
152 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
153 SelectionDAG &DAG) const override;
154 SDValue LowerCall(CallLoweringInfo &CLI,
155 SmallVectorImpl<SDValue> &InVals) const override;
157 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op,
158 SelectionDAG &DAG) const;
160 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
161 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
162 void ReplaceNodeResults(SDNode * N,
163 SmallVectorImpl<SDValue> &Results,
164 SelectionDAG &DAG) const override;
166 SDValue CombineFMinMaxLegacy(const SDLoc &DL, EVT VT, SDValue LHS,
167 SDValue RHS, SDValue True, SDValue False,
168 SDValue CC, DAGCombinerInfo &DCI) const;
170 const char* getTargetNodeName(unsigned Opcode) const override;
172 bool isFsqrtCheap(SDValue Operand, SelectionDAG &DAG) const override {
175 SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
176 int &RefinementSteps, bool &UseOneConstNR,
177 bool Reciprocal) const override;
178 SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled,
179 int &RefinementSteps) const override;
181 virtual SDNode *PostISelFolding(MachineSDNode *N,
182 SelectionDAG &DAG) const = 0;
184 /// \brief Determine which of the bits specified in \p Mask are known to be
185 /// either zero or one and return them in the \p KnownZero and \p KnownOne
187 void computeKnownBitsForTargetNode(const SDValue Op,
190 const SelectionDAG &DAG,
191 unsigned Depth = 0) const override;
193 unsigned ComputeNumSignBitsForTargetNode(SDValue Op, const SelectionDAG &DAG,
194 unsigned Depth = 0) const override;
196 /// \brief Helper function that adds Reg to the LiveIn list of the DAG's
199 /// \returns a RegisterSDNode representing Reg.
200 virtual SDValue CreateLiveInRegister(SelectionDAG &DAG,
201 const TargetRegisterClass *RC,
202 unsigned Reg, EVT VT) const;
204 enum ImplicitParameter {
206 GRID_DIM = FIRST_IMPLICIT,
210 /// \brief Helper function that returns the byte offset of the given
211 /// type of implicit parameter.
212 uint32_t getImplicitParameterOffset(const AMDGPUMachineFunction *MFI,
213 const ImplicitParameter Param) const;
216 namespace AMDGPUISD {
218 enum NodeType : unsigned {
220 FIRST_NUMBER = ISD::BUILTIN_OP_END,
221 CALL, // Function call based on a single integer
222 UMUL, // 32bit unsigned multiplication
224 // End AMDIL ISD Opcodes
230 // This is SETCC with the full mask result which is used for a compare with a
231 // result bit per item in the wavefront.
234 // FP ops with input and output chain.
238 // SIN_HW, COS_HW - f32 for SI, 1 ULP max error, valid from -100 pi to 100 pi.
239 // Denormals handled on some parts.
257 TRIG_PREOP, // 1 ULP max error for f64
259 // RCP, RSQ - For f32, 1 ULP max error, no denormal handling.
260 // For f64, max error 2^29 ULP, handles denormals.
272 BFE_U32, // Extract range of bits with zero extension to 32-bits.
273 BFE_I32, // Extract range of bits with sign extension to 32-bits.
274 BFI, // (src0 & src1) | (~src0 & src2)
275 BFM, // Insert a range of bits into a 32-bit word.
276 FFBH_U32, // ctlz with -1 if input is zero.
287 EXPORT, // exp on SI+
288 EXPORT_DONE, // exp on SI+ with done bit set
299 // These cvt_f32_ubyte* nodes need to remain consecutive and in order.
304 /// This node is for VLIW targets and it is used to represent a vector
305 /// that is stored in consecutive registers with the same channel.
312 BUILD_VERTICAL_VECTOR,
313 /// Pointer to the start of the shader's constant data.
322 FIRST_MEM_OPCODE_NUMBER = ISD::FIRST_TARGET_MEMORY_OPCODE,
325 TBUFFER_STORE_FORMAT,
331 LAST_AMDGPU_ISD_NUMBER
335 } // End namespace AMDGPUISD
337 } // End namespace llvm