36 ArgAlign =
DL.getABITypeAlign(Ty);
38 return std::pair(Ty, *ArgAlign);
44 "amdgpu-dump-hsa-metadata",
45 cl::desc(
"Dump AMDGPU HSA Metadata"));
47 "amdgpu-verify-hsa-metadata",
48 cl::desc(
"Verify AMDGPU HSA Metadata"));
50namespace AMDGPU::HSAMD {
57 errs() <<
"AMDGPU HSA Metadata:\n" << HSAMetadataString <<
'\n';
61 errs() <<
"AMDGPU HSA Metadata Parser Test: ";
65 if (!FromHSAMetadataString.
fromYAML(HSAMetadataString)) {
70 std::string ToHSAMetadataString;
72 FromHSAMetadataString.
toYAML(StrOS);
74 errs() << (HSAMetadataString == StrOS.
str() ?
"PASS" :
"FAIL") <<
'\n';
75 if (HSAMetadataString != ToHSAMetadataString) {
76 errs() <<
"Original input: " << HSAMetadataString <<
'\n'
77 <<
"Produced output: " << StrOS.
str() <<
'\n';
81std::optional<StringRef>
84 .Case(
"read_only",
StringRef(
"read_only"))
85 .Case(
"write_only",
StringRef(
"write_only"))
86 .Case(
"read_write",
StringRef(
"read_write"))
117 .
Case(
"image1d_t",
"image")
118 .
Case(
"image1d_array_t",
"image")
119 .
Case(
"image1d_buffer_t",
"image")
120 .
Case(
"image2d_t",
"image")
121 .
Case(
"image2d_array_t",
"image")
122 .
Case(
"image2d_array_depth_t",
"image")
123 .
Case(
"image2d_array_msaa_t",
"image")
124 .
Case(
"image2d_array_msaa_depth_t",
"image")
125 .
Case(
"image2d_depth_t",
"image")
126 .
Case(
"image2d_msaa_t",
"image")
127 .
Case(
"image2d_msaa_depth_t",
"image")
128 .
Case(
"image3d_t",
"image")
129 .
Case(
"sampler_t",
"sampler")
130 .
Case(
"queue_t",
"queue")
133 ?
"dynamic_shared_pointer"
166 auto VecTy = cast<FixedVectorType>(Ty);
167 auto ElTy = VecTy->getElementType();
168 auto NumElements = VecTy->getNumElements();
179 if (Node->getNumOperands() != 3)
182 for (
auto &
Op : Node->operands())
183 Dims.push_back(Dims.getDocument()->getNode(
184 uint64_t(mdconst::extract<ConstantInt>(
Op)->getZExtValue())));
202 auto Node =
Mod.getNamedMetadata(
"llvm.printf.fmts");
207 for (
auto *
Op : Node->operands())
209 Printf.push_back(Printf.getDocument()->getNode(
210 cast<MDString>(
Op->getOperand(0))->getString(),
true));
217 auto Node = Func.getParent()->getNamedMetadata(
"opencl.ocl.version");
218 if (!Node || !Node->getNumOperands())
220 auto Op0 = Node->getOperand(0);
221 if (Op0->getNumOperands() <= 1)
227 mdconst::extract<ConstantInt>(Op0->getOperand(0))->getZExtValue()));
229 mdconst::extract<ConstantInt>(Op0->getOperand(1))->getZExtValue()));
236 if (
auto Node = Func.getMetadata(
"reqd_work_group_size"))
238 if (
auto Node = Func.getMetadata(
"work_group_size_hint"))
240 if (
auto Node = Func.getMetadata(
"vec_type_hint")) {
243 cast<ValueAsMetadata>(Node->getOperand(0))->getType(),
244 mdconst::extract<ConstantInt>(Node->getOperand(1))->getZExtValue()),
247 if (Func.hasFnAttribute(
"runtime-handle")) {
249 Func.getFnAttribute(
"runtime-handle").getValueAsString().str(),
252 if (Func.hasFnAttribute(
"device-init"))
254 else if (Func.hasFnAttribute(
"device-fini"))
263 for (
auto &Arg : Func.args())
268 Kern[
".args"] = Args;
279 Node = Func->getMetadata(
"kernel_arg_name");
280 if (Node && ArgNo < Node->getNumOperands())
281 Name = cast<MDString>(Node->getOperand(ArgNo))->getString();
286 Node = Func->getMetadata(
"kernel_arg_type");
287 if (Node && ArgNo < Node->getNumOperands())
288 TypeName = cast<MDString>(Node->getOperand(ArgNo))->getString();
291 Node = Func->getMetadata(
"kernel_arg_base_type");
292 if (Node && ArgNo < Node->getNumOperands())
293 BaseTypeName = cast<MDString>(Node->getOperand(ArgNo))->getString();
299 ActAccQual =
"read_only";
301 ActAccQual =
"write_only";
305 Node = Func->getMetadata(
"kernel_arg_access_qual");
306 if (Node && ArgNo < Node->getNumOperands())
307 AccQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
310 Node = Func->getMetadata(
"kernel_arg_type_qual");
311 if (Node && ArgNo < Node->getNumOperands())
312 TypeQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
320 if (
auto PtrTy = dyn_cast<PointerType>(Ty)) {
332 PointeeAlign,
Name, TypeName, BaseTypeName, ActAccQual,
341 auto Arg = Args.getDocument()->getMapNode();
344 Arg[
".name"] = Arg.getDocument()->getNode(
Name,
true);
345 if (!TypeName.empty())
346 Arg[
".type_name"] = Arg.getDocument()->getNode(TypeName,
true);
347 auto Size =
DL.getTypeAllocSize(Ty);
348 Arg[
".size"] = Arg.getDocument()->getNode(
Size);
350 Arg[
".offset"] = Arg.getDocument()->getNode(
Offset);
352 Arg[
".value_kind"] = Arg.getDocument()->getNode(
ValueKind,
true);
354 Arg[
".pointee_align"] = Arg.getDocument()->getNode(PointeeAlign->value());
356 if (
auto PtrTy = dyn_cast<PointerType>(Ty))
360 Arg[
".address_space"] = Arg.getDocument()->getNode(*Qualifier,
364 Arg[
".access"] = Arg.getDocument()->getNode(*AQ,
true);
367 Arg[
".actual_access"] = Arg.getDocument()->getNode(*AAQ,
true);
370 TypeQual.
split(SplitTypeQuals,
" ", -1,
false);
373 Arg[
".is_const"] = Arg.getDocument()->getNode(
true);
374 else if (Key ==
"restrict")
375 Arg[
".is_restrict"] = Arg.getDocument()->getNode(
true);
376 else if (Key ==
"volatile")
377 Arg[
".is_volatile"] = Arg.getDocument()->getNode(
true);
378 else if (Key ==
"pipe")
379 Arg[
".is_pipe"] = Arg.getDocument()->getNode(
true);
390 unsigned HiddenArgNumBytes = ST.getImplicitArgNumBytes(Func);
391 if (!HiddenArgNumBytes)
394 const Module *M = Func.getParent();
395 auto &
DL = M->getDataLayout();
400 if (HiddenArgNumBytes >= 8)
403 if (HiddenArgNumBytes >= 16)
406 if (HiddenArgNumBytes >= 24)
413 if (HiddenArgNumBytes >= 32) {
417 if (M->getNamedMetadata(
"llvm.printf.fmts"))
420 else if (!Func.hasFnAttribute(
"amdgpu-no-hostcall-ptr"))
429 if (HiddenArgNumBytes >= 40) {
430 if (!Func.hasFnAttribute(
"amdgpu-no-default-queue")) {
438 if (HiddenArgNumBytes >= 48) {
439 if (!Func.hasFnAttribute(
"amdgpu-no-completion-action")) {
448 if (HiddenArgNumBytes >= 56) {
449 if (!Func.hasFnAttribute(
"amdgpu-no-multigrid-sync-arg")) {
461 unsigned CodeObjectVersion)
const {
468 Align MaxKernArgAlign;
469 Kern[
".kernarg_segment_size"] = Kern.getDocument()->getNode(
471 Kern[
".group_segment_fixed_size"] =
472 Kern.getDocument()->getNode(ProgramInfo.
LDSSize);
473 DelayedExprs->assignDocNode(Kern[
".private_segment_fixed_size"],
476 DelayedExprs->assignDocNode(Kern[
".uses_dynamic_stack"],
482 Kern[
".workgroup_processor_mode"] =
483 Kern.getDocument()->getNode(ProgramInfo.
WgpMode);
486 Kern[
".kernarg_segment_align"] =
487 Kern.getDocument()->getNode(std::max(
Align(4), MaxKernArgAlign).
value());
488 Kern[
".wavefront_size"] =
501 Kern[
".max_flat_workgroup_size"] =
502 Kern.getDocument()->getNode(MFI.getMaxFlatWorkGroupSize());
503 unsigned NumWGX = MFI.getMaxNumWorkGroupsX();
504 unsigned NumWGY = MFI.getMaxNumWorkGroupsY();
505 unsigned NumWGZ = MFI.getMaxNumWorkGroupsZ();
506 if (NumWGX != 0 && NumWGY != 0 && NumWGZ != 0) {
507 Kern[
".max_num_workgroups_x"] = Kern.getDocument()->getNode(NumWGX);
508 Kern[
".max_num_workgroups_y"] = Kern.getDocument()->getNode(NumWGY);
509 Kern[
".max_num_workgroups_z"] = Kern.getDocument()->getNode(NumWGZ);
511 Kern[
".sgpr_spill_count"] =
512 Kern.getDocument()->getNode(MFI.getNumSpilledSGPRs());
513 Kern[
".vgpr_spill_count"] =
514 Kern.getDocument()->getNode(MFI.getNumSpilledVGPRs());
535 std::string HSAMetadataString;
552 auto CodeObjectVersion =
562 (
Twine(Func.getName()) +
Twine(
".kd")).str(),
true);
568 Kernels.push_back(Kern);
588 if (ST.getImplicitArgNumBytes(Func) == 0)
591 const Module *M = Func.getParent();
592 auto &
DL = M->getDataLayout();
627 if (M->getNamedMetadata(
"llvm.printf.fmts")) {
634 if (!Func.hasFnAttribute(
"amdgpu-no-hostcall-ptr")) {
641 if (!Func.hasFnAttribute(
"amdgpu-no-multigrid-sync-arg")) {
648 if (!Func.hasFnAttribute(
"amdgpu-no-heap-ptr"))
653 if (!Func.hasFnAttribute(
"amdgpu-no-default-queue")) {
660 if (!Func.hasFnAttribute(
"amdgpu-no-completion-action")) {
679 if (!ST.hasApertureRegs()) {
694 if (Func.getFnAttribute(
"uniform-work-group-size").getValueAsBool())
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Given that RA is a live value
AMD GCN specific subclass of TargetSubtarget.
Module.h This file contains the declarations for the Module class.
Defines struct to track resource usage and hardware flags for kernels and entry functions.
bool isDynamicLDSUsed() const
unsigned getKernArgSegmentSize(const Function &F, Align &MaxAlign) const
unsigned getWavefrontSize() const
virtual bool EmitHSAMetadata(msgpack::Document &HSAMetadata, bool Strict)
Emit HSA Metadata.
std::string toString() const
This class represents an incoming formal argument to a Function.
Type * getParamByRefType() const
If this is a byref argument, return its type.
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
bool hasByRefAttr() const
Return true if this argument has the byref attribute.
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
bool hasAttribute(Attribute::AttrKind Kind) const
Check if an argument has a given attribute.
const Function * getParent() const
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
MaybeAlign getParamAlign() const
If this is a byval or inalloca argument, return its alignment.
This class represents an Operation in the Expression.
uint64_t getNumOperands() const
A parsed version of the target data layout string in and methods for querying it.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
A Module instance is used to store all the information related to an LLVM module.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
GCNUserSGPRUsageInfo & getUserSGPRInfo()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getIntegerBitWidth() const
bool isPointerTy() const
True if this is an instance of PointerType.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ HalfTyID
16-bit floating point type
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ DoubleTyID
64-bit floating point type
static IntegerType * getInt16Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
TypeID getTypeID() const
Return the type id for the type.
Type * getType() const
All values are typed, get the type of this value.
StringRef getName() const
Return a constant reference to the value's name.
A DocNode that is an array.
ArrayDocNode & getArray(bool Convert=false)
Get an ArrayDocNode for an array node.
Document * getDocument() const
Simple in-memory representation of a document of msgpack objects with ability to find and create arra...
DocNode getNode()
Create a nil node associated with this Document.
ArrayDocNode getArrayNode()
Create an empty Array node associated with this Document.
void toYAML(raw_ostream &OS)
Convert MsgPack Document to YAML text.
bool fromYAML(StringRef S)
Read YAML text into the MsgPack document. Returns false on failure.
A raw_ostream that writes to an std::string.
std::string & str()
Returns the string's reference.
unsigned LanguageVersion(SourceLanguage L)
@ REGION_ADDRESS
Address space for region memory. (GDS)
@ LOCAL_ADDRESS
Address space for local memory.
@ CONSTANT_ADDRESS
Address space for constant memory (VTX2).
@ FLAT_ADDRESS
Address space for flat memory.
@ GLOBAL_ADDRESS
Address space for global memory (RAT0, VTX0).
@ PRIVATE_ADDRESS
Address space for private memory.
constexpr uint32_t VersionMajorV5
HSA metadata major version for code object V5.
constexpr uint32_t VersionMinorV4
HSA metadata minor version for code object V4.
constexpr uint32_t VersionMinorV5
HSA metadata minor version for code object V5.
constexpr uint32_t VersionMinorV6
HSA metadata minor version for code object V6.
constexpr uint32_t VersionMajorV6
HSA metadata major version for code object V6.
constexpr uint32_t VersionMajorV4
HSA metadata major version for code object V4.
unsigned getAMDHSACodeObjectVersion(const Module &M)
@ AMDGPU_KERNEL
Used for AMDGPU code object kernels.
@ SPIR_KERNEL
Used for SPIR kernel functions.
This is an optimization pass for GlobalISel generic memory operations.
static cl::opt< bool > VerifyHSAMetadata("amdgpu-verify-hsa-metadata", cl::desc("Verify AMDGPU HSA Metadata"))
static cl::opt< bool > DumpHSAMetadata("amdgpu-dump-hsa-metadata", cl::desc("Dump AMDGPU HSA Metadata"))
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
StringRef getTypeName()
We provide a function which tries to compute the (demangled) name of a type statically.
@ Mod
The access may modify the value stored in memory.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
constexpr unsigned BitWidth
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Track resource usage for kernels / entry functions.
const MCExpr * NumAccVGPR
const MCExpr * DynamicCallStack
const MCExpr * ScratchSize