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