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 const AMDGPUSubtarget *Subtarget;
31 SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
32 SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
33 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
34 /// \brief Split a vector store into multiple scalar stores.
35 /// \returns The resulting chain.
37 SDValue LowerFREM(SDValue Op, SelectionDAG &DAG) const;
38 SDValue LowerFCEIL(SDValue Op, SelectionDAG &DAG) const;
39 SDValue LowerFTRUNC(SDValue Op, SelectionDAG &DAG) const;
40 SDValue LowerFRINT(SDValue Op, SelectionDAG &DAG) const;
41 SDValue LowerFNEARBYINT(SDValue Op, SelectionDAG &DAG) const;
43 SDValue LowerFROUND32(SDValue Op, SelectionDAG &DAG) const;
44 SDValue LowerFROUND64(SDValue Op, SelectionDAG &DAG) const;
45 SDValue LowerFROUND(SDValue Op, SelectionDAG &DAG) const;
46 SDValue LowerFFLOOR(SDValue Op, SelectionDAG &DAG) const;
48 SDValue LowerCTLZ(SDValue Op, SelectionDAG &DAG) const;
50 SDValue LowerINT_TO_FP32(SDValue Op, SelectionDAG &DAG, bool Signed) const;
51 SDValue LowerINT_TO_FP64(SDValue Op, SelectionDAG &DAG, bool Signed) const;
52 SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
53 SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) const;
55 SDValue LowerFP64_TO_INT(SDValue Op, SelectionDAG &DAG, bool Signed) const;
56 SDValue LowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG) const;
57 SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const;
59 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
62 bool shouldCombineMemoryType(EVT VT) const;
63 SDValue performLoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
64 SDValue performStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const;
66 SDValue splitBinaryBitConstantOpImpl(DAGCombinerInfo &DCI, const SDLoc &SL,
67 unsigned Opc, SDValue LHS,
68 uint32_t ValLo, uint32_t ValHi) const;
69 SDValue performShlCombine(SDNode *N, DAGCombinerInfo &DCI) const;
70 SDValue performSraCombine(SDNode *N, DAGCombinerInfo &DCI) const;
71 SDValue performSrlCombine(SDNode *N, DAGCombinerInfo &DCI) const;
72 SDValue performMulCombine(SDNode *N, DAGCombinerInfo &DCI) const;
73 SDValue performMulhsCombine(SDNode *N, DAGCombinerInfo &DCI) const;
74 SDValue performMulhuCombine(SDNode *N, DAGCombinerInfo &DCI) const;
75 SDValue performMulLoHi24Combine(SDNode *N, DAGCombinerInfo &DCI) const;
76 SDValue performCtlzCombine(const SDLoc &SL, SDValue Cond, SDValue LHS,
77 SDValue RHS, DAGCombinerInfo &DCI) const;
78 SDValue performSelectCombine(SDNode *N, DAGCombinerInfo &DCI) const;
80 static EVT getEquivalentMemType(LLVMContext &Context, EVT VT);
82 virtual SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
83 SelectionDAG &DAG) const;
85 /// Return 64-bit value Op as two 32-bit integers.
86 std::pair<SDValue, SDValue> split64BitValue(SDValue Op,
87 SelectionDAG &DAG) const;
88 SDValue getLoHalf64(SDValue Op, SelectionDAG &DAG) const;
89 SDValue getHiHalf64(SDValue Op, SelectionDAG &DAG) const;
91 /// \brief Split a vector load into 2 loads of half the vector.
92 SDValue SplitVectorLoad(SDValue Op, SelectionDAG &DAG) const;
94 /// \brief Split a vector store into 2 stores of half the vector.
95 SDValue SplitVectorStore(SDValue Op, SelectionDAG &DAG) const;
97 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
98 SDValue LowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
99 SDValue LowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
100 SDValue LowerDIVREM24(SDValue Op, SelectionDAG &DAG, bool sign) const;
101 void LowerUDIVREM64(SDValue Op, SelectionDAG &DAG,
102 SmallVectorImpl<SDValue> &Results) const;
103 void analyzeFormalArgumentsCompute(CCState &State,
104 const SmallVectorImpl<ISD::InputArg> &Ins) const;
105 void AnalyzeFormalArguments(CCState &State,
106 const SmallVectorImpl<ISD::InputArg> &Ins) const;
107 void AnalyzeReturn(CCState &State,
108 const SmallVectorImpl<ISD::OutputArg> &Outs) const;
111 AMDGPUTargetLowering(const TargetMachine &TM, const AMDGPUSubtarget &STI);
113 bool isFAbsFree(EVT VT) const override;
114 bool isFNegFree(EVT VT) const override;
115 bool isTruncateFree(EVT Src, EVT Dest) const override;
116 bool isTruncateFree(Type *Src, Type *Dest) const override;
118 bool isZExtFree(Type *Src, Type *Dest) const override;
119 bool isZExtFree(EVT Src, EVT Dest) const override;
120 bool isZExtFree(SDValue Val, EVT VT2) const override;
122 bool isNarrowingProfitable(EVT VT1, EVT VT2) const override;
124 MVT getVectorIdxTy(const DataLayout &) const override;
125 bool isSelectSupported(SelectSupportKind) const override;
127 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
128 bool ShouldShrinkFPConstant(EVT VT) const override;
129 bool shouldReduceLoadWidth(SDNode *Load,
130 ISD::LoadExtType ExtType,
131 EVT ExtVT) const override;
133 bool isLoadBitCastBeneficial(EVT, EVT) const final;
135 bool storeOfVectorConstantIsCheap(EVT MemVT,
137 unsigned AS) const override;
138 bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override;
139 bool isCheapToSpeculateCttz() const override;
140 bool isCheapToSpeculateCtlz() const override;
142 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
143 const SmallVectorImpl<ISD::OutputArg> &Outs,
144 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
145 SelectionDAG &DAG) const override;
146 SDValue LowerCall(CallLoweringInfo &CLI,
147 SmallVectorImpl<SDValue> &InVals) const override;
149 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op,
150 SelectionDAG &DAG) const;
152 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
153 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
154 void ReplaceNodeResults(SDNode * N,
155 SmallVectorImpl<SDValue> &Results,
156 SelectionDAG &DAG) const override;
158 SDValue CombineFMinMaxLegacy(const SDLoc &DL, EVT VT, SDValue LHS,
159 SDValue RHS, SDValue True, SDValue False,
160 SDValue CC, DAGCombinerInfo &DCI) const;
162 const char* getTargetNodeName(unsigned Opcode) const override;
164 bool isFsqrtCheap(SDValue Operand, SelectionDAG &DAG) const override {
167 SDValue getRsqrtEstimate(SDValue Operand,
168 DAGCombinerInfo &DCI,
169 unsigned &RefinementSteps,
170 bool &UseOneConstNR) const override;
171 SDValue getRecipEstimate(SDValue Operand,
172 DAGCombinerInfo &DCI,
173 unsigned &RefinementSteps) const override;
175 virtual SDNode *PostISelFolding(MachineSDNode *N,
176 SelectionDAG &DAG) const = 0;
178 /// \brief Determine which of the bits specified in \p Mask are known to be
179 /// either zero or one and return them in the \p KnownZero and \p KnownOne
181 void computeKnownBitsForTargetNode(const SDValue Op,
184 const SelectionDAG &DAG,
185 unsigned Depth = 0) const override;
187 unsigned ComputeNumSignBitsForTargetNode(SDValue Op, const SelectionDAG &DAG,
188 unsigned Depth = 0) const override;
190 /// \brief Helper function that adds Reg to the LiveIn list of the DAG's
193 /// \returns a RegisterSDNode representing Reg.
194 virtual SDValue CreateLiveInRegister(SelectionDAG &DAG,
195 const TargetRegisterClass *RC,
196 unsigned Reg, EVT VT) const;
198 enum ImplicitParameter {
200 GRID_DIM = FIRST_IMPLICIT,
204 /// \brief Helper function that returns the byte offset of the given
205 /// type of implicit parameter.
206 uint32_t getImplicitParameterOffset(const AMDGPUMachineFunction *MFI,
207 const ImplicitParameter Param) const;
210 namespace AMDGPUISD {
212 enum NodeType : unsigned {
214 FIRST_NUMBER = ISD::BUILTIN_OP_END,
215 CALL, // Function call based on a single integer
216 UMUL, // 32bit unsigned multiplication
218 // End AMDIL ISD Opcodes
224 // This is SETCC with the full mask result which is used for a compare with a
225 // result bit per item in the wavefront.
228 // SIN_HW, COS_HW - f32 for SI, 1 ULP max error, valid from -100 pi to 100 pi.
229 // Denormals handled on some parts.
247 TRIG_PREOP, // 1 ULP max error for f64
249 // RCP, RSQ - For f32, 1 ULP max error, no denormal handling.
250 // For f64, max error 2^29 ULP, handles denormals.
262 BFE_U32, // Extract range of bits with zero extension to 32-bits.
263 BFE_I32, // Extract range of bits with sign extension to 32-bits.
264 BFI, // (src0 & src1) | (~src0 & src2)
265 BFM, // Insert a range of bits into a 32-bit word.
266 FFBH_U32, // ctlz with -1 if input is zero.
287 // These cvt_f32_ubyte* nodes need to remain consecutive and in order.
292 /// This node is for VLIW targets and it is used to represent a vector
293 /// that is stored in consecutive registers with the same channel.
300 BUILD_VERTICAL_VECTOR,
301 /// Pointer to the start of the shader's constant data.
309 FIRST_MEM_OPCODE_NUMBER = ISD::FIRST_TARGET_MEMORY_OPCODE,
312 TBUFFER_STORE_FORMAT,
316 LAST_AMDGPU_ISD_NUMBER
320 } // End namespace AMDGPUISD
322 } // End namespace llvm