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