xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AMDGPU/SIISelLowering.h (revision 81ad626541db97eb356e2c1d4a20eb2a26a766ab)
10b57cec5SDimitry Andric //===-- SIISelLowering.h - SI DAG Lowering Interface ------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric /// \file
100b57cec5SDimitry Andric /// SI DAG Lowering interface definition
110b57cec5SDimitry Andric //
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_AMDGPU_SIISELLOWERING_H
150b57cec5SDimitry Andric #define LLVM_LIB_TARGET_AMDGPU_SIISELLOWERING_H
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric #include "AMDGPUISelLowering.h"
180b57cec5SDimitry Andric #include "AMDGPUArgumentUsageInfo.h"
19349cc55cSDimitry Andric #include "llvm/CodeGen/MachineFunction.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace llvm {
220b57cec5SDimitry Andric 
23e8d8bef9SDimitry Andric class GCNSubtarget;
24e8d8bef9SDimitry Andric class SIMachineFunctionInfo;
25e8d8bef9SDimitry Andric class SIRegisterInfo;
26e8d8bef9SDimitry Andric 
27e8d8bef9SDimitry Andric namespace AMDGPU {
28e8d8bef9SDimitry Andric struct ImageDimIntrinsicInfo;
29e8d8bef9SDimitry Andric }
30e8d8bef9SDimitry Andric 
310b57cec5SDimitry Andric class SITargetLowering final : public AMDGPUTargetLowering {
320b57cec5SDimitry Andric private:
330b57cec5SDimitry Andric   const GCNSubtarget *Subtarget;
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric public:
360b57cec5SDimitry Andric   MVT getRegisterTypeForCallingConv(LLVMContext &Context,
370b57cec5SDimitry Andric                                     CallingConv::ID CC,
380b57cec5SDimitry Andric                                     EVT VT) const override;
390b57cec5SDimitry Andric   unsigned getNumRegistersForCallingConv(LLVMContext &Context,
400b57cec5SDimitry Andric                                          CallingConv::ID CC,
410b57cec5SDimitry Andric                                          EVT VT) const override;
420b57cec5SDimitry Andric 
430b57cec5SDimitry Andric   unsigned getVectorTypeBreakdownForCallingConv(
440b57cec5SDimitry Andric     LLVMContext &Context, CallingConv::ID CC, EVT VT, EVT &IntermediateVT,
450b57cec5SDimitry Andric     unsigned &NumIntermediates, MVT &RegisterVT) const override;
460b57cec5SDimitry Andric 
470b57cec5SDimitry Andric private:
480b57cec5SDimitry Andric   SDValue lowerKernArgParameterPtr(SelectionDAG &DAG, const SDLoc &SL,
490b57cec5SDimitry Andric                                    SDValue Chain, uint64_t Offset) const;
500b57cec5SDimitry Andric   SDValue getImplicitArgPtr(SelectionDAG &DAG, const SDLoc &SL) const;
510b57cec5SDimitry Andric   SDValue lowerKernargMemParameter(SelectionDAG &DAG, EVT VT, EVT MemVT,
520b57cec5SDimitry Andric                                    const SDLoc &SL, SDValue Chain,
535ffd83dbSDimitry Andric                                    uint64_t Offset, Align Alignment,
545ffd83dbSDimitry Andric                                    bool Signed,
550b57cec5SDimitry Andric                                    const ISD::InputArg *Arg = nullptr) const;
56*81ad6265SDimitry Andric   SDValue loadImplicitKernelArgument(SelectionDAG &DAG, MVT VT, const SDLoc &DL,
57*81ad6265SDimitry Andric                                      Align Alignment,
58*81ad6265SDimitry Andric                                      ImplicitParameter Param) const;
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric   SDValue lowerStackParameter(SelectionDAG &DAG, CCValAssign &VA,
610b57cec5SDimitry Andric                               const SDLoc &SL, SDValue Chain,
620b57cec5SDimitry Andric                               const ISD::InputArg &Arg) const;
630b57cec5SDimitry Andric   SDValue getPreloadedValue(SelectionDAG &DAG,
640b57cec5SDimitry Andric                             const SIMachineFunctionInfo &MFI,
650b57cec5SDimitry Andric                             EVT VT,
660b57cec5SDimitry Andric                             AMDGPUFunctionArgInfo::PreloadedValue) const;
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
690b57cec5SDimitry Andric                              SelectionDAG &DAG) const override;
700b57cec5SDimitry Andric   SDValue lowerImplicitZextParam(SelectionDAG &DAG, SDValue Op,
710b57cec5SDimitry Andric                                  MVT VT, unsigned Offset) const;
720b57cec5SDimitry Andric   SDValue lowerImage(SDValue Op, const AMDGPU::ImageDimIntrinsicInfo *Intr,
73e8d8bef9SDimitry Andric                      SelectionDAG &DAG, bool WithChain) const;
740b57cec5SDimitry Andric   SDValue lowerSBuffer(EVT VT, SDLoc DL, SDValue Rsrc, SDValue Offset,
755ffd83dbSDimitry Andric                        SDValue CachePolicy, SelectionDAG &DAG) const;
760b57cec5SDimitry Andric 
77e8d8bef9SDimitry Andric   SDValue lowerRawBufferAtomicIntrin(SDValue Op, SelectionDAG &DAG,
78e8d8bef9SDimitry Andric                                      unsigned NewOpcode) const;
79e8d8bef9SDimitry Andric   SDValue lowerStructBufferAtomicIntrin(SDValue Op, SelectionDAG &DAG,
80e8d8bef9SDimitry Andric                                         unsigned NewOpcode) const;
81e8d8bef9SDimitry Andric 
82*81ad6265SDimitry Andric   SDValue lowerWorkitemID(SelectionDAG &DAG, SDValue Op, unsigned Dim,
83*81ad6265SDimitry Andric                           const ArgDescriptor &ArgDesc) const;
84*81ad6265SDimitry Andric 
850b57cec5SDimitry Andric   SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
860b57cec5SDimitry Andric   SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
870b57cec5SDimitry Andric   SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric   // The raw.tbuffer and struct.tbuffer intrinsics have two offset args: offset
900b57cec5SDimitry Andric   // (the offset that is included in bounds checking and swizzling, to be split
910b57cec5SDimitry Andric   // between the instruction's voffset and immoffset fields) and soffset (the
920b57cec5SDimitry Andric   // offset that is excluded from bounds checking and swizzling, to go in the
930b57cec5SDimitry Andric   // instruction's soffset field).  This function takes the first kind of
940b57cec5SDimitry Andric   // offset and figures out how to split it between voffset and immoffset.
950b57cec5SDimitry Andric   std::pair<SDValue, SDValue> splitBufferOffsets(SDValue Offset,
960b57cec5SDimitry Andric                                                  SelectionDAG &DAG) const;
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   SDValue widenLoad(LoadSDNode *Ld, DAGCombinerInfo &DCI) const;
990b57cec5SDimitry Andric   SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
1000b57cec5SDimitry Andric   SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
1010b57cec5SDimitry Andric   SDValue lowerFastUnsafeFDIV(SDValue Op, SelectionDAG &DAG) const;
102e8d8bef9SDimitry Andric   SDValue lowerFastUnsafeFDIV64(SDValue Op, SelectionDAG &DAG) const;
1030b57cec5SDimitry Andric   SDValue lowerFDIV_FAST(SDValue Op, SelectionDAG &DAG) const;
1040b57cec5SDimitry Andric   SDValue LowerFDIV16(SDValue Op, SelectionDAG &DAG) const;
1050b57cec5SDimitry Andric   SDValue LowerFDIV32(SDValue Op, SelectionDAG &DAG) const;
1060b57cec5SDimitry Andric   SDValue LowerFDIV64(SDValue Op, SelectionDAG &DAG) const;
1070b57cec5SDimitry Andric   SDValue LowerFDIV(SDValue Op, SelectionDAG &DAG) const;
1080b57cec5SDimitry Andric   SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
1090b57cec5SDimitry Andric   SDValue LowerTrig(SDValue Op, SelectionDAG &DAG) const;
1100b57cec5SDimitry Andric   SDValue LowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
1110b57cec5SDimitry Andric   SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
1120b57cec5SDimitry Andric   SDValue LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const;
1130b57cec5SDimitry Andric   SDValue adjustLoadValueType(unsigned Opcode, MemSDNode *M,
1140b57cec5SDimitry Andric                               SelectionDAG &DAG, ArrayRef<SDValue> Ops,
1150b57cec5SDimitry Andric                               bool IsIntrinsic = false) const;
1160b57cec5SDimitry Andric 
1178bcb0991SDimitry Andric   SDValue lowerIntrinsicLoad(MemSDNode *M, bool IsFormat, SelectionDAG &DAG,
1188bcb0991SDimitry Andric                              ArrayRef<SDValue> Ops) const;
1198bcb0991SDimitry Andric 
1200b57cec5SDimitry Andric   // Call DAG.getMemIntrinsicNode for a load, but first widen a dwordx3 type to
1210b57cec5SDimitry Andric   // dwordx4 if on SI.
1220b57cec5SDimitry Andric   SDValue getMemIntrinsicNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
1230b57cec5SDimitry Andric                               ArrayRef<SDValue> Ops, EVT MemVT,
1240b57cec5SDimitry Andric                               MachineMemOperand *MMO, SelectionDAG &DAG) const;
1250b57cec5SDimitry Andric 
126e8d8bef9SDimitry Andric   SDValue handleD16VData(SDValue VData, SelectionDAG &DAG,
127e8d8bef9SDimitry Andric                          bool ImageStore = false) const;
1280b57cec5SDimitry Andric 
1290b57cec5SDimitry Andric   /// Converts \p Op, which must be of floating point type, to the
1300b57cec5SDimitry Andric   /// floating point type \p VT, by either extending or truncating it.
1315ffd83dbSDimitry Andric   SDValue getFPExtOrFPRound(SelectionDAG &DAG,
1320b57cec5SDimitry Andric                             SDValue Op,
1330b57cec5SDimitry Andric                             const SDLoc &DL,
1340b57cec5SDimitry Andric                             EVT VT) const;
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   SDValue convertArgType(
1370b57cec5SDimitry Andric     SelectionDAG &DAG, EVT VT, EVT MemVT, const SDLoc &SL, SDValue Val,
1380b57cec5SDimitry Andric     bool Signed, const ISD::InputArg *Arg = nullptr) const;
1390b57cec5SDimitry Andric 
1400b57cec5SDimitry Andric   /// Custom lowering for ISD::FP_ROUND for MVT::f16.
1410b57cec5SDimitry Andric   SDValue lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
1420b57cec5SDimitry Andric   SDValue lowerFMINNUM_FMAXNUM(SDValue Op, SelectionDAG &DAG) const;
1435ffd83dbSDimitry Andric   SDValue lowerXMULO(SDValue Op, SelectionDAG &DAG) const;
1444824e7fdSDimitry Andric   SDValue lowerXMUL_LOHI(SDValue Op, SelectionDAG &DAG) const;
1450b57cec5SDimitry Andric 
1460b57cec5SDimitry Andric   SDValue getSegmentAperture(unsigned AS, const SDLoc &DL,
1470b57cec5SDimitry Andric                              SelectionDAG &DAG) const;
1480b57cec5SDimitry Andric 
1490b57cec5SDimitry Andric   SDValue lowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG) const;
1500b57cec5SDimitry Andric   SDValue lowerINSERT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const;
1510b57cec5SDimitry Andric   SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
1520b57cec5SDimitry Andric   SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
1530b57cec5SDimitry Andric   SDValue lowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) const;
154*81ad6265SDimitry Andric   SDValue lowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) const;
1550b57cec5SDimitry Andric   SDValue lowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) const;
156fe6060f1SDimitry Andric 
1570b57cec5SDimitry Andric   SDValue lowerTRAP(SDValue Op, SelectionDAG &DAG) const;
158fe6060f1SDimitry Andric   SDValue lowerTrapEndpgm(SDValue Op, SelectionDAG &DAG) const;
159fe6060f1SDimitry Andric   SDValue lowerTrapHsaQueuePtr(SDValue Op, SelectionDAG &DAG) const;
160fe6060f1SDimitry Andric   SDValue lowerTrapHsa(SDValue Op, SelectionDAG &DAG) const;
1610b57cec5SDimitry Andric   SDValue lowerDEBUGTRAP(SDValue Op, SelectionDAG &DAG) const;
1620b57cec5SDimitry Andric 
1630b57cec5SDimitry Andric   SDNode *adjustWritemask(MachineSDNode *&N, SelectionDAG &DAG) const;
1640b57cec5SDimitry Andric 
1650b57cec5SDimitry Andric   SDValue performUCharToFloatCombine(SDNode *N,
1660b57cec5SDimitry Andric                                      DAGCombinerInfo &DCI) const;
1670b57cec5SDimitry Andric   SDValue performSHLPtrCombine(SDNode *N,
1680b57cec5SDimitry Andric                                unsigned AS,
1690b57cec5SDimitry Andric                                EVT MemVT,
1700b57cec5SDimitry Andric                                DAGCombinerInfo &DCI) const;
1710b57cec5SDimitry Andric 
1720b57cec5SDimitry Andric   SDValue performMemSDNodeCombine(MemSDNode *N, DAGCombinerInfo &DCI) const;
1730b57cec5SDimitry Andric 
1740b57cec5SDimitry Andric   SDValue splitBinaryBitConstantOp(DAGCombinerInfo &DCI, const SDLoc &SL,
1750b57cec5SDimitry Andric                                    unsigned Opc, SDValue LHS,
1760b57cec5SDimitry Andric                                    const ConstantSDNode *CRHS) const;
1770b57cec5SDimitry Andric 
1780b57cec5SDimitry Andric   SDValue performAndCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1790b57cec5SDimitry Andric   SDValue performOrCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1800b57cec5SDimitry Andric   SDValue performXorCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1810b57cec5SDimitry Andric   SDValue performZeroExtendCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1820b57cec5SDimitry Andric   SDValue performSignExtendInRegCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1830b57cec5SDimitry Andric   SDValue performClassCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1840b57cec5SDimitry Andric   SDValue getCanonicalConstantFP(SelectionDAG &DAG, const SDLoc &SL, EVT VT,
1850b57cec5SDimitry Andric                                  const APFloat &C) const;
1860b57cec5SDimitry Andric   SDValue performFCanonicalizeCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1870b57cec5SDimitry Andric 
1880b57cec5SDimitry Andric   SDValue performFPMed3ImmCombine(SelectionDAG &DAG, const SDLoc &SL,
1890b57cec5SDimitry Andric                                   SDValue Op0, SDValue Op1) const;
1900b57cec5SDimitry Andric   SDValue performIntMed3ImmCombine(SelectionDAG &DAG, const SDLoc &SL,
1910b57cec5SDimitry Andric                                    SDValue Op0, SDValue Op1, bool Signed) const;
1920b57cec5SDimitry Andric   SDValue performMinMaxCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1930b57cec5SDimitry Andric   SDValue performFMed3Combine(SDNode *N, DAGCombinerInfo &DCI) const;
1940b57cec5SDimitry Andric   SDValue performCvtPkRTZCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1950b57cec5SDimitry Andric   SDValue performExtractVectorEltCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1960b57cec5SDimitry Andric   SDValue performInsertVectorEltCombine(SDNode *N, DAGCombinerInfo &DCI) const;
1970b57cec5SDimitry Andric 
1980b57cec5SDimitry Andric   SDValue reassociateScalarOps(SDNode *N, SelectionDAG &DAG) const;
1990b57cec5SDimitry Andric   unsigned getFusedOpcode(const SelectionDAG &DAG,
2000b57cec5SDimitry Andric                           const SDNode *N0, const SDNode *N1) const;
201*81ad6265SDimitry Andric   SDValue tryFoldToMad64_32(SDNode *N, DAGCombinerInfo &DCI) const;
2020b57cec5SDimitry Andric   SDValue performAddCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2030b57cec5SDimitry Andric   SDValue performAddCarrySubCarryCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2040b57cec5SDimitry Andric   SDValue performSubCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2050b57cec5SDimitry Andric   SDValue performFAddCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2060b57cec5SDimitry Andric   SDValue performFSubCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2070b57cec5SDimitry Andric   SDValue performFMACombine(SDNode *N, DAGCombinerInfo &DCI) const;
2080b57cec5SDimitry Andric   SDValue performSetCCCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2090b57cec5SDimitry Andric   SDValue performCvtF32UByteNCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2100b57cec5SDimitry Andric   SDValue performClampCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2110b57cec5SDimitry Andric   SDValue performRcpCombine(SDNode *N, DAGCombinerInfo &DCI) const;
2120b57cec5SDimitry Andric 
2130b57cec5SDimitry Andric   bool isLegalFlatAddressingMode(const AddrMode &AM) const;
2140b57cec5SDimitry Andric   bool isLegalMUBUFAddressingMode(const AddrMode &AM) const;
2150b57cec5SDimitry Andric 
2160b57cec5SDimitry Andric   unsigned isCFIntrinsic(const SDNode *Intr) const;
2170b57cec5SDimitry Andric 
2188bcb0991SDimitry Andric public:
2190b57cec5SDimitry Andric   /// \returns True if fixup needs to be emitted for given global value \p GV,
2200b57cec5SDimitry Andric   /// false otherwise.
2210b57cec5SDimitry Andric   bool shouldEmitFixup(const GlobalValue *GV) const;
2220b57cec5SDimitry Andric 
2230b57cec5SDimitry Andric   /// \returns True if GOT relocation needs to be emitted for given global value
2240b57cec5SDimitry Andric   /// \p GV, false otherwise.
2250b57cec5SDimitry Andric   bool shouldEmitGOTReloc(const GlobalValue *GV) const;
2260b57cec5SDimitry Andric 
2270b57cec5SDimitry Andric   /// \returns True if PC-relative relocation needs to be emitted for given
2280b57cec5SDimitry Andric   /// global value \p GV, false otherwise.
2290b57cec5SDimitry Andric   bool shouldEmitPCReloc(const GlobalValue *GV) const;
2300b57cec5SDimitry Andric 
2315ffd83dbSDimitry Andric   /// \returns true if this should use a literal constant for an LDS address,
2325ffd83dbSDimitry Andric   /// and not emit a relocation for an LDS global.
2335ffd83dbSDimitry Andric   bool shouldUseLDSConstAddress(const GlobalValue *GV) const;
2345ffd83dbSDimitry Andric 
2355ffd83dbSDimitry Andric   /// Check if EXTRACT_VECTOR_ELT/INSERT_VECTOR_ELT (<n x e>, var-idx) should be
2365ffd83dbSDimitry Andric   /// expanded into a set of cmp/select instructions.
2375ffd83dbSDimitry Andric   static bool shouldExpandVectorDynExt(unsigned EltSize, unsigned NumElem,
238*81ad6265SDimitry Andric                                        bool IsDivergentIdx,
239*81ad6265SDimitry Andric                                        const GCNSubtarget *Subtarget);
240*81ad6265SDimitry Andric 
241*81ad6265SDimitry Andric   bool shouldExpandVectorDynExt(SDNode *N) const;
2425ffd83dbSDimitry Andric 
2438bcb0991SDimitry Andric private:
2440b57cec5SDimitry Andric   // Analyze a combined offset from an amdgcn_buffer_ intrinsic and store the
2450b57cec5SDimitry Andric   // three offsets (voffset, soffset and instoffset) into the SDValue[3] array
2460b57cec5SDimitry Andric   // pointed to by Offsets.
247fe6060f1SDimitry Andric   void setBufferOffsets(SDValue CombinedOffset, SelectionDAG &DAG,
2485ffd83dbSDimitry Andric                         SDValue *Offsets, Align Alignment = Align(4)) const;
2490b57cec5SDimitry Andric 
2500b57cec5SDimitry Andric   // Handle 8 bit and 16 bit buffer loads
2510b57cec5SDimitry Andric   SDValue handleByteShortBufferLoads(SelectionDAG &DAG, EVT LoadVT, SDLoc DL,
2520b57cec5SDimitry Andric                                      ArrayRef<SDValue> Ops, MemSDNode *M) const;
2530b57cec5SDimitry Andric 
2540b57cec5SDimitry Andric   // Handle 8 bit and 16 bit buffer stores
2550b57cec5SDimitry Andric   SDValue handleByteShortBufferStores(SelectionDAG &DAG, EVT VDataType,
2560b57cec5SDimitry Andric                                       SDLoc DL, SDValue Ops[],
2570b57cec5SDimitry Andric                                       MemSDNode *M) const;
2580b57cec5SDimitry Andric 
2590b57cec5SDimitry Andric public:
2600b57cec5SDimitry Andric   SITargetLowering(const TargetMachine &tm, const GCNSubtarget &STI);
2610b57cec5SDimitry Andric 
2620b57cec5SDimitry Andric   const GCNSubtarget *getSubtarget() const;
2630b57cec5SDimitry Andric 
264480093f4SDimitry Andric   bool isFPExtFoldable(const SelectionDAG &DAG, unsigned Opcode, EVT DestVT,
265480093f4SDimitry Andric                        EVT SrcVT) const override;
2660b57cec5SDimitry Andric 
2674824e7fdSDimitry Andric   bool isFPExtFoldable(const MachineInstr &MI, unsigned Opcode, LLT DestTy,
2684824e7fdSDimitry Andric                        LLT SrcTy) const override;
2694824e7fdSDimitry Andric 
2700b57cec5SDimitry Andric   bool isShuffleMaskLegal(ArrayRef<int> /*Mask*/, EVT /*VT*/) const override;
2710b57cec5SDimitry Andric 
2720b57cec5SDimitry Andric   bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &,
2730b57cec5SDimitry Andric                           MachineFunction &MF,
2740b57cec5SDimitry Andric                           unsigned IntrinsicID) const override;
2750b57cec5SDimitry Andric 
2760b57cec5SDimitry Andric   bool getAddrModeArguments(IntrinsicInst * /*I*/,
2770b57cec5SDimitry Andric                             SmallVectorImpl<Value*> &/*Ops*/,
2780b57cec5SDimitry Andric                             Type *&/*AccessTy*/) const override;
2790b57cec5SDimitry Andric 
2800b57cec5SDimitry Andric   bool isLegalGlobalAddressingMode(const AddrMode &AM) const;
2810b57cec5SDimitry Andric   bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
2820b57cec5SDimitry Andric                              unsigned AS,
2830b57cec5SDimitry Andric                              Instruction *I = nullptr) const override;
2840b57cec5SDimitry Andric 
2850b57cec5SDimitry Andric   bool canMergeStoresTo(unsigned AS, EVT MemVT,
286349cc55cSDimitry Andric                         const MachineFunction &MF) const override;
2870b57cec5SDimitry Andric 
2888bcb0991SDimitry Andric   bool allowsMisalignedMemoryAccessesImpl(
289e8d8bef9SDimitry Andric       unsigned Size, unsigned AddrSpace, Align Alignment,
2908bcb0991SDimitry Andric       MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
2918bcb0991SDimitry Andric       bool *IsFast = nullptr) const;
2928bcb0991SDimitry Andric 
2930b57cec5SDimitry Andric   bool allowsMisalignedMemoryAccesses(
294e8d8bef9SDimitry Andric       LLT Ty, unsigned AddrSpace, Align Alignment,
295e8d8bef9SDimitry Andric       MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
296e8d8bef9SDimitry Andric       bool *IsFast = nullptr) const override {
297e8d8bef9SDimitry Andric     if (IsFast)
298e8d8bef9SDimitry Andric       *IsFast = false;
299e8d8bef9SDimitry Andric     return allowsMisalignedMemoryAccessesImpl(Ty.getSizeInBits(), AddrSpace,
300e8d8bef9SDimitry Andric                                               Alignment, Flags, IsFast);
301e8d8bef9SDimitry Andric   }
302e8d8bef9SDimitry Andric 
303e8d8bef9SDimitry Andric   bool allowsMisalignedMemoryAccesses(
304fe6060f1SDimitry Andric       EVT VT, unsigned AS, Align Alignment,
3050b57cec5SDimitry Andric       MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
3060b57cec5SDimitry Andric       bool *IsFast = nullptr) const override;
3070b57cec5SDimitry Andric 
3085ffd83dbSDimitry Andric   EVT getOptimalMemOpType(const MemOp &Op,
3090b57cec5SDimitry Andric                           const AttributeList &FuncAttributes) const override;
3100b57cec5SDimitry Andric 
3110b57cec5SDimitry Andric   bool isMemOpUniform(const SDNode *N) const;
3120b57cec5SDimitry Andric   bool isMemOpHasNoClobberedMemOperand(const SDNode *N) const;
313480093f4SDimitry Andric 
314e8d8bef9SDimitry Andric   static bool isNonGlobalAddrSpace(unsigned AS);
3155ffd83dbSDimitry Andric 
3160b57cec5SDimitry Andric   bool isFreeAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override;
3170b57cec5SDimitry Andric 
3180b57cec5SDimitry Andric   TargetLoweringBase::LegalizeTypeAction
3190b57cec5SDimitry Andric   getPreferredVectorAction(MVT VT) const override;
3200b57cec5SDimitry Andric 
3210b57cec5SDimitry Andric   bool shouldConvertConstantLoadToIntImm(const APInt &Imm,
3220b57cec5SDimitry Andric                                         Type *Ty) const override;
3230b57cec5SDimitry Andric 
324*81ad6265SDimitry Andric   bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
325*81ad6265SDimitry Andric                                unsigned Index) const override;
326*81ad6265SDimitry Andric 
3270b57cec5SDimitry Andric   bool isTypeDesirableForOp(unsigned Op, EVT VT) const override;
3280b57cec5SDimitry Andric 
3290b57cec5SDimitry Andric   bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
3300b57cec5SDimitry Andric 
3310b57cec5SDimitry Andric   bool supportSplitCSR(MachineFunction *MF) const override;
3320b57cec5SDimitry Andric   void initializeSplitCSR(MachineBasicBlock *Entry) const override;
3330b57cec5SDimitry Andric   void insertCopiesSplitCSR(
3340b57cec5SDimitry Andric     MachineBasicBlock *Entry,
3350b57cec5SDimitry Andric     const SmallVectorImpl<MachineBasicBlock *> &Exits) const override;
3360b57cec5SDimitry Andric 
3370b57cec5SDimitry Andric   SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv,
3380b57cec5SDimitry Andric                                bool isVarArg,
3390b57cec5SDimitry Andric                                const SmallVectorImpl<ISD::InputArg> &Ins,
3400b57cec5SDimitry Andric                                const SDLoc &DL, SelectionDAG &DAG,
3410b57cec5SDimitry Andric                                SmallVectorImpl<SDValue> &InVals) const override;
3420b57cec5SDimitry Andric 
3430b57cec5SDimitry Andric   bool CanLowerReturn(CallingConv::ID CallConv,
3440b57cec5SDimitry Andric                       MachineFunction &MF, bool isVarArg,
3450b57cec5SDimitry Andric                       const SmallVectorImpl<ISD::OutputArg> &Outs,
3460b57cec5SDimitry Andric                       LLVMContext &Context) const override;
3470b57cec5SDimitry Andric 
3480b57cec5SDimitry Andric   SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
3490b57cec5SDimitry Andric                       const SmallVectorImpl<ISD::OutputArg> &Outs,
3500b57cec5SDimitry Andric                       const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
3510b57cec5SDimitry Andric                       SelectionDAG &DAG) const override;
3520b57cec5SDimitry Andric 
3530b57cec5SDimitry Andric   void passSpecialInputs(
3540b57cec5SDimitry Andric     CallLoweringInfo &CLI,
3550b57cec5SDimitry Andric     CCState &CCInfo,
3560b57cec5SDimitry Andric     const SIMachineFunctionInfo &Info,
3570b57cec5SDimitry Andric     SmallVectorImpl<std::pair<unsigned, SDValue>> &RegsToPass,
3580b57cec5SDimitry Andric     SmallVectorImpl<SDValue> &MemOpChains,
3590b57cec5SDimitry Andric     SDValue Chain) const;
3600b57cec5SDimitry Andric 
3610b57cec5SDimitry Andric   SDValue LowerCallResult(SDValue Chain, SDValue InFlag,
3620b57cec5SDimitry Andric                           CallingConv::ID CallConv, bool isVarArg,
3630b57cec5SDimitry Andric                           const SmallVectorImpl<ISD::InputArg> &Ins,
3640b57cec5SDimitry Andric                           const SDLoc &DL, SelectionDAG &DAG,
3650b57cec5SDimitry Andric                           SmallVectorImpl<SDValue> &InVals, bool isThisReturn,
3660b57cec5SDimitry Andric                           SDValue ThisVal) const;
3670b57cec5SDimitry Andric 
3680b57cec5SDimitry Andric   bool mayBeEmittedAsTailCall(const CallInst *) const override;
3690b57cec5SDimitry Andric 
3700b57cec5SDimitry Andric   bool isEligibleForTailCallOptimization(
3710b57cec5SDimitry Andric     SDValue Callee, CallingConv::ID CalleeCC, bool isVarArg,
3720b57cec5SDimitry Andric     const SmallVectorImpl<ISD::OutputArg> &Outs,
3730b57cec5SDimitry Andric     const SmallVectorImpl<SDValue> &OutVals,
3740b57cec5SDimitry Andric     const SmallVectorImpl<ISD::InputArg> &Ins, SelectionDAG &DAG) const;
3750b57cec5SDimitry Andric 
3760b57cec5SDimitry Andric   SDValue LowerCall(CallLoweringInfo &CLI,
3770b57cec5SDimitry Andric                     SmallVectorImpl<SDValue> &InVals) const override;
3780b57cec5SDimitry Andric 
3795ffd83dbSDimitry Andric   SDValue lowerDYNAMIC_STACKALLOCImpl(SDValue Op, SelectionDAG &DAG) const;
3805ffd83dbSDimitry Andric   SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const;
3815ffd83dbSDimitry Andric 
382480093f4SDimitry Andric   Register getRegisterByName(const char* RegName, LLT VT,
3838bcb0991SDimitry Andric                              const MachineFunction &MF) const override;
3840b57cec5SDimitry Andric 
3850b57cec5SDimitry Andric   MachineBasicBlock *splitKillBlock(MachineInstr &MI,
3860b57cec5SDimitry Andric                                     MachineBasicBlock *BB) const;
3870b57cec5SDimitry Andric 
3888bcb0991SDimitry Andric   void bundleInstWithWaitcnt(MachineInstr &MI) const;
3890b57cec5SDimitry Andric   MachineBasicBlock *emitGWSMemViolTestLoop(MachineInstr &MI,
3900b57cec5SDimitry Andric                                             MachineBasicBlock *BB) const;
3910b57cec5SDimitry Andric 
3920b57cec5SDimitry Andric   MachineBasicBlock *
3930b57cec5SDimitry Andric   EmitInstrWithCustomInserter(MachineInstr &MI,
3940b57cec5SDimitry Andric                               MachineBasicBlock *BB) const override;
3950b57cec5SDimitry Andric 
3960b57cec5SDimitry Andric   bool hasBitPreservingFPLogic(EVT VT) const override;
397*81ad6265SDimitry Andric   bool hasAtomicFaddRtnForTy(SDValue &Op) const;
3980b57cec5SDimitry Andric   bool enableAggressiveFMAFusion(EVT VT) const override;
3994824e7fdSDimitry Andric   bool enableAggressiveFMAFusion(LLT Ty) const override;
4000b57cec5SDimitry Andric   EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
4010b57cec5SDimitry Andric                          EVT VT) const override;
4020b57cec5SDimitry Andric   MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override;
403e8d8bef9SDimitry Andric   LLT getPreferredShiftAmountTy(LLT Ty) const override;
404e8d8bef9SDimitry Andric 
405480093f4SDimitry Andric   bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
406480093f4SDimitry Andric                                   EVT VT) const override;
4074824e7fdSDimitry Andric   bool isFMAFasterThanFMulAndFAdd(const MachineFunction &MF,
4084824e7fdSDimitry Andric                                   const LLT Ty) const override;
4095ffd83dbSDimitry Andric   bool isFMADLegal(const SelectionDAG &DAG, const SDNode *N) const override;
4104824e7fdSDimitry Andric   bool isFMADLegal(const MachineInstr &MI, const LLT Ty) const override;
411480093f4SDimitry Andric 
4120b57cec5SDimitry Andric   SDValue splitUnaryVectorOp(SDValue Op, SelectionDAG &DAG) const;
4130b57cec5SDimitry Andric   SDValue splitBinaryVectorOp(SDValue Op, SelectionDAG &DAG) const;
4148bcb0991SDimitry Andric   SDValue splitTernaryVectorOp(SDValue Op, SelectionDAG &DAG) const;
4150b57cec5SDimitry Andric   SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
4160b57cec5SDimitry Andric 
4170b57cec5SDimitry Andric   void ReplaceNodeResults(SDNode *N, SmallVectorImpl<SDValue> &Results,
4180b57cec5SDimitry Andric                           SelectionDAG &DAG) const override;
4190b57cec5SDimitry Andric 
4200b57cec5SDimitry Andric   SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
4210b57cec5SDimitry Andric   SDNode *PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const override;
422fe6060f1SDimitry Andric   void AddIMGInit(MachineInstr &MI) const;
4230b57cec5SDimitry Andric   void AdjustInstrPostInstrSelection(MachineInstr &MI,
4240b57cec5SDimitry Andric                                      SDNode *Node) const override;
4250b57cec5SDimitry Andric 
4260b57cec5SDimitry Andric   SDNode *legalizeTargetIndependentNode(SDNode *Node, SelectionDAG &DAG) const;
4270b57cec5SDimitry Andric 
4280b57cec5SDimitry Andric   MachineSDNode *wrapAddr64Rsrc(SelectionDAG &DAG, const SDLoc &DL,
4290b57cec5SDimitry Andric                                 SDValue Ptr) const;
4300b57cec5SDimitry Andric   MachineSDNode *buildRSRC(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr,
4310b57cec5SDimitry Andric                            uint32_t RsrcDword1, uint64_t RsrcDword2And3) const;
4320b57cec5SDimitry Andric   std::pair<unsigned, const TargetRegisterClass *>
4330b57cec5SDimitry Andric   getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
4340b57cec5SDimitry Andric                                StringRef Constraint, MVT VT) const override;
4350b57cec5SDimitry Andric   ConstraintType getConstraintType(StringRef Constraint) const override;
4365ffd83dbSDimitry Andric   void LowerAsmOperandForConstraint(SDValue Op,
4375ffd83dbSDimitry Andric                                     std::string &Constraint,
4385ffd83dbSDimitry Andric                                     std::vector<SDValue> &Ops,
4395ffd83dbSDimitry Andric                                     SelectionDAG &DAG) const override;
4405ffd83dbSDimitry Andric   bool getAsmOperandConstVal(SDValue Op, uint64_t &Val) const;
4415ffd83dbSDimitry Andric   bool checkAsmConstraintVal(SDValue Op,
4425ffd83dbSDimitry Andric                              const std::string &Constraint,
4435ffd83dbSDimitry Andric                              uint64_t Val) const;
4445ffd83dbSDimitry Andric   bool checkAsmConstraintValA(SDValue Op,
4455ffd83dbSDimitry Andric                               uint64_t Val,
4465ffd83dbSDimitry Andric                               unsigned MaxSize = 64) const;
4470b57cec5SDimitry Andric   SDValue copyToM0(SelectionDAG &DAG, SDValue Chain, const SDLoc &DL,
4480b57cec5SDimitry Andric                    SDValue V) const;
4490b57cec5SDimitry Andric 
4500b57cec5SDimitry Andric   void finalizeLowering(MachineFunction &MF) const override;
4510b57cec5SDimitry Andric 
4525ffd83dbSDimitry Andric   void computeKnownBitsForFrameIndex(int FrameIdx,
4530b57cec5SDimitry Andric                                      KnownBits &Known,
4545ffd83dbSDimitry Andric                                      const MachineFunction &MF) const override;
455e8d8bef9SDimitry Andric   void computeKnownBitsForTargetInstr(GISelKnownBits &Analysis, Register R,
456e8d8bef9SDimitry Andric                                       KnownBits &Known,
457e8d8bef9SDimitry Andric                                       const APInt &DemandedElts,
458e8d8bef9SDimitry Andric                                       const MachineRegisterInfo &MRI,
459e8d8bef9SDimitry Andric                                       unsigned Depth = 0) const override;
4600b57cec5SDimitry Andric 
4615ffd83dbSDimitry Andric   Align computeKnownAlignForTargetInstr(GISelKnownBits &Analysis, Register R,
4625ffd83dbSDimitry Andric                                         const MachineRegisterInfo &MRI,
4635ffd83dbSDimitry Andric                                         unsigned Depth = 0) const override;
4640b57cec5SDimitry Andric   bool isSDNodeSourceOfDivergence(const SDNode *N,
4650b57cec5SDimitry Andric     FunctionLoweringInfo *FLI, LegacyDivergenceAnalysis *DA) const override;
4660b57cec5SDimitry Andric 
46704eeddc0SDimitry Andric   bool hasMemSDNodeUser(SDNode *N) const;
46804eeddc0SDimitry Andric 
46904eeddc0SDimitry Andric   bool isReassocProfitable(SelectionDAG &DAG, SDValue N0,
47004eeddc0SDimitry Andric                            SDValue N1) const override;
47104eeddc0SDimitry Andric 
4720b57cec5SDimitry Andric   bool isCanonicalized(SelectionDAG &DAG, SDValue Op,
4730b57cec5SDimitry Andric                        unsigned MaxDepth = 5) const;
474fe6060f1SDimitry Andric   bool isCanonicalized(Register Reg, MachineFunction &MF,
475fe6060f1SDimitry Andric                        unsigned MaxDepth = 5) const;
476480093f4SDimitry Andric   bool denormalsEnabledForType(const SelectionDAG &DAG, EVT VT) const;
477fe6060f1SDimitry Andric   bool denormalsEnabledForType(LLT Ty, MachineFunction &MF) const;
4780b57cec5SDimitry Andric 
4790b57cec5SDimitry Andric   bool isKnownNeverNaNForTargetNode(SDValue Op,
4800b57cec5SDimitry Andric                                     const SelectionDAG &DAG,
4810b57cec5SDimitry Andric                                     bool SNaN = false,
4820b57cec5SDimitry Andric                                     unsigned Depth = 0) const override;
4830b57cec5SDimitry Andric   AtomicExpansionKind shouldExpandAtomicRMWInIR(AtomicRMWInst *) const override;
484*81ad6265SDimitry Andric   AtomicExpansionKind shouldExpandAtomicLoadInIR(LoadInst *LI) const override;
485*81ad6265SDimitry Andric   AtomicExpansionKind shouldExpandAtomicStoreInIR(StoreInst *SI) const override;
486*81ad6265SDimitry Andric   AtomicExpansionKind
487*81ad6265SDimitry Andric   shouldExpandAtomicCmpXchgInIR(AtomicCmpXchgInst *AI) const override;
4880b57cec5SDimitry Andric 
4898bcb0991SDimitry Andric   virtual const TargetRegisterClass *
4908bcb0991SDimitry Andric   getRegClassFor(MVT VT, bool isDivergent) const override;
4918bcb0991SDimitry Andric   virtual bool requiresUniformRegister(MachineFunction &MF,
4928bcb0991SDimitry Andric                                        const Value *V) const override;
4938bcb0991SDimitry Andric   Align getPrefLoopAlignment(MachineLoop *ML) const override;
4948bcb0991SDimitry Andric 
4958bcb0991SDimitry Andric   void allocateHSAUserSGPRs(CCState &CCInfo,
4968bcb0991SDimitry Andric                             MachineFunction &MF,
4978bcb0991SDimitry Andric                             const SIRegisterInfo &TRI,
4988bcb0991SDimitry Andric                             SIMachineFunctionInfo &Info) const;
4998bcb0991SDimitry Andric 
5008bcb0991SDimitry Andric   void allocateSystemSGPRs(CCState &CCInfo,
5018bcb0991SDimitry Andric                            MachineFunction &MF,
5028bcb0991SDimitry Andric                            SIMachineFunctionInfo &Info,
5038bcb0991SDimitry Andric                            CallingConv::ID CallConv,
5048bcb0991SDimitry Andric                            bool IsShader) const;
5058bcb0991SDimitry Andric 
5068bcb0991SDimitry Andric   void allocateSpecialEntryInputVGPRs(CCState &CCInfo,
5078bcb0991SDimitry Andric                                       MachineFunction &MF,
5088bcb0991SDimitry Andric                                       const SIRegisterInfo &TRI,
5098bcb0991SDimitry Andric                                       SIMachineFunctionInfo &Info) const;
5108bcb0991SDimitry Andric   void allocateSpecialInputSGPRs(
5118bcb0991SDimitry Andric     CCState &CCInfo,
5128bcb0991SDimitry Andric     MachineFunction &MF,
5138bcb0991SDimitry Andric     const SIRegisterInfo &TRI,
5148bcb0991SDimitry Andric     SIMachineFunctionInfo &Info) const;
5158bcb0991SDimitry Andric 
5168bcb0991SDimitry Andric   void allocateSpecialInputVGPRs(CCState &CCInfo,
5178bcb0991SDimitry Andric                                  MachineFunction &MF,
5188bcb0991SDimitry Andric                                  const SIRegisterInfo &TRI,
5198bcb0991SDimitry Andric                                  SIMachineFunctionInfo &Info) const;
5205ffd83dbSDimitry Andric   void allocateSpecialInputVGPRsFixed(CCState &CCInfo,
5215ffd83dbSDimitry Andric                                       MachineFunction &MF,
5225ffd83dbSDimitry Andric                                       const SIRegisterInfo &TRI,
5235ffd83dbSDimitry Andric                                       SIMachineFunctionInfo &Info) const;
5245ffd83dbSDimitry Andric 
525fe6060f1SDimitry Andric   std::pair<InstructionCost, MVT> getTypeLegalizationCost(const DataLayout &DL,
5265ffd83dbSDimitry Andric                                                           Type *Ty) const;
527*81ad6265SDimitry Andric 
528*81ad6265SDimitry Andric   MachineMemOperand::Flags
529*81ad6265SDimitry Andric   getTargetMMOFlags(const Instruction &I) const override;
5300b57cec5SDimitry Andric };
5310b57cec5SDimitry Andric 
5320b57cec5SDimitry Andric } // End namespace llvm
5330b57cec5SDimitry Andric 
5340b57cec5SDimitry Andric #endif
535