LLVM  5.0.0
SIISelLowering.h
Go to the documentation of this file.
1 //===-- SIISelLowering.h - SI DAG Lowering Interface ------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// \brief SI DAG Lowering interface definition
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_AMDGPU_SIISELLOWERING_H
16 #define LLVM_LIB_TARGET_AMDGPU_SIISELLOWERING_H
17 
18 #include "AMDGPUISelLowering.h"
19 #include "SIInstrInfo.h"
20 
21 namespace llvm {
22 
23 class SITargetLowering final : public AMDGPUTargetLowering {
24  SDValue lowerKernArgParameterPtr(SelectionDAG &DAG, const SDLoc &SL,
25  SDValue Chain, uint64_t Offset) const;
26  SDValue lowerKernargMemParameter(SelectionDAG &DAG, EVT VT, EVT MemVT,
27  const SDLoc &SL, SDValue Chain,
28  uint64_t Offset, bool Signed,
29  const ISD::InputArg *Arg = nullptr) const;
30 
31  SDValue lowerStackParameter(SelectionDAG &DAG, CCValAssign &VA,
32  const SDLoc &SL, SDValue Chain,
33  const ISD::InputArg &Arg) const;
34 
35  SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op,
36  SelectionDAG &DAG) const override;
37  SDValue lowerImplicitZextParam(SelectionDAG &DAG, SDValue Op,
38  MVT VT, unsigned Offset) const;
39 
40  SDValue LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) const;
41  SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, SelectionDAG &DAG) const;
42  SDValue LowerINTRINSIC_VOID(SDValue Op, SelectionDAG &DAG) const;
43  SDValue LowerLOAD(SDValue Op, SelectionDAG &DAG) const;
44  SDValue LowerSELECT(SDValue Op, SelectionDAG &DAG) const;
45  SDValue lowerFastUnsafeFDIV(SDValue Op, SelectionDAG &DAG) const;
46  SDValue lowerFDIV_FAST(SDValue Op, SelectionDAG &DAG) const;
47  SDValue LowerFDIV16(SDValue Op, SelectionDAG &DAG) const;
48  SDValue LowerFDIV32(SDValue Op, SelectionDAG &DAG) const;
49  SDValue LowerFDIV64(SDValue Op, SelectionDAG &DAG) const;
50  SDValue LowerFDIV(SDValue Op, SelectionDAG &DAG) const;
51  SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG, bool Signed) const;
52  SDValue LowerSTORE(SDValue Op, SelectionDAG &DAG) const;
53  SDValue LowerTrig(SDValue Op, SelectionDAG &DAG) const;
54  SDValue LowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
55  SDValue LowerBRCOND(SDValue Op, SelectionDAG &DAG) const;
56 
57  /// \brief Converts \p Op, which must be of floating point type, to the
58  /// floating point type \p VT, by either extending or truncating it.
59  SDValue getFPExtOrFPTrunc(SelectionDAG &DAG,
60  SDValue Op,
61  const SDLoc &DL,
62  EVT VT) const;
63 
64  SDValue convertArgType(
65  SelectionDAG &DAG, EVT VT, EVT MemVT, const SDLoc &SL, SDValue Val,
66  bool Signed, const ISD::InputArg *Arg = nullptr) const;
67 
68  /// \brief Custom lowering for ISD::FP_ROUND for MVT::f16.
69  SDValue lowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const;
70 
71  SDValue getSegmentAperture(unsigned AS, const SDLoc &DL,
72  SelectionDAG &DAG) const;
73 
74  SDValue lowerADDRSPACECAST(SDValue Op, SelectionDAG &DAG) const;
75  SDValue lowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
76  SDValue lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const;
77  SDValue lowerTRAP(SDValue Op, SelectionDAG &DAG) const;
78 
79  void adjustWritemask(MachineSDNode *&N, SelectionDAG &DAG) const;
80 
81  SDValue performUCharToFloatCombine(SDNode *N,
82  DAGCombinerInfo &DCI) const;
83  SDValue performSHLPtrCombine(SDNode *N,
84  unsigned AS,
85  DAGCombinerInfo &DCI) const;
86 
87  SDValue performMemSDNodeCombine(MemSDNode *N, DAGCombinerInfo &DCI) const;
88 
89  SDValue splitBinaryBitConstantOp(DAGCombinerInfo &DCI, const SDLoc &SL,
90  unsigned Opc, SDValue LHS,
91  const ConstantSDNode *CRHS) const;
92 
93  SDValue performAndCombine(SDNode *N, DAGCombinerInfo &DCI) const;
94  SDValue performOrCombine(SDNode *N, DAGCombinerInfo &DCI) const;
95  SDValue performXorCombine(SDNode *N, DAGCombinerInfo &DCI) const;
96  SDValue performZeroExtendCombine(SDNode *N, DAGCombinerInfo &DCI) const;
97  SDValue performClassCombine(SDNode *N, DAGCombinerInfo &DCI) const;
98  SDValue performFCanonicalizeCombine(SDNode *N, DAGCombinerInfo &DCI) const;
99 
100  SDValue performFPMed3ImmCombine(SelectionDAG &DAG, const SDLoc &SL,
101  SDValue Op0, SDValue Op1) const;
102  SDValue performIntMed3ImmCombine(SelectionDAG &DAG, const SDLoc &SL,
103  SDValue Op0, SDValue Op1, bool Signed) const;
104  SDValue performMinMaxCombine(SDNode *N, DAGCombinerInfo &DCI) const;
105  SDValue performFMed3Combine(SDNode *N, DAGCombinerInfo &DCI) const;
106  SDValue performCvtPkRTZCombine(SDNode *N, DAGCombinerInfo &DCI) const;
107  SDValue performExtractVectorEltCombine(SDNode *N, DAGCombinerInfo &DCI) const;
108 
109  unsigned getFusedOpcode(const SelectionDAG &DAG,
110  const SDNode *N0, const SDNode *N1) const;
111  SDValue performAddCombine(SDNode *N, DAGCombinerInfo &DCI) const;
112  SDValue performAddCarrySubCarryCombine(SDNode *N, DAGCombinerInfo &DCI) const;
113  SDValue performSubCombine(SDNode *N, DAGCombinerInfo &DCI) const;
114  SDValue performFAddCombine(SDNode *N, DAGCombinerInfo &DCI) const;
115  SDValue performFSubCombine(SDNode *N, DAGCombinerInfo &DCI) const;
116  SDValue performSetCCCombine(SDNode *N, DAGCombinerInfo &DCI) const;
117  SDValue performCvtF32UByteNCombine(SDNode *N, DAGCombinerInfo &DCI) const;
118 
119  bool isLegalFlatAddressingMode(const AddrMode &AM) const;
120  bool isLegalMUBUFAddressingMode(const AddrMode &AM) const;
121 
122  unsigned isCFIntrinsic(const SDNode *Intr) const;
123 
124  void createDebuggerPrologueStackObjects(MachineFunction &MF) const;
125 
126  /// \returns True if fixup needs to be emitted for given global value \p GV,
127  /// false otherwise.
128  bool shouldEmitFixup(const GlobalValue *GV) const;
129 
130  /// \returns True if GOT relocation needs to be emitted for given global value
131  /// \p GV, false otherwise.
132  bool shouldEmitGOTReloc(const GlobalValue *GV) const;
133 
134  /// \returns True if PC-relative relocation needs to be emitted for given
135  /// global value \p GV, false otherwise.
136  bool shouldEmitPCReloc(const GlobalValue *GV) const;
137 
138 public:
139  SITargetLowering(const TargetMachine &tm, const SISubtarget &STI);
140 
141  const SISubtarget *getSubtarget() const;
142 
143  bool isShuffleMaskLegal(const SmallVectorImpl<int> &/*Mask*/,
144  EVT /*VT*/) const override;
145 
146  bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &,
147  unsigned IntrinsicID) const override;
148 
149  bool getAddrModeArguments(IntrinsicInst * /*I*/,
150  SmallVectorImpl<Value*> &/*Ops*/,
151  Type *&/*AccessTy*/) const override;
152 
153  bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty,
154  unsigned AS) const override;
155 
156  bool canMergeStoresTo(unsigned AS, EVT MemVT,
157  const SelectionDAG &DAG) const override;
158 
159  bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS,
160  unsigned Align,
161  bool *IsFast) const override;
162 
163  EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign,
164  unsigned SrcAlign, bool IsMemset,
165  bool ZeroMemset,
166  bool MemcpyStrSrc,
167  MachineFunction &MF) const override;
168 
169  bool isMemOpUniform(const SDNode *N) const;
170  bool isMemOpHasNoClobberedMemOperand(const SDNode *N) const;
171  bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override;
172  bool isCheapAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override;
173 
175  getPreferredVectorAction(EVT VT) const override;
176 
178  Type *Ty) const override;
179 
180  bool isTypeDesirableForOp(unsigned Op, EVT VT) const override;
181 
182  bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override;
183 
185  bool isVarArg,
187  const SDLoc &DL, SelectionDAG &DAG,
188  SmallVectorImpl<SDValue> &InVals) const override;
189 
190  bool CanLowerReturn(CallingConv::ID CallConv,
191  MachineFunction &MF, bool isVarArg,
193  LLVMContext &Context) const override;
194 
195  SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
197  const SmallVectorImpl<SDValue> &OutVals, const SDLoc &DL,
198  SelectionDAG &DAG) const override;
199 
200  unsigned getRegisterByName(const char* RegName, EVT VT,
201  SelectionDAG &DAG) const override;
202 
204  MachineBasicBlock *BB) const;
205 
208  MachineBasicBlock *BB) const override;
209  bool enableAggressiveFMAFusion(EVT VT) const override;
210  EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context,
211  EVT VT) const override;
212  MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override;
213  bool isFMAFasterThanFMulAndFAdd(EVT VT) const override;
214  SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
216  SelectionDAG &DAG) const override;
217 
218  SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;
219  SDNode *PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const override;
221  SDNode *Node) const override;
222 
224 
226  SDValue Ptr) const;
227  MachineSDNode *buildRSRC(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr,
228  uint32_t RsrcDword1, uint64_t RsrcDword2And3) const;
229  std::pair<unsigned, const TargetRegisterClass *>
231  StringRef Constraint, MVT VT) const override;
232  ConstraintType getConstraintType(StringRef Constraint) const override;
233  SDValue copyToM0(SelectionDAG &DAG, SDValue Chain, const SDLoc &DL,
234  SDValue V) const;
235 
236  void finalizeLowering(MachineFunction &MF) const override;
237 };
238 
239 } // End namespace llvm
240 
241 #endif
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
MachineSDNode * wrapAddr64Rsrc(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr) const
This represents an addressing mode of: BaseGV + BaseOffs + BaseReg + Scale*ScaleReg If BaseGV is null...
std::pair< unsigned, const TargetRegisterClass * > getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const override
Given a physical register constraint (e.g.
bool isFMAFasterThanFMulAndFAdd(EVT VT) const override
Return true if an FMA operation is faster than a pair of fmul and fadd instructions.
LLVMContext & Context
bool isLegalAddressingMode(const DataLayout &DL, const AddrMode &AM, Type *Ty, unsigned AS) const override
Return true if the addressing mode represented by AM is legal for this target, for a load/store of th...
InputArg - This struct carries flags and type information about a single incoming (formal) argument o...
bool canMergeStoresTo(unsigned AS, EVT MemVT, const SelectionDAG &DAG) const override
Returns if it's reasonable to merge stores to MemVT size.
DataLayout DL
This class represents a function call, abstracting a target machine's calling convention.
bool getTgtMemIntrinsic(IntrinsicInfo &, const CallInst &, unsigned IntrinsicID) const override
Given an intrinsic, checks if on the target the intrinsic will need to map to a MemIntrinsicNode (tou...
Function Alias Analysis Results
bool isMemOpUniform(const SDNode *N) const
EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const override
Return the ValueType of the result of SETCC operations.
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
bool getAddrModeArguments(IntrinsicInst *, SmallVectorImpl< Value * > &, Type *&) const override
CodeGenPrepare sinks address calculations into the same BB as Load/Store instructions reading the add...
bool isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const override
Return true if folding a constant offset with the given GlobalAddress is legal.
const AMDGPUAS &AS return SrcAS
bool isShuffleMaskLegal(const SmallVectorImpl< int > &, EVT) const override
Targets can use this to indicate that they only support some VECTOR_SHUFFLE operations, those with specific masks.
bool enableAggressiveFMAFusion(EVT VT) const override
Return true if target always beneficiates from combining into FMA for a given value type...
ConstraintType getConstraintType(StringRef Constraint) const override
Given a constraint, return the type of constraint it is for this target.
Machine Value Type.
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
SDNode * PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const override
Fold the instructions after selecting them.
EVT getOptimalMemOpType(uint64_t Size, unsigned DstAlign, unsigned SrcAlign, bool IsMemset, bool ZeroMemset, bool MemcpyStrSrc, MachineFunction &MF) const override
Returns the target specific optimal type for load and store operations as a result of memset...
SITargetLowering(const TargetMachine &tm, const SISubtarget &STI)
Extended Value Type.
Definition: ValueTypes.h:34
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MVT getScalarShiftAmountTy(const DataLayout &, EVT) const override
EVT is not used in-tree, but is used by out-of-tree target.
TargetLoweringBase::LegalizeTypeAction getPreferredVectorAction(EVT VT) const override
Return the preferred vector type legalization action.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:209
Interface definition of the TargetLowering class that is common to all AMD GPUs.
CCValAssign - Represent assignment of one arg/retval to a location.
SDNode * legalizeTargetIndependentNode(SDNode *Node, SelectionDAG &DAG) const
Legalize target independent instructions (e.g.
An SDNode that represents everything that will be needed to construct a MachineInstr.
const size_t N
This is an abstract virtual class for memory operations.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SDValue LowerFormalArguments(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::InputArg > &Ins, const SDLoc &DL, SelectionDAG &DAG, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower the incoming (formal) arguments, described by the Ins array...
Class for arbitrary precision integers.
Definition: APInt.h:69
void finalizeLowering(MachineFunction &MF) const override
Execute target specific actions to finalize target lowering.
SDValue copyToM0(SelectionDAG &DAG, SDValue Chain, const SDLoc &DL, SDValue V) const
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, LLVMContext &Context) const override
This hook should be implemented to check whether the return values described by the Outs array can fi...
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AS, unsigned Align, bool *IsFast) const override
Determine if the target supports unaligned memory accesses.
void AdjustInstrPostInstrSelection(MachineInstr &MI, SDNode *Node) const override
Assign the register class depending on the number of bits set in the writemask.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
bool isNoopAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast between SrcAS and DestAS is a noop.
bool isCheapAddrSpaceCast(unsigned SrcAS, unsigned DestAS) const override
Returns true if a cast from SrcAS to DestAS is "cheap", such that e.g.
const SISubtarget * getSubtarget() const
Representation of each machine instruction.
Definition: MachineInstr.h:59
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &DL, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array...
Interface definition for SIInstrInfo.
bool isMemOpHasNoClobberedMemOperand(const SDNode *N) const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
LegalizeTypeAction
This enum indicates whether a types are legal for a target, and if not, what action should be used to...
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool isTypeDesirableForOp(unsigned Op, EVT VT) const override
Return true if the target has native support for the specified value type and it is 'desirable' to us...
int * Ptr
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
MachineBasicBlock * EmitInstrWithCustomInserter(MachineInstr &MI, MachineBasicBlock *BB) const override
This method should be implemented by targets that mark instructions with the 'usesCustomInserter' fla...
MachineSDNode * buildRSRC(SelectionDAG &DAG, const SDLoc &DL, SDValue Ptr, uint32_t RsrcDword1, uint64_t RsrcDword2And3) const
Return a resource descriptor with the 'Add TID' bit enabled The TID (Thread ID) is multiplied by the ...
bool shouldConvertConstantLoadToIntImm(const APInt &Imm, Type *Ty) const override
Return true if it is beneficial to convert a load of a constant to just the constant itself...
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:44
unsigned getRegisterByName(const char *RegName, EVT VT, SelectionDAG &DAG) const override
Return the register ID of the name passed in.
MachineBasicBlock * splitKillBlock(MachineInstr &MI, MachineBasicBlock *BB) const
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...