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 LowerConstantInitializer(const Constant* Init, const GlobalValue *GV,
32 const SDValue &InitPtr,
34 SelectionDAG &DAG) const;
35 SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
36 SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const;
37 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
38 /// \brief Lower vector stores by merging the vector elements into an integer
39 /// of the same bitwidth.
40 SDValue MergeVectorStore(const 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_UINT(SDValue Op, SelectionDAG &DAG) const;
64 SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const;
66 SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const;
69 bool shouldCombineMemoryType(EVT VT) const;
70 SDValue performLoadCombine(SDNode *N, DAGCombinerInfo &DCI) const;
71 SDValue performStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const;
72 SDValue performAndCombine(SDNode *N, DAGCombinerInfo &DCI) const;
73 SDValue performShlCombine(SDNode *N, DAGCombinerInfo &DCI) const;
74 SDValue performSraCombine(SDNode *N, DAGCombinerInfo &DCI) const;
75 SDValue performSrlCombine(SDNode *N, DAGCombinerInfo &DCI) const;
76 SDValue performMulCombine(SDNode *N, DAGCombinerInfo &DCI) const;
77 SDValue performCtlzCombine(const SDLoc &SL, SDValue Cond, SDValue LHS,
78 SDValue RHS, DAGCombinerInfo &DCI) const;
79 SDValue performSelectCombine(SDNode *N, DAGCombinerInfo &DCI) const;
81 static EVT getEquivalentMemType(LLVMContext &Context, EVT VT);
82 static EVT getEquivalentBitType(LLVMContext &Context, EVT VT);
84 virtual SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
85 SelectionDAG &DAG) const;
87 /// Return 64-bit value Op as two 32-bit integers.
88 std::pair<SDValue, SDValue> split64BitValue(SDValue Op,
89 SelectionDAG &DAG) const;
90 SDValue getLoHalf64(SDValue Op, SelectionDAG &DAG) const;
91 SDValue getHiHalf64(SDValue Op, SelectionDAG &DAG) const;
93 /// \brief Split a vector load into 2 loads of half the vector.
94 SDValue SplitVectorLoad(SDValue Op, SelectionDAG &DAG) const;
96 /// \brief Split a vector store into 2 stores of half the vector.
97 SDValue SplitVectorStore(SDValue Op, SelectionDAG &DAG) const;
99 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
100 SDValue LowerSDIVREM(SDValue Op, SelectionDAG &DAG) const;
101 SDValue LowerUDIVREM(SDValue Op, SelectionDAG &DAG) const;
102 SDValue LowerDIVREM24(SDValue Op, SelectionDAG &DAG, bool sign) const;
103 void LowerUDIVREM64(SDValue Op, SelectionDAG &DAG,
104 SmallVectorImpl<SDValue> &Results) const;
105 /// The SelectionDAGBuilder will automatically promote function arguments
106 /// with illegal types. However, this does not work for the AMDGPU targets
107 /// since the function arguments are stored in memory as these illegal types.
108 /// In order to handle this properly we need to get the origianl types sizes
109 /// from the LLVM IR Function and fixup the ISD:InputArg values before
110 /// passing them to AnalyzeFormalArguments()
111 void getOriginalFunctionArgs(SelectionDAG &DAG,
113 const SmallVectorImpl<ISD::InputArg> &Ins,
114 SmallVectorImpl<ISD::InputArg> &OrigIns) const;
115 void AnalyzeFormalArguments(CCState &State,
116 const SmallVectorImpl<ISD::InputArg> &Ins) const;
117 void AnalyzeReturn(CCState &State,
118 const SmallVectorImpl<ISD::OutputArg> &Outs) const;
121 AMDGPUTargetLowering(const TargetMachine &TM, const AMDGPUSubtarget &STI);
123 bool isFAbsFree(EVT VT) const override;
124 bool isFNegFree(EVT VT) const override;
125 bool isTruncateFree(EVT Src, EVT Dest) const override;
126 bool isTruncateFree(Type *Src, Type *Dest) const override;
128 bool isZExtFree(Type *Src, Type *Dest) const override;
129 bool isZExtFree(EVT Src, EVT Dest) const override;
130 bool isZExtFree(SDValue Val, EVT VT2) const override;
132 bool isNarrowingProfitable(EVT VT1, EVT VT2) const override;
134 MVT getVectorIdxTy(const DataLayout &) const override;
135 bool isSelectSupported(SelectSupportKind) const override;
137 bool isFPImmLegal(const APFloat &Imm, EVT VT) const override;
138 bool ShouldShrinkFPConstant(EVT VT) const override;
139 bool shouldReduceLoadWidth(SDNode *Load,
140 ISD::LoadExtType ExtType,
141 EVT ExtVT) const override;
143 bool isLoadBitCastBeneficial(EVT, EVT) const final;
145 bool storeOfVectorConstantIsCheap(EVT MemVT,
147 unsigned AS) const override;
148 bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override;
149 bool isCheapToSpeculateCttz() const override;
150 bool isCheapToSpeculateCtlz() const override;
152 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
153 const SmallVectorImpl<ISD::OutputArg> &Outs,
154 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
155 SelectionDAG &DAG) const override;
156 SDValue LowerCall(CallLoweringInfo &CLI,
157 SmallVectorImpl<SDValue> &InVals) const override;
159 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op,
160 SelectionDAG &DAG) const;
162 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
163 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
164 void ReplaceNodeResults(SDNode * N,
165 SmallVectorImpl<SDValue> &Results,
166 SelectionDAG &DAG) const override;
168 SDValue CombineFMinMaxLegacy(const SDLoc &DL, EVT VT, SDValue LHS,
169 SDValue RHS, SDValue True, SDValue False,
170 SDValue CC, DAGCombinerInfo &DCI) const;
172 const char* getTargetNodeName(unsigned Opcode) const override;
174 SDValue getRsqrtEstimate(SDValue Operand,
175 DAGCombinerInfo &DCI,
176 unsigned &RefinementSteps,
177 bool &UseOneConstNR) const override;
178 SDValue getRecipEstimate(SDValue Operand,
179 DAGCombinerInfo &DCI,
180 unsigned &RefinementSteps) const override;
182 virtual SDNode *PostISelFolding(MachineSDNode *N,
183 SelectionDAG &DAG) const = 0;
185 /// \brief Determine which of the bits specified in \p Mask are known to be
186 /// either zero or one and return them in the \p KnownZero and \p KnownOne
188 void computeKnownBitsForTargetNode(const SDValue Op,
191 const SelectionDAG &DAG,
192 unsigned Depth = 0) const override;
194 unsigned ComputeNumSignBitsForTargetNode(SDValue Op, const SelectionDAG &DAG,
195 unsigned Depth = 0) const override;
197 /// \brief Helper function that adds Reg to the LiveIn list of the DAG's
200 /// \returns a RegisterSDNode representing Reg.
201 virtual SDValue CreateLiveInRegister(SelectionDAG &DAG,
202 const TargetRegisterClass *RC,
203 unsigned Reg, EVT VT) const;
205 enum ImplicitParameter {
207 GRID_DIM = FIRST_IMPLICIT,
211 /// \brief Helper function that returns the byte offset of the given
212 /// type of implicit parameter.
213 uint32_t getImplicitParameterOffset(const AMDGPUMachineFunction *MFI,
214 const ImplicitParameter Param) const;
217 namespace AMDGPUISD {
219 enum NodeType : unsigned {
221 FIRST_NUMBER = ISD::BUILTIN_OP_END,
222 CALL, // Function call based on a single integer
223 UMUL, // 32bit unsigned multiplication
225 // End AMDIL ISD Opcodes
232 // SIN_HW, COS_HW - f32 for SI, 1 ULP max error, valid from -100 pi to 100 pi.
233 // Denormals handled on some parts.
251 TRIG_PREOP, // 1 ULP max error for f64
253 // RCP, RSQ - For f32, 1 ULP max error, no denormal handling.
254 // For f64, max error 2^29 ULP, handles denormals.
264 BFE_U32, // Extract range of bits with zero extension to 32-bits.
265 BFE_I32, // Extract range of bits with sign extension to 32-bits.
266 BFI, // (src0 & src1) | (~src0 & src2)
267 BFM, // Insert a range of bits into a 32-bit word.
268 FFBH_U32, // ctlz with -1 if input is zero.
284 // These cvt_f32_ubyte* nodes need to remain consecutive and in order.
289 /// This node is for VLIW targets and it is used to represent a vector
290 /// that is stored in consecutive registers with the same channel.
297 BUILD_VERTICAL_VECTOR,
298 /// Pointer to the start of the shader's constant data.
305 FIRST_MEM_OPCODE_NUMBER = ISD::FIRST_TARGET_MEMORY_OPCODE,
308 TBUFFER_STORE_FORMAT,
312 LAST_AMDGPU_ISD_NUMBER
316 } // End namespace AMDGPUISD
318 } // End namespace llvm