LLVM 23.0.0git
AMDGPUISelDAGToDAG.h
Go to the documentation of this file.
1//===-- AMDGPUISelDAGToDAG.h - A dag to dag inst selector for AMDGPU ----===//
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/// Defines an instruction selector for the AMDGPU target.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUISELDAGTODAG_H
15#define LLVM_LIB_TARGET_AMDGPU_AMDGPUISELDAGTODAG_H
16
18#include "GCNSubtarget.h"
25
26namespace llvm {
27
28static inline bool getConstantValue(SDValue N, uint32_t &Out) {
29 // This is only used for packed vectors, where using 0 for undef should
30 // always be good.
31 if (N.isUndef()) {
32 Out = 0;
33 return true;
34 }
35
37 Out = C->getAPIntValue().getSExtValue();
38 return true;
39 }
40
42 Out = C->getValueAPF().bitcastToAPInt().getSExtValue();
43 return true;
44 }
45
46 return false;
47}
48
49/// AMDGPU specific code to select AMDGPU machine instructions for
50/// SelectionDAG operations.
52 // Subtarget - Keep a pointer to the AMDGPU Subtarget around so that we can
53 // make the right decision when generating code for different targets.
54 const GCNSubtarget *Subtarget;
55
56 // Default FP mode for the current function.
58
59 // Instructions that will be lowered with a final instruction that zeros the
60 // high result bits.
61 bool fp16SrcZerosHighBits(unsigned Opc) const;
62
63public:
65
67
70 void PreprocessISelDAG() override;
71 void Select(SDNode *N) override;
72 void PostprocessISelDAG() override;
73
74protected:
75 void SelectBuildVector(SDNode *N, unsigned RegClassID);
77
78private:
79 std::pair<SDValue, SDValue> foldFrameIndex(SDValue N) const;
80
81 bool isInlineImmediate(const SDNode *N) const;
82
83 bool isInlineImmediate(const APInt &Imm) const {
84 return Subtarget->getInstrInfo()->isInlineConstant(Imm);
85 }
86
87 bool isInlineImmediate(const APFloat &Imm) const {
88 return Subtarget->getInstrInfo()->isInlineConstant(Imm);
89 }
90
91 bool isVGPRImm(const SDNode *N) const;
92 bool isUniformLoad(const SDNode *N) const;
93 bool isUniformBr(const SDNode *N) const;
94
95 MachineSDNode *buildRegSequence16(SmallVectorImpl<SDValue> &Elts,
96 const SDLoc &DL) const;
97 MachineSDNode *buildRegSequence32(SmallVectorImpl<SDValue> &Elts,
98 const SDLoc &DL) const;
99 MachineSDNode *buildRegSequence(SmallVectorImpl<SDValue> &Elts,
100 const SDLoc &DL, unsigned ElementSize) const;
101
102 void selectWMMAModsNegAbs(unsigned ModOpcode, unsigned &Mods,
103 SmallVectorImpl<SDValue> &Elts, SDValue &Src,
104 const SDLoc &DL, unsigned ElementSize) const;
105
106 // Returns true if ISD::AND SDNode `N`'s masking of the shift amount operand's
107 // `ShAmtBits` bits is unneeded.
108 bool isUnneededShiftMask(const SDNode *N, unsigned ShAmtBits) const;
109
110 bool isBaseWithConstantOffset64(SDValue Addr, SDValue &LHS,
111 SDValue &RHS) const;
112
113 MachineSDNode *buildSMovImm64(SDLoc &DL, uint64_t Val, EVT VT) const;
114
115 SDNode *packConstantV2I16(const SDNode *N, SelectionDAG &DAG) const;
116
117 SDNode *glueCopyToOp(SDNode *N, SDValue NewChain, SDValue Glue) const;
118 SDNode *glueCopyToM0(SDNode *N, SDValue Val) const;
119 SDNode *glueCopyToM0LDSInit(SDNode *N) const;
120
121 const TargetRegisterClass *getOperandRegClass(SDNode *N, unsigned OpNo) const;
122 virtual bool SelectADDRVTX_READ(SDValue Addr, SDValue &Base, SDValue &Offset);
123 virtual bool SelectADDRIndirect(SDValue Addr, SDValue &Base, SDValue &Offset);
124 bool isDSOffsetLegal(SDValue Base, unsigned Offset) const;
125 bool isDSOffset2Legal(SDValue Base, unsigned Offset0, unsigned Offset1,
126 unsigned Size) const;
127
128 bool isFlatScratchBaseLegal(SDValue Addr) const;
129 bool isFlatScratchBaseLegalSV(SDValue Addr) const;
130 bool isFlatScratchBaseLegalSVImm(SDValue Addr) const;
131 bool isSOffsetLegalWithImmOffset(SDValue *SOffset, bool Imm32Only,
132 bool IsBuffer, int64_t ImmOffset = 0) const;
133
134 bool SelectDS1Addr1Offset(SDValue Ptr, SDValue &Base, SDValue &Offset) const;
135 bool SelectDS64Bit4ByteAligned(SDValue Ptr, SDValue &Base, SDValue &Offset0,
136 SDValue &Offset1) const;
137 bool SelectDS128Bit8ByteAligned(SDValue Ptr, SDValue &Base, SDValue &Offset0,
138 SDValue &Offset1) const;
139 bool SelectDSReadWrite2(SDValue Ptr, SDValue &Base, SDValue &Offset0,
140 SDValue &Offset1, unsigned Size) const;
141 bool SelectMUBUF(SDValue Addr, SDValue &SRsrc, SDValue &VAddr,
142 SDValue &SOffset, SDValue &Offset, SDValue &Offen,
143 SDValue &Idxen, SDValue &Addr64) const;
144 bool SelectMUBUFAddr64(SDValue Addr, SDValue &SRsrc, SDValue &VAddr,
145 SDValue &SOffset, SDValue &Offset) const;
146 bool SelectMUBUFScratchOffen(SDNode *Parent, SDValue Addr, SDValue &RSrc,
147 SDValue &VAddr, SDValue &SOffset,
148 SDValue &ImmOffset) const;
149 bool SelectMUBUFScratchOffset(SDNode *Parent, SDValue Addr, SDValue &SRsrc,
150 SDValue &Soffset, SDValue &Offset) const;
151
152 bool SelectMUBUFOffset(SDValue Addr, SDValue &SRsrc, SDValue &Soffset,
153 SDValue &Offset) const;
154 bool SelectBUFSOffset(SDValue Addr, SDValue &SOffset) const;
155
156 bool SelectFlatOffsetImpl(SDNode *N, SDValue Addr, SDValue &VAddr,
157 SDValue &Offset, uint64_t FlatVariant) const;
158 bool SelectFlatOffset(SDNode *N, SDValue Addr, SDValue &VAddr,
159 SDValue &Offset) const;
160 bool SelectGlobalOffset(SDNode *N, SDValue Addr, SDValue &VAddr,
161 SDValue &Offset) const;
162 bool SelectScratchOffset(SDNode *N, SDValue Addr, SDValue &VAddr,
163 SDValue &Offset) const;
164 bool SelectGlobalSAddr(SDNode *N, SDValue Addr, SDValue &SAddr,
165 SDValue &VOffset, SDValue &Offset, bool &ScaleOffset,
166 bool NeedIOffset = true) const;
167 bool SelectGlobalSAddr(SDNode *N, SDValue Addr, SDValue &SAddr,
168 SDValue &VOffset, SDValue &Offset,
169 SDValue &CPol) const;
170 bool SelectGlobalSAddrCPol(SDNode *N, SDValue Addr, SDValue &SAddr,
171 SDValue &VOffset, SDValue &Offset,
172 SDValue &CPol) const;
173 bool SelectGlobalSAddrCPolM0(SDNode *N, SDValue Addr, SDValue &SAddr,
174 SDValue &VOffset, SDValue &Offset,
175 SDValue &CPol) const;
176 bool SelectGlobalSAddrGLC(SDNode *N, SDValue Addr, SDValue &SAddr,
177 SDValue &VOffset, SDValue &Offset,
178 SDValue &CPol) const;
179 bool SelectGlobalSAddrNoIOffset(SDNode *N, SDValue Addr, SDValue &SAddr,
180 SDValue &VOffset, SDValue &CPol) const;
181 bool SelectGlobalSAddrNoIOffsetM0(SDNode *N, SDValue Addr, SDValue &SAddr,
182 SDValue &VOffset, SDValue &CPol) const;
183 bool SelectScratchSAddr(SDNode *N, SDValue Addr, SDValue &SAddr,
184 SDValue &Offset) const;
185 bool checkFlatScratchSVSSwizzleBug(SDValue VAddr, SDValue SAddr,
186 uint64_t ImmOffset) const;
187 bool SelectScratchSVAddr(SDNode *N, SDValue Addr, SDValue &VAddr,
188 SDValue &SAddr, SDValue &Offset,
189 SDValue &CPol) const;
190
191 bool SelectSMRDOffset(SDNode *N, SDValue ByteOffsetNode, SDValue *SOffset,
192 SDValue *Offset, bool Imm32Only = false,
193 bool IsBuffer = false, bool HasSOffset = false,
194 int64_t ImmOffset = 0,
195 bool *ScaleOffset = nullptr) const;
196 SDValue Expand32BitAddress(SDValue Addr) const;
197 bool SelectSMRDBaseOffset(SDNode *N, SDValue Addr, SDValue &SBase,
198 SDValue *SOffset, SDValue *Offset,
199 bool Imm32Only = false, bool IsBuffer = false,
200 bool HasSOffset = false, int64_t ImmOffset = 0,
201 bool *ScaleOffset = nullptr) const;
202 bool SelectSMRD(SDNode *N, SDValue Addr, SDValue &SBase, SDValue *SOffset,
203 SDValue *Offset, bool Imm32Only = false,
204 bool *ScaleOffset = nullptr) const;
205 bool SelectSMRDImm(SDValue Addr, SDValue &SBase, SDValue &Offset) const;
206 bool SelectSMRDImm32(SDValue Addr, SDValue &SBase, SDValue &Offset) const;
207 bool SelectScaleOffset(SDNode *N, SDValue &Offset, bool IsSigned) const;
208 bool SelectSMRDSgpr(SDNode *N, SDValue Addr, SDValue &SBase, SDValue &SOffset,
209 SDValue &CPol) const;
210 bool SelectSMRDSgprImm(SDNode *N, SDValue Addr, SDValue &SBase,
211 SDValue &SOffset, SDValue &Offset,
212 SDValue &CPol) const;
213 bool SelectSMRDBufferImm(SDValue N, SDValue &Offset) const;
214 bool SelectSMRDBufferImm32(SDValue N, SDValue &Offset) const;
215 bool SelectSMRDBufferSgprImm(SDValue N, SDValue &SOffset,
216 SDValue &Offset) const;
217 bool SelectSMRDPrefetchImm(SDValue Addr, SDValue &SBase,
218 SDValue &Offset) const;
219 bool SelectMOVRELOffset(SDValue Index, SDValue &Base, SDValue &Offset) const;
220
221 bool SelectVOP3ModsImpl(SDValue In, SDValue &Src, unsigned &SrcMods,
222 bool IsCanonicalizing = true,
223 bool AllowAbs = true) const;
224 bool SelectVOP3Mods(SDValue In, SDValue &Src, SDValue &SrcMods) const;
225 bool SelectVOP3ModsNonCanonicalizing(SDValue In, SDValue &Src,
226 SDValue &SrcMods) const;
227 bool SelectVOP3BMods(SDValue In, SDValue &Src, SDValue &SrcMods) const;
228 bool SelectVOP3NoMods(SDValue In, SDValue &Src) const;
229 bool SelectVOP3Mods0(SDValue In, SDValue &Src, SDValue &SrcMods,
230 SDValue &Clamp, SDValue &Omod) const;
231 bool SelectVOP3BMods0(SDValue In, SDValue &Src, SDValue &SrcMods,
232 SDValue &Clamp, SDValue &Omod) const;
233 bool SelectVOP3NoMods0(SDValue In, SDValue &Src, SDValue &SrcMods,
234 SDValue &Clamp, SDValue &Omod) const;
235
236 bool SelectVINTERPModsImpl(SDValue In, SDValue &Src, SDValue &SrcMods,
237 bool OpSel) const;
238 bool SelectVINTERPMods(SDValue In, SDValue &Src, SDValue &SrcMods) const;
239 bool SelectVINTERPModsHi(SDValue In, SDValue &Src, SDValue &SrcMods) const;
240
241 bool SelectVOP3OMods(SDValue In, SDValue &Src, SDValue &Clamp,
242 SDValue &Omod) const;
243
244 bool SelectVOP3PMods(SDValue In, SDValue &Src, SDValue &SrcMods,
245 bool IsDOT = false) const;
246 bool SelectVOP3PModsDOT(SDValue In, SDValue &Src, SDValue &SrcMods) const;
247 bool SelectVOP3PNoModsDOT(SDValue In, SDValue &Src) const;
248 bool SelectVOP3PModsF32(SDValue In, SDValue &Src, SDValue &SrcMods) const;
249 bool SelectVOP3PNoModsF32(SDValue In, SDValue &Src) const;
250
251 bool SelectWMMAOpSelVOP3PMods(SDValue In, SDValue &Src) const;
252
253 bool SelectWMMAModsF32NegAbs(SDValue In, SDValue &Src,
254 SDValue &SrcMods) const;
255 bool SelectWMMAModsF16Neg(SDValue In, SDValue &Src, SDValue &SrcMods) const;
256 bool SelectWMMAModsF16NegAbs(SDValue In, SDValue &Src,
257 SDValue &SrcMods) const;
258 bool SelectWMMAVISrc(SDValue In, SDValue &Src) const;
259
260 bool SelectSWMMACIndex8(SDValue In, SDValue &Src, SDValue &IndexKey) const;
261 bool SelectSWMMACIndex16(SDValue In, SDValue &Src, SDValue &IndexKey) const;
262 bool SelectSWMMACIndex32(SDValue In, SDValue &Src, SDValue &IndexKey) const;
263
264 bool SelectVOP3OpSel(SDValue In, SDValue &Src, SDValue &SrcMods) const;
265
266 bool SelectVOP3OpSelMods(SDValue In, SDValue &Src, SDValue &SrcMods) const;
267 bool SelectVOP3PMadMixModsImpl(SDValue In, SDValue &Src, unsigned &Mods,
268 MVT VT) const;
269 bool SelectVOP3PMadMixModsExt(SDValue In, SDValue &Src,
270 SDValue &SrcMods) const;
271 bool SelectVOP3PMadMixMods(SDValue In, SDValue &Src, SDValue &SrcMods) const;
272 bool SelectVOP3PMadMixBF16ModsExt(SDValue In, SDValue &Src,
273 SDValue &SrcMods) const;
274 bool SelectVOP3PMadMixBF16Mods(SDValue In, SDValue &Src,
275 SDValue &SrcMods) const;
276
277 bool SelectBITOP3(SDValue In, SDValue &Src0, SDValue &Src1, SDValue &Src2,
278 SDValue &Tbl) const;
279
280 SDValue getHi16Elt(SDValue In) const;
281
282 SDValue getMaterializedScalarImm32(int64_t Val, const SDLoc &DL) const;
283
284 void SelectADD_SUB_I64(SDNode *N);
285 void SelectAddcSubb(SDNode *N);
286 void SelectUADDO_USUBO(SDNode *N);
287 void SelectDIV_SCALE(SDNode *N);
288 void SelectMAD_64_32(SDNode *N);
289 void SelectMUL_LOHI(SDNode *N);
290 void SelectFMA_W_CHAIN(SDNode *N);
291 void SelectFMUL_W_CHAIN(SDNode *N);
292 SDNode *getBFE32(bool IsSigned, const SDLoc &DL, SDValue Val, uint32_t Offset,
293 uint32_t Width);
294 void SelectS_BFEFromShifts(SDNode *N);
295 void SelectS_BFE(SDNode *N);
296 bool isCBranchSCC(const SDNode *N) const;
297 void SelectBRCOND(SDNode *N);
298 void SelectFMAD_FMA(SDNode *N);
299 void SelectFP_EXTEND(SDNode *N);
300 void SelectDSAppendConsume(SDNode *N, unsigned IntrID);
301 void SelectDSBvhStackIntrinsic(SDNode *N, unsigned IntrID);
302 void SelectTensorLoadStore(SDNode *N, unsigned IntrID);
303 void SelectDS_GWS(SDNode *N, unsigned IntrID);
304 void SelectInterpP1F16(SDNode *N);
305 void SelectINTRINSIC_W_CHAIN(SDNode *N);
306 void SelectINTRINSIC_WO_CHAIN(SDNode *N);
307 void SelectINTRINSIC_VOID(SDNode *N);
308 void SelectWAVE_ADDRESS(SDNode *N);
309 void SelectSTACKRESTORE(SDNode *N);
310
311protected:
312 // Include the pieces autogenerated from the target description.
313#include "AMDGPUGenDAGISel.inc"
314};
315
323
325public:
326 static char ID;
327
329
330 bool runOnMachineFunction(MachineFunction &MF) override;
331 void getAnalysisUsage(AnalysisUsage &AU) const override;
332 StringRef getPassName() const override;
333};
334
335} // namespace llvm
336
337#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUISELDAGTODAG_H
return SDValue()
AMDGPU address space definition.
static Register buildRegSequence(SmallVectorImpl< Register > &Elts, MachineInstr *InsertPt, MachineRegisterInfo &MRI)
static void selectWMMAModsNegAbs(unsigned ModOpcode, unsigned &Mods, SmallVectorImpl< Register > &Elts, Register &Src, MachineInstr *InsertPt, MachineRegisterInfo &MRI)
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
AMD GCN specific subclass of TargetSubtarget.
Value * RHS
Value * LHS
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
AMDGPUDAGToDAGISelLegacy(TargetMachine &TM, CodeGenOptLevel OptLevel)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
StringRef getPassName() const override
getPassName - Return a nice clean name for a pass.
void SelectBuildVector(SDNode *N, unsigned RegClassID)
bool runOnMachineFunction(MachineFunction &MF) override
void PreprocessISelDAG() override
PreprocessISelDAG - This hook allows targets to hack on the graph before instruction selection starts...
void PostprocessISelDAG() override
PostprocessISelDAG() - This hook allows the target to hack on the graph right after selection.
bool matchLoadD16FromBuildVector(SDNode *N) const
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
AMDGPUISelDAGToDAGPass(TargetMachine &TM)
Class for arbitrary precision integers.
Definition APInt.h:78
Represent the analysis usage information of a pass.
const SIInstrInfo * getInstrInfo() const override
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
Represents one node in the SelectionDAG.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
bool isInlineConstant(const APInt &Imm) const
SelectionDAGISelLegacy(char &ID, std::unique_ptr< SelectionDAGISel > S)
SelectionDAGISelPass(std::unique_ptr< SelectionDAGISel > Selector)
SelectionDAGISel(TargetMachine &tm, CodeGenOptLevel OL=CodeGenOptLevel::Default)
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Primary interface to the complete machine description for the target machine.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
@ Offset
Definition DWP.cpp:532
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
static bool getConstantValue(SDValue N, uint32_t &Out)
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
#define N