31 "amdgpu-dump-hsa-metadata",
32 cl::desc(
"Dump AMDGPU HSA Metadata"));
34 "amdgpu-verify-hsa-metadata",
35 cl::desc(
"Verify AMDGPU HSA Metadata"));
43 void MetadataStreamerV2::dump(StringRef HSAMetadataString)
const {
44 errs() <<
"AMDGPU HSA Metadata:\n" << HSAMetadataString <<
'\n';
47 void MetadataStreamerV2::verify(StringRef HSAMetadataString)
const {
48 errs() <<
"AMDGPU HSA Metadata Parser Test: ";
51 if (
fromString(HSAMetadataString, FromHSAMetadataString)) {
56 std::string ToHSAMetadataString;
57 if (
toString(FromHSAMetadataString, ToHSAMetadataString)) {
62 errs() << (HSAMetadataString == ToHSAMetadataString ?
"PASS" :
"FAIL")
64 if (HSAMetadataString != ToHSAMetadataString) {
65 errs() <<
"Original input: " << HSAMetadataString <<
'\n' 66 <<
"Produced output: " << ToHSAMetadataString <<
'\n';
71 MetadataStreamerV2::getAccessQualifier(StringRef
AccQual)
const {
75 return StringSwitch<AccessQualifier>(
AccQual)
83 MetadataStreamerV2::getAddressSpaceQualifier(
85 switch (AddressSpace) {
103 ValueKind MetadataStreamerV2::getValueKind(Type *Ty, StringRef TypeQual,
104 StringRef BaseTypeName)
const {
108 return StringSwitch<ValueKind>(BaseTypeName)
123 .Default(isa<PointerType>(Ty) ?
124 (Ty->getPointerAddressSpace() ==
132 switch (Ty->getTypeID()) {
134 auto Signed = !TypeName.startswith(
"u");
135 switch (Ty->getIntegerBitWidth()) {
155 return getValueType(Ty->getPointerElementType(),
TypeName);
157 return getValueType(Ty->getVectorElementType(),
TypeName);
163 std::string MetadataStreamerV2::getTypeName(Type *Ty,
bool Signed)
const {
164 switch (Ty->getTypeID()) {
167 return (Twine(
'u') + getTypeName(Ty,
true)).str();
169 auto BitWidth = Ty->getIntegerBitWidth();
180 return (Twine(
'i') + Twine(BitWidth)).str();
190 auto VecTy = cast<VectorType>(Ty);
191 auto ElTy = VecTy->getElementType();
192 auto NumElements = VecTy->getVectorNumElements();
193 return (Twine(getTypeName(ElTy, Signed)) + Twine(NumElements)).str();
200 std::vector<uint32_t>
201 MetadataStreamerV2::getWorkGroupDimensions(MDNode *Node)
const {
202 std::vector<uint32_t> Dims;
203 if (Node->getNumOperands() != 3)
206 for (
auto &
Op : Node->operands())
207 Dims.push_back(mdconst::extract<ConstantInt>(
Op)->getZExtValue());
212 MetadataStreamerV2::getHSACodeProps(
const MachineFunction &MF,
213 const SIProgramInfo &ProgramInfo)
const {
214 const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
215 const SIMachineFunctionInfo &MFI = *MF.getInfo<SIMachineFunctionInfo>();
222 unsigned MaxKernArgAlign;
223 HSACodeProps.mKernargSegmentSize = STM.getKernArgSegmentSize(F,
225 HSACodeProps.mGroupSegmentFixedSize = ProgramInfo.LDSSize;
226 HSACodeProps.mPrivateSegmentFixedSize = ProgramInfo.ScratchSize;
227 HSACodeProps.mKernargSegmentAlign =
std::max(MaxKernArgAlign, 4u);
228 HSACodeProps.mWavefrontSize = STM.getWavefrontSize();
229 HSACodeProps.mNumSGPRs = ProgramInfo.NumSGPR;
230 HSACodeProps.mNumVGPRs = ProgramInfo.NumVGPR;
231 HSACodeProps.mMaxFlatWorkGroupSize = MFI.getMaxFlatWorkGroupSize();
232 HSACodeProps.mIsDynamicCallStack = ProgramInfo.DynamicCallStack;
233 HSACodeProps.mIsXNACKEnabled = STM.isXNACKEnabled();
234 HSACodeProps.mNumSpilledSGPRs = MFI.getNumSpilledSGPRs();
235 HSACodeProps.mNumSpilledVGPRs = MFI.getNumSpilledVGPRs();
241 MetadataStreamerV2::getHSADebugProps(
const MachineFunction &MF,
242 const SIProgramInfo &ProgramInfo)
const {
243 const GCNSubtarget &STM = MF.getSubtarget<GCNSubtarget>();
246 if (!STM.debuggerSupported())
247 return HSADebugProps;
249 HSADebugProps.mDebuggerABIVersion.push_back(1);
250 HSADebugProps.mDebuggerABIVersion.push_back(0);
252 if (STM.debuggerEmitPrologue()) {
253 HSADebugProps.mPrivateSegmentBufferSGPR =
254 ProgramInfo.DebuggerPrivateSegmentBufferSGPR;
255 HSADebugProps.mWavefrontPrivateSegmentOffsetSGPR =
256 ProgramInfo.DebuggerWavefrontPrivateSegmentOffsetSGPR;
259 return HSADebugProps;
262 void MetadataStreamerV2::emitVersion() {
269 void MetadataStreamerV2::emitPrintf(
const Module &Mod) {
272 auto Node = Mod.getNamedMetadata(
"llvm.printf.fmts");
276 for (
auto Op : Node->operands())
277 if (
Op->getNumOperands())
278 Printf.push_back(cast<MDString>(
Op->getOperand(0))->getString());
281 void MetadataStreamerV2::emitKernelLanguage(
const Function &Func) {
285 auto Node = Func.getParent()->getNamedMetadata(
"opencl.ocl.version");
286 if (!Node || !Node->getNumOperands())
288 auto Op0 = Node->getOperand(0);
289 if (Op0->getNumOperands() <= 1)
292 Kernel.mLanguage =
"OpenCL C";
293 Kernel.mLanguageVersion.push_back(
294 mdconst::extract<ConstantInt>(Op0->getOperand(0))->getZExtValue());
295 Kernel.mLanguageVersion.push_back(
296 mdconst::extract<ConstantInt>(Op0->getOperand(1))->getZExtValue());
299 void MetadataStreamerV2::emitKernelAttrs(
const Function &Func) {
302 if (
auto Node = Func.getMetadata(
"reqd_work_group_size"))
303 Attrs.mReqdWorkGroupSize = getWorkGroupDimensions(Node);
304 if (
auto Node = Func.getMetadata(
"work_group_size_hint"))
305 Attrs.mWorkGroupSizeHint = getWorkGroupDimensions(Node);
306 if (
auto Node = Func.getMetadata(
"vec_type_hint")) {
307 Attrs.mVecTypeHint = getTypeName(
308 cast<ValueAsMetadata>(Node->getOperand(0))->
getType(),
309 mdconst::extract<ConstantInt>(Node->getOperand(1))->getZExtValue());
311 if (Func.hasFnAttribute(
"runtime-handle")) {
312 Attrs.mRuntimeHandle =
313 Func.getFnAttribute(
"runtime-handle").getValueAsString().str();
317 void MetadataStreamerV2::emitKernelArgs(
const Function &Func) {
318 for (
auto &
Arg : Func.args())
321 emitHiddenKernelArgs(Func);
324 void MetadataStreamerV2::emitKernelArg(
const Argument &
Arg) {
325 auto Func = Arg.getParent();
326 auto ArgNo = Arg.getArgNo();
330 Node = Func->getMetadata(
"kernel_arg_name");
331 if (Node && ArgNo < Node->getNumOperands())
332 Name = cast<MDString>(Node->getOperand(ArgNo))->getString();
333 else if (Arg.hasName())
334 Name = Arg.getName();
337 Node = Func->getMetadata(
"kernel_arg_type");
338 if (Node && ArgNo < Node->getNumOperands())
339 TypeName = cast<MDString>(Node->getOperand(ArgNo))->getString();
341 StringRef BaseTypeName;
342 Node = Func->getMetadata(
"kernel_arg_base_type");
343 if (Node && ArgNo < Node->getNumOperands())
344 BaseTypeName = cast<MDString>(Node->getOperand(ArgNo))->getString();
347 if (Arg.getType()->isPointerTy() && Arg.onlyReadsMemory() &&
348 Arg.hasNoAliasAttr()) {
349 AccQual =
"read_only";
351 Node = Func->getMetadata(
"kernel_arg_access_qual");
352 if (Node && ArgNo < Node->getNumOperands())
353 AccQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
357 Node = Func->getMetadata(
"kernel_arg_type_qual");
358 if (Node && ArgNo < Node->getNumOperands())
359 TypeQual = cast<MDString>(Node->getOperand(ArgNo))->getString();
361 Type *Ty = Arg.getType();
362 const DataLayout &DL = Func->getParent()->getDataLayout();
365 if (
auto PtrTy = dyn_cast<PointerType>(Ty)) {
367 PointeeAlign = Arg.getParamAlignment();
368 if (PointeeAlign == 0)
369 PointeeAlign = DL.getABITypeAlignment(PtrTy->getElementType());
373 emitKernelArg(DL, Ty, getValueKind(Arg.getType(), TypeQual, BaseTypeName),
374 PointeeAlign, Name, TypeName, BaseTypeName, AccQual, TypeQual);
377 void MetadataStreamerV2::emitKernelArg(
const DataLayout &DL, Type *Ty,
379 unsigned PointeeAlign, StringRef Name,
381 StringRef BaseTypeName,
382 StringRef AccQual, StringRef TypeQual) {
384 auto &Arg = HSAMetadata.
mKernels.back().mArgs.back();
388 Arg.mSize = DL.getTypeAllocSize(Ty);
389 Arg.mAlign = DL.getABITypeAlignment(Ty);
391 Arg.mValueType = getValueType(Ty, BaseTypeName);
394 if (
auto PtrTy = dyn_cast<PointerType>(Ty))
395 Arg.mAddrSpaceQual = getAddressSpaceQualifier(PtrTy->getAddressSpace());
397 Arg.mAccQual = getAccessQualifier(AccQual);
401 SmallVector<StringRef, 1> SplitTypeQuals;
402 TypeQual.split(SplitTypeQuals,
" ", -1,
false);
403 for (StringRef
Key : SplitTypeQuals) {
404 auto P = StringSwitch<bool*>(
Key)
405 .Case(
"const", &Arg.mIsConst)
406 .Case(
"restrict", &Arg.mIsRestrict)
407 .Case(
"volatile", &Arg.mIsVolatile)
408 .Case(
"pipe", &Arg.mIsPipe)
415 void MetadataStreamerV2::emitHiddenKernelArgs(
const Function &Func) {
416 int HiddenArgNumBytes =
419 if (!HiddenArgNumBytes)
422 auto &DL = Func.getParent()->getDataLayout();
425 if (HiddenArgNumBytes >= 8)
427 if (HiddenArgNumBytes >= 16)
429 if (HiddenArgNumBytes >= 24)
437 if (HiddenArgNumBytes >= 32) {
438 if (Func.getParent()->getNamedMetadata(
"llvm.printf.fmts"))
446 if (HiddenArgNumBytes >= 48) {
447 if (Func.hasFnAttribute(
"calls-enqueue-kernel")) {
467 std::string HSAMetadataString;
468 if (
toString(HSAMetadata, HSAMetadataString))
472 dump(HSAMetadataString);
474 verify(HSAMetadataString);
483 auto CodeProps = getHSACodeProps(MF, ProgramInfo);
484 auto DebugProps = getHSADebugProps(MF, ProgramInfo);
489 Kernel.mName = Func.getName();
491 emitKernelLanguage(Func);
492 emitKernelAttrs(Func);
493 emitKernelArgs(Func);
502 void MetadataStreamerV3::dump(
StringRef HSAMetadataString)
const {
503 errs() <<
"AMDGPU HSA Metadata:\n" << HSAMetadataString <<
'\n';
506 void MetadataStreamerV3::verify(
StringRef HSAMetadataString)
const {
507 errs() <<
"AMDGPU HSA Metadata Parser Test: ";
509 std::shared_ptr<msgpack::Node> FromHSAMetadataString =
510 std::make_shared<msgpack::MapNode>();
512 yaml::Input YIn(HSAMetadataString);
513 YIn >> FromHSAMetadataString;
519 std::string ToHSAMetadataString;
521 yaml::Output YOut(StrOS);
522 YOut << FromHSAMetadataString;
524 errs() << (HSAMetadataString == StrOS.
str() ?
"PASS" :
"FAIL") <<
'\n';
525 if (HSAMetadataString != ToHSAMetadataString) {
526 errs() <<
"Original input: " << HSAMetadataString <<
'\n' 527 <<
"Produced output: " << StrOS.
str() <<
'\n';
532 MetadataStreamerV3::getAccessQualifier(
StringRef AccQual)
const {
534 .Case(
"read_only",
StringRef(
"read_only"))
535 .Case(
"write_only",
StringRef(
"write_only"))
536 .Case(
"read_write",
StringRef(
"read_write"))
541 MetadataStreamerV3::getAddressSpaceQualifier(
unsigned AddressSpace)
const {
542 switch (AddressSpace) {
566 .Case(
"image1d_t",
"image")
567 .
Case(
"image1d_array_t",
"image")
568 .
Case(
"image1d_buffer_t",
"image")
569 .
Case(
"image2d_t",
"image")
570 .
Case(
"image2d_array_t",
"image")
571 .
Case(
"image2d_array_depth_t",
"image")
572 .
Case(
"image2d_array_msaa_t",
"image")
573 .
Case(
"image2d_array_msaa_depth_t",
"image")
574 .
Case(
"image2d_depth_t",
"image")
575 .
Case(
"image2d_msaa_t",
"image")
576 .
Case(
"image2d_msaa_depth_t",
"image")
577 .
Case(
"image3d_t",
"image")
578 .
Case(
"sampler_t",
"sampler")
579 .
Case(
"queue_t",
"queue")
582 ?
"dynamic_shared_pointer" 593 return Signed ?
"i8" :
"u8";
595 return Signed ?
"i16" :
"u16";
597 return Signed ?
"i32" :
"u32";
599 return Signed ?
"i64" :
"u64";
619 std::string MetadataStreamerV3::getTypeName(
Type *Ty,
bool Signed)
const {
623 return (
Twine(
'u') + getTypeName(Ty,
true)).str();
646 auto VecTy = cast<VectorType>(Ty);
647 auto ElTy = VecTy->getElementType();
648 auto NumElements = VecTy->getVectorNumElements();
649 return (
Twine(getTypeName(ElTy, Signed)) +
Twine(NumElements)).str();
656 std::shared_ptr<msgpack::ArrayNode>
657 MetadataStreamerV3::getWorkGroupDimensions(
MDNode *Node)
const {
658 auto Dims = std::make_shared<msgpack::ArrayNode>();
663 Dims->push_back(std::make_shared<msgpack::ScalarNode>(
664 mdconst::extract<ConstantInt>(
Op)->getZExtValue()));
668 void MetadataStreamerV3::emitVersion() {
669 auto Version = std::make_shared<msgpack::ArrayNode>();
672 getRootMetadata(
"amdhsa.version") = std::move(
Version);
675 void MetadataStreamerV3::emitPrintf(
const Module &Mod) {
680 auto Printf = std::make_shared<msgpack::ArrayNode>();
682 if (
Op->getNumOperands())
683 Printf->push_back(std::make_shared<msgpack::ScalarNode>(
684 cast<MDString>(
Op->getOperand(0))->getString()));
685 getRootMetadata(
"amdhsa.printf") = std::move(
Printf);
688 void MetadataStreamerV3::emitKernelLanguage(
const Function &Func,
695 if (Op0->getNumOperands() <= 1)
698 Kern[
".language"] = std::make_shared<msgpack::ScalarNode>(
"OpenCL C");
700 LanguageVersion->push_back(std::make_shared<msgpack::ScalarNode>(
701 mdconst::extract<ConstantInt>(Op0->getOperand(0))->getZExtValue()));
702 LanguageVersion->push_back(std::make_shared<msgpack::ScalarNode>(
703 mdconst::extract<ConstantInt>(Op0->getOperand(1))->getZExtValue()));
704 Kern[
".language_version"] = std::move(LanguageVersion);
707 void MetadataStreamerV3::emitKernelAttrs(
const Function &Func,
710 if (
auto Node = Func.
getMetadata(
"reqd_work_group_size"))
711 Kern[
".reqd_workgroup_size"] = getWorkGroupDimensions(Node);
712 if (
auto Node = Func.
getMetadata(
"work_group_size_hint"))
713 Kern[
".workgroup_size_hint"] = getWorkGroupDimensions(Node);
714 if (
auto Node = Func.
getMetadata(
"vec_type_hint")) {
715 Kern[
".vec_type_hint"] = std::make_shared<msgpack::ScalarNode>(getTypeName(
717 mdconst::extract<ConstantInt>(Node->
getOperand(1))->getZExtValue()));
720 Kern[
".device_enqueue_symbol"] = std::make_shared<msgpack::ScalarNode>(
725 void MetadataStreamerV3::emitKernelArgs(
const Function &Func,
728 auto Args = std::make_shared<msgpack::ArrayNode>();
729 for (
auto &Arg : Func.
args())
730 emitKernelArg(Arg, Offset, *
Args);
732 emitHiddenKernelArgs(Func, Offset, *
Args);
739 emitKernelArg(DL, Int64Ty,
"hidden_global_offset_x", Offset, *
Args);
740 emitKernelArg(DL, Int64Ty,
"hidden_global_offset_y", Offset, *
Args);
741 emitKernelArg(DL, Int64Ty,
"hidden_global_offset_z", Offset, *
Args);
749 emitKernelArg(DL, Int8PtrTy,
"hidden_printf_buffer", Offset, *
Args);
751 emitKernelArg(DL, Int8PtrTy,
"hidden_none", Offset, *
Args);
756 emitKernelArg(DL, Int8PtrTy,
"hidden_default_queue", Offset, *
Args);
757 emitKernelArg(DL, Int8PtrTy,
"hidden_completion_action", Offset, *
Args);
759 emitKernelArg(DL, Int8PtrTy,
"hidden_none", Offset, *
Args);
760 emitKernelArg(DL, Int8PtrTy,
"hidden_none", Offset, *
Args);
764 Kern[
".args"] = std::move(
Args);
767 void MetadataStreamerV3::emitKernelArg(
const Argument &Arg,
unsigned &
Offset,
775 if (Node && ArgNo < Node->getNumOperands())
776 Name = cast<MDString>(Node->
getOperand(ArgNo))->getString();
782 if (Node && ArgNo < Node->getNumOperands())
783 TypeName = cast<MDString>(Node->
getOperand(ArgNo))->getString();
787 if (Node && ArgNo < Node->getNumOperands())
788 BaseTypeName = cast<MDString>(Node->
getOperand(ArgNo))->getString();
793 AccQual =
"read_only";
795 Node = Func->
getMetadata(
"kernel_arg_access_qual");
796 if (Node && ArgNo < Node->getNumOperands())
797 AccQual = cast<MDString>(Node->
getOperand(ArgNo))->getString();
802 if (Node && ArgNo < Node->getNumOperands())
803 TypeQual = cast<MDString>(Node->
getOperand(ArgNo))->getString();
808 unsigned PointeeAlign = 0;
809 if (
auto PtrTy = dyn_cast<PointerType>(Ty)) {
812 if (PointeeAlign == 0)
818 getValueKind(Arg.
getType(), TypeQual, BaseTypeName), Offset,
819 Args, PointeeAlign, Name, TypeName, BaseTypeName, AccQual,
823 void MetadataStreamerV3::emitKernelArg(
const DataLayout &DL,
Type *Ty,
830 auto ArgPtr = std::make_shared<msgpack::MapNode>();
834 Arg[
".name"] = std::make_shared<msgpack::ScalarNode>(Name);
835 if (!TypeName.
empty())
836 Arg[
".type_name"] = std::make_shared<msgpack::ScalarNode>(TypeName);
839 Arg[
".size"] = std::make_shared<msgpack::ScalarNode>(
Size);
841 Arg[
".offset"] = std::make_shared<msgpack::ScalarNode>(
Offset);
843 Arg[
".value_kind"] = std::make_shared<msgpack::ScalarNode>(
ValueKind);
845 std::make_shared<msgpack::ScalarNode>(getValueType(Ty, BaseTypeName));
847 Arg[
".pointee_align"] = std::make_shared<msgpack::ScalarNode>(
PointeeAlign);
849 if (
auto PtrTy = dyn_cast<PointerType>(Ty))
850 if (
auto Qualifier = getAddressSpaceQualifier(PtrTy->getAddressSpace()))
851 Arg[
".address_space"] = std::make_shared<msgpack::ScalarNode>(*Qualifier);
853 if (
auto AQ = getAccessQualifier(AccQual))
854 Arg[
".access"] = std::make_shared<msgpack::ScalarNode>(*AQ);
859 TypeQual.
split(SplitTypeQuals,
" ", -1,
false);
862 Arg[
".is_const"] = std::make_shared<msgpack::ScalarNode>(
true);
863 else if (
Key ==
"restrict")
864 Arg[
".is_restrict"] = std::make_shared<msgpack::ScalarNode>(
true);
865 else if (
Key ==
"volatile")
866 Arg[
".is_volatile"] = std::make_shared<msgpack::ScalarNode>(
true);
867 else if (
Key ==
"pipe")
868 Arg[
".is_pipe"] = std::make_shared<msgpack::ScalarNode>(
true);
871 Args.push_back(std::move(ArgPtr));
874 void MetadataStreamerV3::emitHiddenKernelArgs(
const Function &Func,
877 int HiddenArgNumBytes =
880 if (!HiddenArgNumBytes)
886 if (HiddenArgNumBytes >= 8)
887 emitKernelArg(DL, Int64Ty,
"hidden_global_offset_x", Offset, Args);
888 if (HiddenArgNumBytes >= 16)
889 emitKernelArg(DL, Int64Ty,
"hidden_global_offset_y", Offset, Args);
890 if (HiddenArgNumBytes >= 24)
891 emitKernelArg(DL, Int64Ty,
"hidden_global_offset_z", Offset, Args);
898 if (HiddenArgNumBytes >= 32) {
900 emitKernelArg(DL, Int8PtrTy,
"hidden_printf_buffer", Offset, Args);
902 emitKernelArg(DL, Int8PtrTy,
"hidden_none", Offset, Args);
907 if (HiddenArgNumBytes >= 48) {
909 emitKernelArg(DL, Int8PtrTy,
"hidden_default_queue", Offset, Args);
910 emitKernelArg(DL, Int8PtrTy,
"hidden_completion_action", Offset, Args);
912 emitKernelArg(DL, Int8PtrTy,
"hidden_none", Offset, Args);
913 emitKernelArg(DL, Int8PtrTy,
"hidden_none", Offset, Args);
918 std::shared_ptr<msgpack::MapNode>
925 auto HSAKernelProps = std::make_shared<msgpack::MapNode>();
926 auto &Kern = *HSAKernelProps;
928 unsigned MaxKernArgAlign;
929 Kern[
".kernarg_segment_size"] = std::make_shared<msgpack::ScalarNode>(
931 Kern[
".group_segment_fixed_size"] =
932 std::make_shared<msgpack::ScalarNode>(ProgramInfo.
LDSSize);
933 Kern[
".private_segment_fixed_size"] =
934 std::make_shared<msgpack::ScalarNode>(ProgramInfo.
ScratchSize);
935 Kern[
".kernarg_segment_align"] =
936 std::make_shared<msgpack::ScalarNode>(
std::max(
uint32_t(4), MaxKernArgAlign));
937 Kern[
".wavefront_size"] =
939 Kern[
".sgpr_count"] = std::make_shared<msgpack::ScalarNode>(ProgramInfo.
NumSGPR);
940 Kern[
".vgpr_count"] = std::make_shared<msgpack::ScalarNode>(ProgramInfo.
NumVGPR);
941 Kern[
".max_flat_workgroup_size"] =
942 std::make_shared<msgpack::ScalarNode>(MFI.getMaxFlatWorkGroupSize());
943 Kern[
".sgpr_spill_count"] =
944 std::make_shared<msgpack::ScalarNode>(MFI.getNumSpilledSGPRs());
945 Kern[
".vgpr_spill_count"] =
946 std::make_shared<msgpack::ScalarNode>(MFI.getNumSpilledVGPRs());
948 return HSAKernelProps;
962 std::string HSAMetadataString;
964 yaml::Output YOut(StrOS);
965 YOut << HSAMetadataRoot;
976 auto KernelProps = getHSAKernelProps(MF, ProgramInfo);
981 auto &KernelsNode = getRootMetadata(
"amdhsa.kernels");
982 auto Kernels = cast<msgpack::ArrayNode>(KernelsNode.get());
985 auto &Kern = *KernelProps;
986 Kern[
".name"] = std::make_shared<msgpack::ScalarNode>(Func.
getName());
987 Kern[
".symbol"] = std::make_shared<msgpack::ScalarNode>(
989 emitKernelLanguage(Func, Kern);
990 emitKernelAttrs(Func, Kern);
991 emitKernelArgs(Func, Kern);
994 Kernels->push_back(std::move(KernelProps));
Type * getVectorElementType() const
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
AMDGPU specific subclass of TargetSubtarget.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
2: 32-bit floating point type
constexpr char PointeeAlign[]
Key for Kernel::Arg::Metadata::mPointeeAlign.
Address space for private memory.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
const MDOperand & getOperand(unsigned I) const
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
1: 16-bit floating point type
static IntegerType * getInt64Ty(LLVMContext &C)
Track resource usage for kernels / entry functions.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
Address space for constant memory (VTX2)
Type * getPointerElementType() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
TypeID getTypeID() const
Return the type id for the type.
SPIR_KERNEL - Calling convention for SPIR kernel functions.
constexpr char Printf[]
Key for HSA::Metadata::mPrintf.
Defines struct to track resource usage for kernels and entry functions.
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE R Default(T Value)
std::error_code fromString(std::string String, Metadata &HSAMetadata)
Converts String to HSAMetadata.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Type * getType() const
All values are typed, get the type of this value.
static cl::opt< bool > VerifyHSAMetadata("amdgpu-verify-hsa-metadata", cl::desc("Verify AMDGPU HSA Metadata"))
op_range operands() const
bool onlyReadsMemory() const
Return true if this argument has the readonly or readnone attribute.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
bool hasNoAliasAttr() const
Return true if this argument has the noalias attribute.
11: Arbitrary bit width integers
A switch()-like statement whose cases are string literals.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
The instances of the Type class are immutable: once they are created, they are never changed...
static cl::opt< bool > DumpHSAMetadata("amdgpu-dump-hsa-metadata", cl::desc("Dump AMDGPU HSA Metadata"))
Address space for flat memory.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
Address space for local memory.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
constexpr char TypeName[]
Key for Kernel::Arg::Metadata::mTypeName.
constexpr uint32_t VersionMajor
HSA metadata major version.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
Address space for global memory (RAT0, VTX0).
static wasm::ValType getType(const TargetRegisterClass *RC)
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
constexpr uint32_t VersionMinor
HSA metadata minor version.
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
unsigned getKernArgSegmentSize(const Function &F, unsigned &MaxAlign) const
AccessQualifier
Access qualifiers.
unsigned getWavefrontSize() const
16: SIMD 'packed' format, or other vector type
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
unsigned getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Module.h This file contains the declarations for the Module class.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
constexpr char CodeProps[]
Key for Kernel::Metadata::mCodeProps.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
constexpr char LanguageVersion[]
Key for Kernel::Metadata::mLanguageVersion.
constexpr uint32_t VersionMinor
HSA metadata minor version.
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
LLVM_ATTRIBUTE_ALWAYS_INLINE StringSwitch & Case(StringLiteral S, T Value)
constexpr char Kernels[]
Key for HSA::Metadata::mKernels.
amdgpu Simplify well known AMD library false Value Value * Arg
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
std::error_code toString(Metadata HSAMetadata, std::string &String)
Converts HSAMetadata to String.
This class keeps track of the SPI_SP_INPUT_ADDR config register, which tells the hardware which inter...
const Function * getParent() const
unsigned getIntegerBitWidth() const
StringRef getValueAsString() const
Return the attribute's value as a string.
constexpr char DebugProps[]
Key for Kernel::Metadata::mDebugProps.
AddressSpaceQualifier
Address space qualifiers.
StringRef getName() const
Return a constant reference to the value's name.
int getIntegerAttribute(const Function &F, StringRef Name, int Default)
constexpr char AccQual[]
Key for Kernel::Arg::Metadata::mAccQual.
3: 64-bit floating point type
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
Module * getParent()
Get the module that this global value is contained inside of...
Address space for region memory. (GDS)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
virtual bool EmitHSAMetadata(std::shared_ptr< msgpack::Node > &HSAMetadata, bool Strict)=0
Emit HSA Metadata.
StringRef - Represent a constant reference to a string, i.e.
unsigned getNumOperands() const
Return number of MDNode operands.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Calling convention for AMDGPU code object kernels.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr uint32_t VersionMajor
HSA metadata major version.
std::vector< uint32_t > Metadata
PAL metadata represented as a vector.
iterator_range< arg_iterator > args()