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()));
230 Kern[
".language_version"] = LanguageVersion;
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()) {
264 if (Arg.hasAttribute(
"amdgpu-hidden-argument"))
272 Kern[
".args"] = Args;
283 Node = Func->getMetadata(
"kernel_arg_name");
284 if (Node && ArgNo < Node->getNumOperands())
285 Name = cast<MDString>(Node->getOperand(ArgNo))->getString();
290 Node = Func->getMetadata(
"kernel_arg_type");
291 if (Node && ArgNo < Node->getNumOperands())
292 TypeName = cast<MDString>(Node->getOperand(ArgNo))->getString();
295 Node = Func->getMetadata(
"kernel_arg_base_type");
296 if (Node && ArgNo < Node->getNumOperands())
297 BaseTypeName = cast<MDString>(Node->getOperand(ArgNo))->getString();
303 ActAccQual =
"read_only";
305 ActAccQual =
"write_only";
309 Node = Func->getMetadata(
"kernel_arg_access_qual");
310 if (Node && ArgNo < Node->getNumOperands())
311 AccQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
314 Node = Func->getMetadata(
"kernel_arg_type_qual");
315 if (Node && ArgNo < Node->getNumOperands())
316 TypeQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
324 if (
auto *PtrTy = dyn_cast<PointerType>(Ty)) {
336 PointeeAlign,
Name, TypeName, BaseTypeName, ActAccQual,
345 auto Arg = Args.getDocument()->getMapNode();
348 Arg[
".name"] = Arg.getDocument()->getNode(
Name,
true);
349 if (!TypeName.empty())
350 Arg[
".type_name"] = Arg.getDocument()->getNode(TypeName,
true);
351 auto Size =
DL.getTypeAllocSize(Ty);
352 Arg[
".size"] = Arg.getDocument()->getNode(
Size);
354 Arg[
".offset"] = Arg.getDocument()->getNode(
Offset);
356 Arg[
".value_kind"] = Arg.getDocument()->getNode(
ValueKind,
true);
358 Arg[
".pointee_align"] = Arg.getDocument()->getNode(PointeeAlign->value());
360 if (
auto *PtrTy = dyn_cast<PointerType>(Ty))
364 Arg[
".address_space"] = Arg.getDocument()->getNode(*Qualifier,
368 Arg[
".access"] = Arg.getDocument()->getNode(*AQ,
true);
371 Arg[
".actual_access"] = Arg.getDocument()->getNode(*AAQ,
true);
374 TypeQual.
split(SplitTypeQuals,
" ", -1,
false);
377 Arg[
".is_const"] = Arg.getDocument()->getNode(
true);
378 else if (Key ==
"restrict")
379 Arg[
".is_restrict"] = Arg.getDocument()->getNode(
true);
380 else if (Key ==
"volatile")
381 Arg[
".is_volatile"] = Arg.getDocument()->getNode(
true);
382 else if (Key ==
"pipe")
383 Arg[
".is_pipe"] = Arg.getDocument()->getNode(
true);
394 unsigned HiddenArgNumBytes = ST.getImplicitArgNumBytes(Func);
395 if (!HiddenArgNumBytes)
398 const Module *M = Func.getParent();
399 auto &
DL = M->getDataLayout();
404 if (HiddenArgNumBytes >= 8)
407 if (HiddenArgNumBytes >= 16)
410 if (HiddenArgNumBytes >= 24)
417 if (HiddenArgNumBytes >= 32) {
421 if (M->getNamedMetadata(
"llvm.printf.fmts"))
424 else if (!Func.hasFnAttribute(
"amdgpu-no-hostcall-ptr"))
433 if (HiddenArgNumBytes >= 40) {
434 if (!Func.hasFnAttribute(
"amdgpu-no-default-queue")) {
442 if (HiddenArgNumBytes >= 48) {
443 if (!Func.hasFnAttribute(
"amdgpu-no-completion-action")) {
452 if (HiddenArgNumBytes >= 56) {
453 if (!Func.hasFnAttribute(
"amdgpu-no-multigrid-sync-arg")) {
465 unsigned CodeObjectVersion)
const {
472 Align MaxKernArgAlign;
473 Kern[
".kernarg_segment_size"] = Kern.getDocument()->getNode(
475 Kern[
".group_segment_fixed_size"] =
476 Kern.getDocument()->getNode(ProgramInfo.
LDSSize);
477 DelayedExprs->assignDocNode(Kern[
".private_segment_fixed_size"],
480 DelayedExprs->assignDocNode(Kern[
".uses_dynamic_stack"],
486 Kern[
".workgroup_processor_mode"] =
487 Kern.getDocument()->getNode(ProgramInfo.
WgpMode);
490 Kern[
".kernarg_segment_align"] =
491 Kern.getDocument()->getNode(std::max(
Align(4), MaxKernArgAlign).
value());
492 Kern[
".wavefront_size"] =
505 Kern[
".max_flat_workgroup_size"] =
506 Kern.getDocument()->getNode(MFI.getMaxFlatWorkGroupSize());
508 uint32_t NumWGY = MFI.getMaxNumWorkGroupsY();
509 uint32_t NumWGZ = MFI.getMaxNumWorkGroupsZ();
510 uint32_t NumWGX = MFI.getMaxNumWorkGroupsX();
513 if (NumWGX != std::numeric_limits<uint32_t>::max() && NumWGX != 0)
514 Kern[
".max_num_workgroups_x"] = Kern.getDocument()->getNode(NumWGX);
516 if (NumWGY != std::numeric_limits<uint32_t>::max() && NumWGY != 0)
517 Kern[
".max_num_workgroups_y"] = Kern.getDocument()->getNode(NumWGY);
519 if (NumWGZ != std::numeric_limits<uint32_t>::max() && NumWGZ != 0)
520 Kern[
".max_num_workgroups_z"] = Kern.getDocument()->getNode(NumWGZ);
522 Kern[
".sgpr_spill_count"] =
523 Kern.getDocument()->getNode(MFI.getNumSpilledSGPRs());
524 Kern[
".vgpr_spill_count"] =
525 Kern.getDocument()->getNode(MFI.getNumSpilledVGPRs());
546 std::string HSAMetadataString;
563 auto CodeObjectVersion =
573 (
Twine(Func.getName()) +
Twine(
".kd")).str(),
true);
579 Kernels.push_back(Kern);
599 if (ST.getImplicitArgNumBytes(Func) == 0)
602 const Module *M = Func.getParent();
603 auto &
DL = M->getDataLayout();
638 if (M->getNamedMetadata(
"llvm.printf.fmts")) {
645 if (!Func.hasFnAttribute(
"amdgpu-no-hostcall-ptr")) {
652 if (!Func.hasFnAttribute(
"amdgpu-no-multigrid-sync-arg")) {
659 if (!Func.hasFnAttribute(
"amdgpu-no-heap-ptr"))
664 if (!Func.hasFnAttribute(
"amdgpu-no-default-queue")) {
671 if (!Func.hasFnAttribute(
"amdgpu-no-completion-action")) {
690 if (!ST.hasApertureRegs()) {
705 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.
@ 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