1 //===--- AMDGPUMetadata.cpp -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 /// AMDGPU metadata definitions and in-memory representations.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/Support/AMDGPUMetadata.h"
17 #include "llvm/Support/YAMLTraits.h"
19 using namespace llvm::AMDGPU
;
20 using namespace llvm::AMDGPU::HSAMD
;
22 LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Arg::Metadata
)
23 LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Metadata
)
29 struct ScalarEnumerationTraits
<AccessQualifier
> {
30 static void enumeration(IO
&YIO
, AccessQualifier
&EN
) {
31 YIO
.enumCase(EN
, "Default", AccessQualifier::Default
);
32 YIO
.enumCase(EN
, "ReadOnly", AccessQualifier::ReadOnly
);
33 YIO
.enumCase(EN
, "WriteOnly", AccessQualifier::WriteOnly
);
34 YIO
.enumCase(EN
, "ReadWrite", AccessQualifier::ReadWrite
);
39 struct ScalarEnumerationTraits
<AddressSpaceQualifier
> {
40 static void enumeration(IO
&YIO
, AddressSpaceQualifier
&EN
) {
41 YIO
.enumCase(EN
, "Private", AddressSpaceQualifier::Private
);
42 YIO
.enumCase(EN
, "Global", AddressSpaceQualifier::Global
);
43 YIO
.enumCase(EN
, "Constant", AddressSpaceQualifier::Constant
);
44 YIO
.enumCase(EN
, "Local", AddressSpaceQualifier::Local
);
45 YIO
.enumCase(EN
, "Generic", AddressSpaceQualifier::Generic
);
46 YIO
.enumCase(EN
, "Region", AddressSpaceQualifier::Region
);
51 struct ScalarEnumerationTraits
<ValueKind
> {
52 static void enumeration(IO
&YIO
, ValueKind
&EN
) {
53 YIO
.enumCase(EN
, "ByValue", ValueKind::ByValue
);
54 YIO
.enumCase(EN
, "GlobalBuffer", ValueKind::GlobalBuffer
);
55 YIO
.enumCase(EN
, "DynamicSharedPointer", ValueKind::DynamicSharedPointer
);
56 YIO
.enumCase(EN
, "Sampler", ValueKind::Sampler
);
57 YIO
.enumCase(EN
, "Image", ValueKind::Image
);
58 YIO
.enumCase(EN
, "Pipe", ValueKind::Pipe
);
59 YIO
.enumCase(EN
, "Queue", ValueKind::Queue
);
60 YIO
.enumCase(EN
, "HiddenGlobalOffsetX", ValueKind::HiddenGlobalOffsetX
);
61 YIO
.enumCase(EN
, "HiddenGlobalOffsetY", ValueKind::HiddenGlobalOffsetY
);
62 YIO
.enumCase(EN
, "HiddenGlobalOffsetZ", ValueKind::HiddenGlobalOffsetZ
);
63 YIO
.enumCase(EN
, "HiddenNone", ValueKind::HiddenNone
);
64 YIO
.enumCase(EN
, "HiddenPrintfBuffer", ValueKind::HiddenPrintfBuffer
);
65 YIO
.enumCase(EN
, "HiddenDefaultQueue", ValueKind::HiddenDefaultQueue
);
66 YIO
.enumCase(EN
, "HiddenCompletionAction",
67 ValueKind::HiddenCompletionAction
);
72 struct ScalarEnumerationTraits
<ValueType
> {
73 static void enumeration(IO
&YIO
, ValueType
&EN
) {
74 YIO
.enumCase(EN
, "Struct", ValueType::Struct
);
75 YIO
.enumCase(EN
, "I8", ValueType::I8
);
76 YIO
.enumCase(EN
, "U8", ValueType::U8
);
77 YIO
.enumCase(EN
, "I16", ValueType::I16
);
78 YIO
.enumCase(EN
, "U16", ValueType::U16
);
79 YIO
.enumCase(EN
, "F16", ValueType::F16
);
80 YIO
.enumCase(EN
, "I32", ValueType::I32
);
81 YIO
.enumCase(EN
, "U32", ValueType::U32
);
82 YIO
.enumCase(EN
, "F32", ValueType::F32
);
83 YIO
.enumCase(EN
, "I64", ValueType::I64
);
84 YIO
.enumCase(EN
, "U64", ValueType::U64
);
85 YIO
.enumCase(EN
, "F64", ValueType::F64
);
90 struct MappingTraits
<Kernel::Attrs::Metadata
> {
91 static void mapping(IO
&YIO
, Kernel::Attrs::Metadata
&MD
) {
92 YIO
.mapOptional(Kernel::Attrs::Key::ReqdWorkGroupSize
,
93 MD
.mReqdWorkGroupSize
, std::vector
<uint32_t>());
94 YIO
.mapOptional(Kernel::Attrs::Key::WorkGroupSizeHint
,
95 MD
.mWorkGroupSizeHint
, std::vector
<uint32_t>());
96 YIO
.mapOptional(Kernel::Attrs::Key::VecTypeHint
,
97 MD
.mVecTypeHint
, std::string());
98 YIO
.mapOptional(Kernel::Attrs::Key::RuntimeHandle
, MD
.mRuntimeHandle
,
104 struct MappingTraits
<Kernel::Arg::Metadata
> {
105 static void mapping(IO
&YIO
, Kernel::Arg::Metadata
&MD
) {
106 YIO
.mapOptional(Kernel::Arg::Key::Name
, MD
.mName
, std::string());
107 YIO
.mapOptional(Kernel::Arg::Key::TypeName
, MD
.mTypeName
, std::string());
108 YIO
.mapRequired(Kernel::Arg::Key::Size
, MD
.mSize
);
109 YIO
.mapRequired(Kernel::Arg::Key::Align
, MD
.mAlign
);
110 YIO
.mapRequired(Kernel::Arg::Key::ValueKind
, MD
.mValueKind
);
111 YIO
.mapRequired(Kernel::Arg::Key::ValueType
, MD
.mValueType
);
112 YIO
.mapOptional(Kernel::Arg::Key::PointeeAlign
, MD
.mPointeeAlign
,
114 YIO
.mapOptional(Kernel::Arg::Key::AddrSpaceQual
, MD
.mAddrSpaceQual
,
115 AddressSpaceQualifier::Unknown
);
116 YIO
.mapOptional(Kernel::Arg::Key::AccQual
, MD
.mAccQual
,
117 AccessQualifier::Unknown
);
118 YIO
.mapOptional(Kernel::Arg::Key::ActualAccQual
, MD
.mActualAccQual
,
119 AccessQualifier::Unknown
);
120 YIO
.mapOptional(Kernel::Arg::Key::IsConst
, MD
.mIsConst
, false);
121 YIO
.mapOptional(Kernel::Arg::Key::IsRestrict
, MD
.mIsRestrict
, false);
122 YIO
.mapOptional(Kernel::Arg::Key::IsVolatile
, MD
.mIsVolatile
, false);
123 YIO
.mapOptional(Kernel::Arg::Key::IsPipe
, MD
.mIsPipe
, false);
128 struct MappingTraits
<Kernel::CodeProps::Metadata
> {
129 static void mapping(IO
&YIO
, Kernel::CodeProps::Metadata
&MD
) {
130 YIO
.mapRequired(Kernel::CodeProps::Key::KernargSegmentSize
,
131 MD
.mKernargSegmentSize
);
132 YIO
.mapRequired(Kernel::CodeProps::Key::GroupSegmentFixedSize
,
133 MD
.mGroupSegmentFixedSize
);
134 YIO
.mapRequired(Kernel::CodeProps::Key::PrivateSegmentFixedSize
,
135 MD
.mPrivateSegmentFixedSize
);
136 YIO
.mapRequired(Kernel::CodeProps::Key::KernargSegmentAlign
,
137 MD
.mKernargSegmentAlign
);
138 YIO
.mapRequired(Kernel::CodeProps::Key::WavefrontSize
,
140 YIO
.mapOptional(Kernel::CodeProps::Key::NumSGPRs
,
141 MD
.mNumSGPRs
, uint16_t(0));
142 YIO
.mapOptional(Kernel::CodeProps::Key::NumVGPRs
,
143 MD
.mNumVGPRs
, uint16_t(0));
144 YIO
.mapOptional(Kernel::CodeProps::Key::MaxFlatWorkGroupSize
,
145 MD
.mMaxFlatWorkGroupSize
, uint32_t(0));
146 YIO
.mapOptional(Kernel::CodeProps::Key::IsDynamicCallStack
,
147 MD
.mIsDynamicCallStack
, false);
148 YIO
.mapOptional(Kernel::CodeProps::Key::IsXNACKEnabled
,
149 MD
.mIsXNACKEnabled
, false);
150 YIO
.mapOptional(Kernel::CodeProps::Key::NumSpilledSGPRs
,
151 MD
.mNumSpilledSGPRs
, uint16_t(0));
152 YIO
.mapOptional(Kernel::CodeProps::Key::NumSpilledVGPRs
,
153 MD
.mNumSpilledVGPRs
, uint16_t(0));
158 struct MappingTraits
<Kernel::DebugProps::Metadata
> {
159 static void mapping(IO
&YIO
, Kernel::DebugProps::Metadata
&MD
) {
160 YIO
.mapOptional(Kernel::DebugProps::Key::DebuggerABIVersion
,
161 MD
.mDebuggerABIVersion
, std::vector
<uint32_t>());
162 YIO
.mapOptional(Kernel::DebugProps::Key::ReservedNumVGPRs
,
163 MD
.mReservedNumVGPRs
, uint16_t(0));
164 YIO
.mapOptional(Kernel::DebugProps::Key::ReservedFirstVGPR
,
165 MD
.mReservedFirstVGPR
, uint16_t(-1));
166 YIO
.mapOptional(Kernel::DebugProps::Key::PrivateSegmentBufferSGPR
,
167 MD
.mPrivateSegmentBufferSGPR
, uint16_t(-1));
168 YIO
.mapOptional(Kernel::DebugProps::Key::WavefrontPrivateSegmentOffsetSGPR
,
169 MD
.mWavefrontPrivateSegmentOffsetSGPR
, uint16_t(-1));
174 struct MappingTraits
<Kernel::Metadata
> {
175 static void mapping(IO
&YIO
, Kernel::Metadata
&MD
) {
176 YIO
.mapRequired(Kernel::Key::Name
, MD
.mName
);
177 YIO
.mapRequired(Kernel::Key::SymbolName
, MD
.mSymbolName
);
178 YIO
.mapOptional(Kernel::Key::Language
, MD
.mLanguage
, std::string());
179 YIO
.mapOptional(Kernel::Key::LanguageVersion
, MD
.mLanguageVersion
,
180 std::vector
<uint32_t>());
181 if (!MD
.mAttrs
.empty() || !YIO
.outputting())
182 YIO
.mapOptional(Kernel::Key::Attrs
, MD
.mAttrs
);
183 if (!MD
.mArgs
.empty() || !YIO
.outputting())
184 YIO
.mapOptional(Kernel::Key::Args
, MD
.mArgs
);
185 if (!MD
.mCodeProps
.empty() || !YIO
.outputting())
186 YIO
.mapOptional(Kernel::Key::CodeProps
, MD
.mCodeProps
);
187 if (!MD
.mDebugProps
.empty() || !YIO
.outputting())
188 YIO
.mapOptional(Kernel::Key::DebugProps
, MD
.mDebugProps
);
193 struct MappingTraits
<HSAMD::Metadata
> {
194 static void mapping(IO
&YIO
, HSAMD::Metadata
&MD
) {
195 YIO
.mapRequired(Key::Version
, MD
.mVersion
);
196 YIO
.mapOptional(Key::Printf
, MD
.mPrintf
, std::vector
<std::string
>());
197 if (!MD
.mKernels
.empty() || !YIO
.outputting())
198 YIO
.mapOptional(Key::Kernels
, MD
.mKernels
);
202 } // end namespace yaml
207 std::error_code
fromString(std::string String
, Metadata
&HSAMetadata
) {
208 yaml::Input
YamlInput(String
);
209 YamlInput
>> HSAMetadata
;
210 return YamlInput
.error();
213 std::error_code
toString(Metadata HSAMetadata
, std::string
&String
) {
214 raw_string_ostream
YamlStream(String
);
215 yaml::Output
YamlOutput(YamlStream
, nullptr, std::numeric_limits
<int>::max());
216 YamlOutput
<< HSAMetadata
;
217 return std::error_code();
220 } // end namespace HSAMD
224 std::error_code
toString(const Metadata
&PALMetadata
, std::string
&String
) {
225 raw_string_ostream
Stream(String
);
226 for (auto I
= PALMetadata
.begin(), E
= PALMetadata
.end(); I
!= E
; ++I
) {
227 Stream
<< Twine(I
== PALMetadata
.begin() ? " 0x" : ",0x");
228 Stream
<< Twine::utohexstr(*I
);
231 return std::error_code();
234 } // end namespace PALMD
235 } // end namespace AMDGPU
236 } // end namespace llvm