1//===-- SIISelLowering.h - SI DAG Lowering Interface ------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// SI DAG Lowering interface definition
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_AMDGPU_SIISELLOWERING_H
15#define LLVM_LIB_TARGET_AMDGPU_SIISELLOWERING_H
16
17#include "AMDGPUArgumentUsageInfo.h"
18#include "AMDGPUISelLowering.h"
19#include "SIDefines.h"
20#include "llvm/CodeGen/MachineFunction.h"
21
22namespace llvm {
23
24class GCNSubtarget;
25class SIMachineFunctionInfo;
26class SIRegisterInfo;
27
28namespace AMDGPU {
29struct ImageDimIntrinsicInfo;
30}
31
32class SITargetLowering final : public AMDGPUTargetLowering {
33private:
34 const GCNSubtarget *Subtarget;
35
36public:
37 MVT getRegisterTypeForCallingConv(LLVMContext &Context,
38 CallingConv::ID CC,
39 EVT VT) const override;
40 unsigned getNumRegistersForCallingConv(LLVMContext &Context,
41 CallingConv::ID CC,
42 EVT VT) const override;
43
44 unsigned getVectorTypeBreakdownForCallingConv(
45 LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT,
46 unsigned &NumIntermediates, MVT &RegisterVT) const override;
47
48 MachinePointerInfo getKernargSegmentPtrInfo(MachineFunction &MF) const;
49
50private:
51 SDValue lowerKernArgParameterPtr(SelectionDAG &DAG, const SDLoc &SL,
52 SDValue Chain, uint64_t Offset) const;
53 SDValue getImplicitArgPtr(SelectionDAG &DAG, const SDLoc &SL) const;
54 SDValue getLDSKernelId(SelectionDAG &DAG, const SDLoc &SL) const;
55 SDValue lowerKernargMemParameter(SelectionDAG &DAG, EVT VT, EVT MemVT,
56 const SDLoc &SL, SDValue Chain,
57 uint64_t Offset, Align Alignment,
58 bool Signed,
59 const ISD::InputArg *Arg = nullptr) const;
60 SDValue loadImplicitKernelArgument(SelectionDAG &DAG, MVT VT, const SDLoc &DL,
61 Align Alignment,
62 ImplicitParameter Param) const;
63
64 SDValue convertABITypeToValueType(SelectionDAG &DAG, SDValue Val,
65 CCValAssign &VA, const SDLoc &SL) const;
66
67 SDValue lowerStackParameter(SelectionDAG &DAG, CCValAssign &VA,
68 const SDLoc &SL, SDValue Chain,
69 const ISD::InputArg &Arg) const;
70 SDValue lowerWorkGroupId(
71 SelectionDAG &DAG, const SIMachineFunctionInfo &MFI, EVT VT,
72 AMDGPUFunctionArgInfo::PreloadedValue ClusterIdPV,
73 AMDGPUFunctionArgInfo::PreloadedValue ClusterMaxIdPV,
74 AMDGPUFunctionArgInfo::PreloadedValue ClusterWorkGroupIdPV) const;
75 SDValue getPreloadedValue(SelectionDAG &DAG,
76 const SIMachineFunctionInfo &MFI,
77 EVT VT,
78 AMDGPUFunctionArgInfo::PreloadedValue) const;
79
80 SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
81 SelectionDAG &DAG) const override;
82 SDValue LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) const;
83
84 SDValue lowerImplicitZextParam(SelectionDAG &DAG, SDValue Op,
85 MVT VT, unsigned Offset) const;
86 SDValue lowerImage(SDValue Op, const AMDGPU::ImageDimIntrinsicInfo *Intr,
87 SelectionDAG &DAG, bool WithChain) const;
88 SDValue lowerSBuffer(EVT VT, SDLoc DL, SDValue Rsrc, SDValue Offset,
89 SDValue CachePolicy, SelectionDAG &DAG) const;
90
91 SDValue lowerRawBufferAtomicIntrin(SDValue Op, SelectionDAG &DAG,
92 unsigned NewOpcode) const;
93 SDValue lowerStructBufferAtomicIntrin(SDValue Op, SelectionDAG &DAG,
94 unsigned NewOpcode) const;
95
96 SDValue lowerWaveID(SelectionDAG &DAG, SDValue Op) const;
97 SDValue lowerConstHwRegRead(SelectionDAG &DAG, SDValue Op,
98 AMDGPU::Hwreg::Id HwReg, unsigned LowBit,
99 unsigned Width) const;
100 SDValue lowerWorkitemID(SelectionDAG &DAG, SDValue Op, unsigned Dim,
101 const ArgDescriptor &ArgDesc) const;
102
103 SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
104 SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
105 SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
106
107 // The raw.tbuffer and struct.tbuffer intrinsics have two offset args: offset
108 // (the offset that is included in bounds checking and swizzling, to be split
109 // between the instruction's voffset and immoffset fields) and soffset (the
110 // offset that is excluded from bounds checking and swizzling, to go in the
111 // instruction's soffset field). This function takes the first kind of
112 // offset and figures out how to split it between voffset and immoffset.
113 std::pair<SDValue, SDValue> splitBufferOffsets(SDValue Offset,
114 SelectionDAG &DAG) const;
115
116 SDValue widenLoad(LoadSDNode *Ld, DAGCombinerInfo &DCI) const;
117 SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
118 SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
119 SDValue lowerFastUnsafeFDIV(SDValue Op, SelectionDAG &DAG) const;
120 SDValue lowerFastUnsafeFDIV64(SDValue Op, SelectionDAG &DAG) const;
121 SDValue lowerFDIV_FAST(SDValue Op, SelectionDAG &DAG) const;
122 SDValue LowerFDIV16(SDValue Op, SelectionDAG &DAG) const;
123 SDValue LowerFDIV32(SDValue Op, SelectionDAG &DAG) const;
124 SDValue LowerFDIV64(SDValue Op, SelectionDAG &DAG) const;
125 SDValue LowerFDIV(SDValue Op, SelectionDAG &DAG) const;
126 SDValue LowerFFREXP(SDValue Op, SelectionDAG &DAG) const;
127 SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
128 SDValue LowerTrig(SDValue Op, SelectionDAG &DAG) const;
129 SDValue lowerFSQRTF16(SDValue Op, SelectionDAG &DAG) const;
130 SDValue lowerFSQRTF32(SDValue Op, SelectionDAG &DAG) const;
131 SDValue lowerFSQRTF64(SDValue Op, SelectionDAG &DAG) const;
132 SDValue LowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
133 SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
134 SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
135 SDValue LowerSPONENTRY(SDValue Op, SelectionDAG &DAG) const;
136 SDValue adjustLoadValueType(unsigned Opcode, MemSDNode *M,
137 SelectionDAG &DAG, ArrayRef<SDValue> Ops,
138 bool IsIntrinsic = false) const;
139
140 SDValue lowerIntrinsicLoad(MemSDNode *M, bool IsFormat, SelectionDAG &DAG,
141 ArrayRef<SDValue> Ops) const;
142
143 // Call DAG.getMemIntrinsicNode for a load, but first widen a dwordx3 type to
144 // dwordx4 if on SI.
145 SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
146 ArrayRef<SDValue> Ops, EVT MemVT,
147 MachineMemOperand *MMO, SelectionDAG &DAG) const;
148
149 SDValue handleD16VData(SDValue VData, SelectionDAG &DAG,
150 bool ImageStore = false) const;
151
152 /// Converts \p Op, which must be of floating point type, to the
153 /// floating point type \p VT, by either extending or truncating it.
154 SDValue getFPExtOrFPRound(SelectionDAG &DAG,
155 SDValue Op,
156 const SDLoc &DL,
157 EVT VT) const;
158
159 SDValue convertArgType(
160 SelectionDAG &DAG, EVT VT, EVT MemVT, const SDLoc &SL, SDValue Val,
161 bool Signed, const ISD::InputArg *Arg = nullptr) const;
162
163 /// Custom lowering for ISD::FP_ROUND for MVT::f16.
164 SDValue lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
165 SDValue splitFP_ROUNDVectorOp(SDValue Op, SelectionDAG &DAG) const;
166 SDValue lowerFMINNUM_FMAXNUM(SDValue Op, SelectionDAG &DAG) const;
167 SDValue lowerFMINIMUMNUM_FMAXIMUMNUM(SDValue Op, SelectionDAG &DAG) const;
168 SDValue lowerFMINIMUM_FMAXIMUM(SDValue Op, SelectionDAG &DAG) const;
169 SDValue lowerFLDEXP(SDValue Op, SelectionDAG &DAG) const;
170 SDValue promoteUniformOpToI32(SDValue Op, DAGCombinerInfo &DCI) const;
171 SDValue lowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const;
172 SDValue lowerMUL(SDValue Op, SelectionDAG &DAG) const;
173 SDValue lowerXMULO(SDValue Op, SelectionDAG &DAG) const;
174 SDValue lowerXMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
175
176 SDValue getSegmentAperture(unsigned AS, const SDLoc &DL,
177 SelectionDAG &DAG) const;
178
179 SDValue lowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG) const;
180 SDValue lowerINSERT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
181 SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
182 SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
183 SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
184 SDValue lowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
185 SDValue lowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
186
187 SDValue lowerTRAP(SDValue Op, SelectionDAG &DAG) const;
188 SDValue lowerTrapEndpgm(SDValue Op, SelectionDAG &DAG) const;
189 SDValue lowerTrapHsaQueuePtr(SDValue Op, SelectionDAG &DAG) const;
190 SDValue lowerTrapHsa(SDValue Op, SelectionDAG &DAG) const;
191 SDValue lowerDEBUGTRAP(SDValue Op, SelectionDAG &DAG) const;
192
193 SDNode *adjustWritemask(MachineSDNode *&N, SelectionDAG &DAG) const;
194
195 SDValue performUCharToFloatCombine(SDNode *N,
196 DAGCombinerInfo &DCI) const;
197 SDValue performFCopySignCombine(SDNode *N, DAGCombinerInfo &DCI) const;
198
199 SDValue performSHLPtrCombine(SDNode *N,
200 unsigned AS,
201 EVT MemVT,
202 DAGCombinerInfo &DCI) const;
203
204 SDValue performMemSDNodeCombine(MemSDNode *N, DAGCombinerInfo &DCI) const;
205
206 SDValue splitBinaryBitConstantOp(DAGCombinerInfo &DCI, const SDLoc &SL,
207 unsigned Opc, SDValue LHS,
208 const ConstantSDNode *CRHS) const;
209
210 SDValue performAndCombine(SDNode *N, DAGCombinerInfo &DCI) const;
211 SDValue performOrCombine(SDNode *N, DAGCombinerInfo &DCI) const;
212 SDValue performXorCombine(SDNode *N, DAGCombinerInfo &DCI) const;
213 SDValue performZeroOrAnyExtendCombine(SDNode *N, DAGCombinerInfo &DCI) const;
214 SDValue performSignExtendInRegCombine(SDNode *N, DAGCombinerInfo &DCI) const;
215 SDValue performClassCombine(SDNode *N, DAGCombinerInfo &DCI) const;
216 SDValue getCanonicalConstantFP(SelectionDAG &DAG, const SDLoc &SL, EVT VT,
217 const APFloat &C) const;
218 SDValue performFCanonicalizeCombine(SDNode *N, DAGCombinerInfo &DCI) const;
219
220 SDValue performFPMed3ImmCombine(SelectionDAG &DAG, const SDLoc &SL,
221 SDValue Op0, SDValue Op1) const;
222 SDValue performIntMed3ImmCombine(SelectionDAG &DAG, const SDLoc &SL,
223 SDValue Src, SDValue MinVal, SDValue MaxVal,
224 bool Signed) const;
225 SDValue performMinMaxCombine(SDNode *N, DAGCombinerInfo &DCI) const;
226 SDValue performFMed3Combine(SDNode *N, DAGCombinerInfo &DCI) const;
227 SDValue performCvtPkRTZCombine(SDNode *N, DAGCombinerInfo &DCI) const;
228 SDValue performExtractVectorEltCombine(SDNode *N, DAGCombinerInfo &DCI) const;
229 SDValue performInsertVectorEltCombine(SDNode *N, DAGCombinerInfo &DCI) const;
230 SDValue performFPRoundCombine(SDNode *N, DAGCombinerInfo &DCI) const;
231 SDValue performSelectCombine(SDNode *N, DAGCombinerInfo &DCI) const;
232
233 SDValue reassociateScalarOps(SDNode *N, SelectionDAG &DAG) const;
234 unsigned getFusedOpcode(const SelectionDAG &DAG,
235 const SDNode *N0, const SDNode *N1) const;
236 SDValue tryFoldToMad64_32(SDNode *N, DAGCombinerInfo &DCI) const;
237 SDValue foldAddSub64WithZeroLowBitsTo32(SDNode *N,
238 DAGCombinerInfo &DCI) const;
239
240 SDValue performAddCombine(SDNode *N, DAGCombinerInfo &DCI) const;
241 SDValue performPtrAddCombine(SDNode *N, DAGCombinerInfo &DCI) const;
242 SDValue performAddCarrySubCarryCombine(SDNode *N, DAGCombinerInfo &DCI) const;
243 SDValue performSubCombine(SDNode *N, DAGCombinerInfo &DCI) const;
244 SDValue performFAddCombine(SDNode *N, DAGCombinerInfo &DCI) const;
245 SDValue performFSubCombine(SDNode *N, DAGCombinerInfo &DCI) const;
246 SDValue performFDivCombine(SDNode *N, DAGCombinerInfo &DCI) const;
247 SDValue performFMulCombine(SDNode *N, DAGCombinerInfo &DCI) const;
248 SDValue performFMACombine(SDNode *N, DAGCombinerInfo &DCI) const;
249 SDValue performSetCCCombine(SDNode *N, DAGCombinerInfo &DCI) const;
250 SDValue performCvtF32UByteNCombine(SDNode *N, DAGCombinerInfo &DCI) const;
251 SDValue performClampCombine(SDNode *N, DAGCombinerInfo &DCI) const;
252 SDValue performRcpCombine(SDNode *N, DAGCombinerInfo &DCI) const;
253
254 bool isLegalMUBUFAddressingMode(const AddrMode &AM) const;
255
256 unsigned isCFIntrinsic(const SDNode *Intr) const;
257
258public:
259 /// \returns True if fixup needs to be emitted for given global value \p GV,
260 /// false otherwise.
261 bool shouldEmitFixup(const GlobalValue *GV) const;
262
263 /// \returns True if GOT relocation needs to be emitted for given global value
264 /// \p GV, false otherwise.
265 bool shouldEmitGOTReloc(const GlobalValue *GV) const;
266
267 /// \returns True if PC-relative relocation needs to be emitted for given
268 /// global value \p GV, false otherwise.
269 bool shouldEmitPCReloc(const GlobalValue *GV) const;
270
271 /// \returns true if this should use a literal constant for an LDS address,
272 /// and not emit a relocation for an LDS global.
273 bool shouldUseLDSConstAddress(const GlobalValue *GV) const;
274
275 /// Check if EXTRACT_VECTOR_ELT/INSERT_VECTOR_ELT (<n x e>, var-idx) should be
276 /// expanded into a set of cmp/select instructions.
277 static bool shouldExpandVectorDynExt(unsigned EltSize, unsigned NumElem,
278 bool IsDivergentIdx,
279 const GCNSubtarget *Subtarget);
280
281 bool shouldExpandVectorDynExt(SDNode *N) const;
282
283 bool shouldPreservePtrArith(const Function &F, EVT PtrVT) const override;
284
285 bool canTransformPtrArithOutOfBounds(const Function &F,
286 EVT PtrVT) const override;
287
288private:
289 // Analyze a combined offset from an amdgcn_s_buffer_load intrinsic and store
290 // the three offsets (voffset, soffset and instoffset) into the SDValue[3]
291 // array pointed to by Offsets.
292 void setBufferOffsets(SDValue CombinedOffset, SelectionDAG &DAG,
293 SDValue *Offsets, Align Alignment = Align(4)) const;
294
295 // Convert the i128 that an addrspace(8) pointer is natively represented as
296 // into the v4i32 that all the buffer intrinsics expect to receive. We can't
297 // add register classes for i128 on pain of the promotion logic going haywire,
298 // so this slightly ugly hack is what we've got. If passed a non-pointer
299 // argument (as would be seen in older buffer intrinsics), does nothing.
300 SDValue bufferRsrcPtrToVector(SDValue MaybePointer, SelectionDAG &DAG) const;
301
302 // Wrap a 64-bit pointer into a v4i32 (which is how all SelectionDAG code
303 // represents ptr addrspace(8)) using the flags specified in the intrinsic.
304 SDValue lowerPointerAsRsrcIntrin(SDNode *Op, SelectionDAG &DAG) const;
305
306 // Handle 8 bit and 16 bit buffer loads
307 SDValue handleByteShortBufferLoads(SelectionDAG &DAG, EVT LoadVT, SDLoc DL,
308 ArrayRef<SDValue> Ops,
309 MachineMemOperand *MMO,
310 bool IsTFE = false) const;
311
312 // Handle 8 bit and 16 bit buffer stores
313 SDValue handleByteShortBufferStores(SelectionDAG &DAG, EVT VDataType,
314 SDLoc DL, SDValue Ops[],
315 MemSDNode *M) const;
316
317public:
318 SITargetLowering(const TargetMachine &tm, const GCNSubtarget &STI);
319
320 const GCNSubtarget *getSubtarget() const;
321
322 ArrayRef<MCPhysReg> getRoundingControlRegisters() const override;
323
324 bool isFPExtFoldable(const SelectionDAG &DAG, unsigned Opcode, EVT DestVT,
325 EVT SrcVT) const override;
326
327 bool isFPExtFoldable(const MachineInstr &MI, unsigned Opcode, LLT DestTy,
328 LLT SrcTy) const override;
329
330 bool isShuffleMaskLegal(ArrayRef<int> /*Mask*/, EVT /*VT*/) const override;
331
332 // While address space 7 should never make it to codegen, it still needs to
333 // have a MVT to prevent some analyses that query this function from breaking.
334 // We use the custum MVT::amdgpuBufferFatPointer and
335 // amdgpu::amdgpuBufferStridedPointer for this, though we use v8i32 for the
336 // memory type (which is probably unused).
337 MVT getPointerTy(const DataLayout &DL, unsigned AS) const override;
338 MVT getPointerMemTy(const DataLayout &DL, unsigned AS) const override;
339
340 void getTgtMemIntrinsic(SmallVectorImpl<IntrinsicInfo> &, const CallBase &,
341 MachineFunction &MF,
342 unsigned IntrinsicID) const override;
343
344 void CollectTargetIntrinsicOperands(const CallInst &I,
345 SmallVectorImpl<SDValue> &Ops,
346 SelectionDAG &DAG) const override;
347
348 bool getAddrModeArguments(const IntrinsicInst *I,
349 SmallVectorImpl<Value *> &Ops,
350 Type *&AccessTy) const override;
351
352 bool isLegalFlatAddressingMode(const AddrMode &AM, unsigned AddrSpace) const;
353 bool isLegalGlobalAddressingMode(const AddrMode &AM) const;
354 bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
355 unsigned AS,
356 Instruction *I = nullptr) const override;
357
358 bool canMergeStoresTo(unsigned AS, EVT MemVT,
359 const MachineFunction &MF) const override;
360
361 bool allowsMisalignedMemoryAccessesImpl(
362 unsigned Size, unsigned AddrSpace, Align Alignment,
363 MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
364 unsigned *IsFast = nullptr) const;
365
366 bool allowsMisalignedMemoryAccesses(
367 LLT Ty, unsigned AddrSpace, Align Alignment,
368 MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
369 unsigned *IsFast = nullptr) const override {
370 if (IsFast)
371 *IsFast = 0;
372 return allowsMisalignedMemoryAccessesImpl(Size: Ty.getSizeInBits(), AddrSpace,
373 Alignment, Flags, IsFast);
374 }
375
376 bool allowsMisalignedMemoryAccesses(
377 EVT VT, unsigned AS, Align Alignment,
378 MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
379 unsigned *IsFast = nullptr) const override;
380
381 EVT getOptimalMemOpType(LLVMContext &Context, const MemOp &Op,
382 const AttributeList &FuncAttributes) const override;
383
384 bool isMemOpHasNoClobberedMemOperand(const SDNode *N) const;
385
386 static bool isNonGlobalAddrSpace(unsigned AS);
387
388 bool isFreeAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override;
389
390 TargetLoweringBase::LegalizeTypeAction
391 getPreferredVectorAction(MVT VT) const override;
392
393 bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
394 Type *Ty) const override;
395
396 bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
397 unsigned Index) const override;
398 bool isExtractVecEltCheap(EVT VT, unsigned Index) const override;
399
400 bool isTypeDesirableForOp(unsigned Op, EVT VT) const override;
401
402 bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
403
404 unsigned combineRepeatedFPDivisors() const override {
405 // Combine multiple FDIVs with the same divisor into multiple FMULs by the
406 // reciprocal.
407 return 2;
408 }
409
410 bool supportSplitCSR(MachineFunction *MF) const override;
411 void initializeSplitCSR(MachineBasicBlock *Entry) const override;
412 void insertCopiesSplitCSR(
413 MachineBasicBlock *Entry,
414 const SmallVectorImpl<MachineBasicBlock *> &Exits) const override;
415
416 SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
417 bool isVarArg,
418 const SmallVectorImpl<ISD::InputArg> &Ins,
419 const SDLoc &DL, SelectionDAG &DAG,
420 SmallVectorImpl<SDValue> &InVals) const override;
421
422 bool CanLowerReturn(CallingConv::ID CallConv,
423 MachineFunction &MF, bool isVarArg,
424 const SmallVectorImpl<ISD::OutputArg> &Outs,
425 LLVMContext &Context, const Type *RetTy) const override;
426
427 SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
428 const SmallVectorImpl<ISD::OutputArg> &Outs,
429 const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
430 SelectionDAG &DAG) const override;
431
432 void passSpecialInputs(
433 CallLoweringInfo &CLI,
434 CCState &CCInfo,
435 const SIMachineFunctionInfo &Info,
436 SmallVectorImpl<std::pair<unsigned, SDValue>> &RegsToPass,
437 SmallVectorImpl<SDValue> &MemOpChains,
438 SDValue Chain) const;
439
440 SDValue LowerCallResult(SDValue Chain, SDValue InGlue,
441 CallingConv::ID CallConv, bool isVarArg,
442 const SmallVectorImpl<ISD::InputArg> &Ins,
443 const SDLoc &DL, SelectionDAG &DAG,
444 SmallVectorImpl<SDValue> &InVals, bool isThisReturn,
445 SDValue ThisVal) const;
446
447 bool mayBeEmittedAsTailCall(const CallInst *) const override;
448
449 bool isEligibleForTailCallOptimization(
450 SDValue Callee, CallingConv::ID CalleeCC, bool isVarArg,
451 const SmallVectorImpl<ISD::OutputArg> &Outs,
452 const SmallVectorImpl<SDValue> &OutVals,
453 const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const;
454
455 SDValue LowerCall(CallLoweringInfo &CLI,
456 SmallVectorImpl<SDValue> &InVals) const override;
457
458 SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
459 SDValue LowerSTACKSAVE(SDValue Op, SelectionDAG &DAG) const;
460 SDValue lowerGET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
461 SDValue lowerSET_ROUNDING(SDValue Op, SelectionDAG &DAG) const;
462
463 SDValue lowerPREFETCH(SDValue Op, SelectionDAG &DAG) const;
464 SDValue lowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const;
465 SDValue lowerGET_FPENV(SDValue Op, SelectionDAG &DAG) const;
466 SDValue lowerSET_FPENV(SDValue Op, SelectionDAG &DAG) const;
467 SDValue lowerROTR(SDValue Op, SelectionDAG &DAG) const;
468
469 Register getRegisterByName(const char* RegName, LLT VT,
470 const MachineFunction &MF) const override;
471
472 MachineBasicBlock *splitKillBlock(MachineInstr &MI,
473 MachineBasicBlock *BB) const;
474
475 void bundleInstWithWaitcnt(MachineInstr &MI) const;
476 MachineBasicBlock *emitGWSMemViolTestLoop(MachineInstr &MI,
477 MachineBasicBlock *BB) const;
478
479 MachineBasicBlock *
480 EmitInstrWithCustomInserter(MachineInstr &MI,
481 MachineBasicBlock *BB) const override;
482
483 bool enableAggressiveFMAFusion(EVT VT) const override;
484 bool enableAggressiveFMAFusion(LLT Ty) const override;
485 EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
486 EVT VT) const override;
487 MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override;
488 LLT getPreferredShiftAmountTy(LLT Ty) const override;
489
490 bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
491 EVT VT) const override;
492 bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
493 const LLT Ty) const override;
494 bool isFMADLegal(const SelectionDAG &DAG, const SDNode *N) const override;
495 bool isFMADLegal(const MachineInstr &MI, const LLT Ty) const override;
496
497 SDValue splitUnaryVectorOp(SDValue Op, SelectionDAG &DAG) const;
498 SDValue splitBinaryVectorOp(SDValue Op, SelectionDAG &DAG) const;
499 SDValue splitTernaryVectorOp(SDValue Op, SelectionDAG &DAG) const;
500 SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
501 void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
502 SelectionDAG &DAG) const override;
503
504 SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
505 SDNode *PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const override;
506 void AddMemOpInit(MachineInstr &MI) const;
507 void AdjustInstrPostInstrSelection(MachineInstr &MI,
508 SDNode *Node) const override;
509
510 SDNode *legalizeTargetIndependentNode(SDNode *Node, SelectionDAG &DAG) const;
511
512 MachineSDNode *wrapAddr64Rsrc(SelectionDAG &DAG, const SDLoc &DL,
513 SDValue Ptr) const;
514 MachineSDNode *buildRSRC(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr,
515 uint32_t RsrcDword1, uint64_t RsrcDword2And3) const;
516 std::pair<unsigned, const TargetRegisterClass *>
517 getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
518 StringRef Constraint, MVT VT) const override;
519 ConstraintType getConstraintType(StringRef Constraint) const override;
520 void LowerAsmOperandForConstraint(SDValue Op, StringRef Constraint,
521 std::vector<SDValue> &Ops,
522 SelectionDAG &DAG) const override;
523 bool getAsmOperandConstVal(SDValue Op, uint64_t &Val) const;
524 bool checkAsmConstraintVal(SDValue Op, StringRef Constraint,
525 uint64_t Val) const;
526 bool checkAsmConstraintValA(SDValue Op,
527 uint64_t Val,
528 unsigned MaxSize = 64) const;
529 SDValue copyToM0(SelectionDAG &DAG, SDValue Chain, const SDLoc &DL,
530 SDValue V) const;
531
532 void finalizeLowering(MachineFunction &MF) const override;
533
534 void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known,
535 const APInt &DemandedElts,
536 const SelectionDAG &DAG,
537 unsigned Depth = 0) const override;
538 void computeKnownBitsForFrameIndex(int FrameIdx,
539 KnownBits &Known,
540 const MachineFunction &MF) const override;
541 void computeKnownBitsForTargetInstr(GISelValueTracking &Analysis, Register R,
542 KnownBits &Known,
543 const APInt &DemandedElts,
544 const MachineRegisterInfo &MRI,
545 unsigned Depth = 0) const override;
546
547 Align computeKnownAlignForTargetInstr(GISelValueTracking &Analysis,
548 Register R,
549 const MachineRegisterInfo &MRI,
550 unsigned Depth = 0) const override;
551 bool isSDNodeSourceOfDivergence(const SDNode *N, FunctionLoweringInfo *FLI,
552 UniformityInfo *UA) const override;
553
554 bool hasMemSDNodeUser(SDNode *N) const;
555
556 bool isReassocProfitable(SelectionDAG &DAG, SDValue N0,
557 SDValue N1) const override;
558
559 bool isReassocProfitable(MachineRegisterInfo &MRI, Register N0,
560 Register N1) const override;
561
562 bool isCanonicalized(SelectionDAG &DAG, SDValue Op,
563 unsigned MaxDepth = 5) const;
564 bool isCanonicalized(Register Reg, const MachineFunction &MF,
565 unsigned MaxDepth = 5) const;
566 bool denormalsEnabledForType(const SelectionDAG &DAG, EVT VT) const;
567 bool denormalsEnabledForType(LLT Ty, const MachineFunction &MF) const;
568
569 bool isKnownNeverNaNForTargetNode(SDValue Op, const APInt &DemandedElts,
570 const SelectionDAG &DAG, bool SNaN = false,
571 unsigned Depth = 0) const override;
572 AtomicExpansionKind
573 shouldExpandAtomicRMWInIR(const AtomicRMWInst *) const override;
574 AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
575 AtomicExpansionKind shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
576 AtomicExpansionKind
577 shouldExpandAtomicCmpXchgInIR(const AtomicCmpXchgInst *AI) const override;
578
579 void emitExpandAtomicAddrSpacePredicate(Instruction *AI) const;
580 void emitExpandAtomicRMW(AtomicRMWInst *AI) const override;
581 void emitExpandAtomicCmpXchg(AtomicCmpXchgInst *CI) const override;
582 void emitExpandAtomicLoad(LoadInst *LI) const override;
583 void emitExpandAtomicStore(StoreInst *SI) const override;
584
585 LoadInst *
586 lowerIdempotentRMWIntoFencedLoad(AtomicRMWInst *AI) const override;
587
588 const TargetRegisterClass *getRegClassFor(MVT VT,
589 bool isDivergent) const override;
590 bool requiresUniformRegister(MachineFunction &MF,
591 const Value *V) const override;
592 Align getPrefLoopAlignment(MachineLoop *ML) const override;
593
594 void allocateHSAUserSGPRs(CCState &CCInfo,
595 MachineFunction &MF,
596 const SIRegisterInfo &TRI,
597 SIMachineFunctionInfo &Info) const;
598
599 void allocatePreloadKernArgSGPRs(CCState &CCInfo,
600 SmallVectorImpl<CCValAssign> &ArgLocs,
601 const SmallVectorImpl<ISD::InputArg> &Ins,
602 MachineFunction &MF,
603 const SIRegisterInfo &TRI,
604 SIMachineFunctionInfo &Info) const;
605
606 void allocateLDSKernelId(CCState &CCInfo, MachineFunction &MF,
607 const SIRegisterInfo &TRI,
608 SIMachineFunctionInfo &Info) const;
609
610 void allocateSystemSGPRs(CCState &CCInfo,
611 MachineFunction &MF,
612 SIMachineFunctionInfo &Info,
613 CallingConv::ID CallConv,
614 bool IsShader) const;
615
616 void allocateSpecialEntryInputVGPRs(CCState &CCInfo,
617 MachineFunction &MF,
618 const SIRegisterInfo &TRI,
619 SIMachineFunctionInfo &Info) const;
620 void allocateSpecialInputSGPRs(
621 CCState &CCInfo,
622 MachineFunction &MF,
623 const SIRegisterInfo &TRI,
624 SIMachineFunctionInfo &Info) const;
625
626 void allocateSpecialInputVGPRs(CCState &CCInfo,
627 MachineFunction &MF,
628 const SIRegisterInfo &TRI,
629 SIMachineFunctionInfo &Info) const;
630 void allocateSpecialInputVGPRsFixed(CCState &CCInfo,
631 MachineFunction &MF,
632 const SIRegisterInfo &TRI,
633 SIMachineFunctionInfo &Info) const;
634
635 MachineMemOperand::Flags
636 getTargetMMOFlags(const Instruction &I) const override;
637};
638
639// Returns true if argument is a boolean value which is not serialized into
640// memory or argument and does not require v_cndmask_b32 to be deserialized.
641bool isBoolSGPR(SDValue V);
642
643} // End namespace llvm
644
645#endif
646