LLVM 24.0.0git
AMDGPUInstrInfo.h
Go to the documentation of this file.
1//===-- AMDGPUInstrInfo.h - AMDGPU Instruction Information ------*- 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/// Contains the definition of a TargetInstrInfo class that is common
11/// to all AMD GPUs.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUINSTRINFO_H
16#define LLVM_LIB_TARGET_AMDGPU_AMDGPUINSTRINFO_H
17
19
20namespace llvm {
21
23class MachineInstr;
24
25namespace AMDGPU {
26
27bool isUniformMMO(const MachineMemOperand *MMO);
28
29/// Return the intrinsic ID for opcodes with the G_AMDGPU_INTRIN_ prefix.
30///
31/// These opcodes have an Intrinsic::ID operand similar to a GIntrinsic. But
32/// they are not actual instances of GIntrinsics, so we cannot use
33/// GIntrinsic::getIntrinsicID() on them.
34Intrinsic::ID getIntrinsicID(const MachineInstr &I);
35
37 unsigned Intr;
39 bool IsImage;
40};
41const RsrcIntrinsic *lookupRsrcIntrinsic(unsigned Intr);
42
43#define GET_BufferIntrinsicKind_DECL
44#include "AMDGPUGenSearchableTables.inc"
45
46/// The argument layout of a buffer intrinsic. Argument positions are indices
47/// into the IR call's argument list, with NoArg for arguments the intrinsic
48/// doesn't have. Use getMIROperandIdx() / getSDOperandIdx() to convert them to
49/// operand indices. See AMDGPUBufferIntrinsic in IntrinsicsAMDGPU.td.
51 /// The position of absent arguments, (uint8_t)-1.
52 static constexpr uint8_t NoArg = 255;
53
54 unsigned Intr;
55 BufferIntrinsicKind Kind;
65 /// The data is converted according to the format in the resource (the
66 /// *_format intrinsics).
68 /// Loads to LDS that are asynchronous.
69 bool IsAsync;
70
71private:
72 static std::optional<unsigned> getArg(uint8_t Arg) {
73 if (Arg == NoArg)
74 return std::nullopt;
75 return Arg;
76 }
77
78public:
79 bool isStruct() const { return VIndexArg != NoArg; }
80 bool isTyped() const { return FormatArg != NoArg; }
81 /// Whether the data is converted according to the format in the resource.
82 bool isFormatFromRsrc() const { return IsFormatFromRsrc; }
83 /// Whether the data is converted according to a format, drawn either from
84 /// the resource descriptor (untyped/MUBUF _format instructions) or from an
85 /// explicit argument (tbuffer/MFBUF instructions).
86 bool isFormat() const { return IsFormatFromRsrc || isTyped(); }
87
88 /// The stored value for stores and atomics.
89 std::optional<unsigned> getVDataArg() const { return getArg(VDataArg); }
90 /// The comparison value for compare-and-swap atomics.
91 std::optional<unsigned> getCmpArg() const {
92 if (Kind != BufferKindAtomicCmpSwap)
93 return std::nullopt;
94 return VDataArg + 1;
95 }
96 /// The LDS destination of loads to LDS.
97 std::optional<unsigned> getLDSPtrArg() const {
98 if (Kind != BufferKindLoadToLDS)
99 return std::nullopt;
100 return RsrcArg + 1;
101 }
102 /// The access size of loads to LDS and prefetches.
103 std::optional<unsigned> getSizeArg() const { return getArg(SizeArg); }
104 std::optional<unsigned> getVIndexArg() const { return getArg(VIndexArg); }
105 /// The voffset, which scalar loads and prefetches don't have.
106 std::optional<unsigned> getVOffsetArg() const { return getArg(VOffsetArg); }
107 /// The soffset, which is the only offset of scalar loads and prefetches.
108 std::optional<unsigned> getSOffsetArg() const { return getArg(SOffsetArg); }
109 /// The main offset: the voffset if there is one, and the soffset otherwise.
110 unsigned getOffsetArg() const {
112 "buffer intrinsic without an offset");
114 }
115 /// The immediate offset of loads to LDS.
116 std::optional<unsigned> getImmOffsetArg() const {
117 return getArg(ImmOffsetArg);
118 }
119 std::optional<unsigned> getFormatArg() const { return getArg(FormatArg); }
120 /// The auxiliary (cache policy) argument.
121 std::optional<unsigned> getAuxArg() const { return getArg(AuxArg); }
122};
124
125/// Convert IR argument index \p Arg of the intrinsic called by \p MI, a
126/// G_INTRINSIC* instruction, into an operand index of \p MI.
127unsigned getMIROperandIdx(const MachineInstr &MI, unsigned Arg);
128
129/// Convert IR argument index \p Arg of an intrinsic into an operand index of
130/// the INTRINSIC_* SelectionDAG node calling it. \p HasChain is false for
131/// INTRINSIC_WO_CHAIN.
132constexpr unsigned getSDOperandIdx(unsigned Arg, bool HasChain = true) {
133 // The chain, if any, and the intrinsic ID precede the arguments.
134 return Arg + (HasChain ? 2 : 1);
135}
136
173
175getImageDimIntrinsicByBaseOpcode(unsigned BaseOpcode, unsigned Dim);
176
177} // end AMDGPU namespace
178} // End llvm namespace
179
180#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
IRTranslator LLVM IR MI
Representation of each machine instruction.
A description of a memory reference used in the backend.
const ImageDimIntrinsicInfo * getImageDimIntrinsicByBaseOpcode(unsigned BaseOpcode, unsigned Dim)
const BufferIntrinsicInfo * lookupBufferIntrinsic(unsigned Intr)
unsigned getMIROperandIdx(const MachineInstr &MI, unsigned Arg)
Convert IR argument index Arg of the intrinsic called by MI, a G_INTRINSIC* instruction,...
bool isUniformMMO(const MachineMemOperand *MMO)
Intrinsic::ID getIntrinsicID(const MachineInstr &I)
Return the intrinsic ID for opcodes with the G_AMDGPU_INTRIN_ prefix.
constexpr unsigned getSDOperandIdx(unsigned Arg, bool HasChain=true)
Convert IR argument index Arg of an intrinsic into an operand index of the INTRINSIC_* SelectionDAG n...
const ImageDimIntrinsicInfo * getImageDimIntrinsicInfo(unsigned Intr)
const RsrcIntrinsic * lookupRsrcIntrinsic(unsigned Intr)
This is an optimization pass for GlobalISel generic memory operations.
The argument layout of a buffer intrinsic.
bool IsAsync
Loads to LDS that are asynchronous.
bool isFormatFromRsrc() const
Whether the data is converted according to the format in the resource.
std::optional< unsigned > getSizeArg() const
The access size of loads to LDS and prefetches.
std::optional< unsigned > getImmOffsetArg() const
The immediate offset of loads to LDS.
bool isFormat() const
Whether the data is converted according to a format, drawn either from the resource descriptor (untyp...
std::optional< unsigned > getAuxArg() const
The auxiliary (cache policy) argument.
std::optional< unsigned > getCmpArg() const
The comparison value for compare-and-swap atomics.
std::optional< unsigned > getVDataArg() const
The stored value for stores and atomics.
bool IsFormatFromRsrc
The data is converted according to the format in the resource (the *_format intrinsics).
unsigned getOffsetArg() const
The main offset: the voffset if there is one, and the soffset otherwise.
std::optional< unsigned > getVOffsetArg() const
The voffset, which scalar loads and prefetches don't have.
std::optional< unsigned > getSOffsetArg() const
The soffset, which is the only offset of scalar loads and prefetches.
std::optional< unsigned > getLDSPtrArg() const
The LDS destination of loads to LDS.
std::optional< unsigned > getVIndexArg() const
std::optional< unsigned > getFormatArg() const
static constexpr uint8_t NoArg
The position of absent arguments, (uint8_t)-1.