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