[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / Support / AMDGPUMetadata.cpp
blob3d6325134d75f1ee4f4a0c967e0c3b7e28d5fdef
1 //===--- AMDGPUMetadata.cpp -------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 /// \file
10 /// AMDGPU metadata definitions and in-memory representations.
11 ///
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Support/AMDGPUMetadata.h"
16 #include "llvm/Support/YAMLTraits.h"
18 using namespace llvm::AMDGPU;
19 using namespace llvm::AMDGPU::HSAMD;
21 LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Arg::Metadata)
22 LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Metadata)
24 namespace llvm {
25 namespace yaml {
27 template <>
28 struct ScalarEnumerationTraits<AccessQualifier> {
29 static void enumeration(IO &YIO, AccessQualifier &EN) {
30 YIO.enumCase(EN, "Default", AccessQualifier::Default);
31 YIO.enumCase(EN, "ReadOnly", AccessQualifier::ReadOnly);
32 YIO.enumCase(EN, "WriteOnly", AccessQualifier::WriteOnly);
33 YIO.enumCase(EN, "ReadWrite", AccessQualifier::ReadWrite);
37 template <>
38 struct ScalarEnumerationTraits<AddressSpaceQualifier> {
39 static void enumeration(IO &YIO, AddressSpaceQualifier &EN) {
40 YIO.enumCase(EN, "Private", AddressSpaceQualifier::Private);
41 YIO.enumCase(EN, "Global", AddressSpaceQualifier::Global);
42 YIO.enumCase(EN, "Constant", AddressSpaceQualifier::Constant);
43 YIO.enumCase(EN, "Local", AddressSpaceQualifier::Local);
44 YIO.enumCase(EN, "Generic", AddressSpaceQualifier::Generic);
45 YIO.enumCase(EN, "Region", AddressSpaceQualifier::Region);
49 template <>
50 struct ScalarEnumerationTraits<ValueKind> {
51 static void enumeration(IO &YIO, ValueKind &EN) {
52 YIO.enumCase(EN, "ByValue", ValueKind::ByValue);
53 YIO.enumCase(EN, "GlobalBuffer", ValueKind::GlobalBuffer);
54 YIO.enumCase(EN, "DynamicSharedPointer", ValueKind::DynamicSharedPointer);
55 YIO.enumCase(EN, "Sampler", ValueKind::Sampler);
56 YIO.enumCase(EN, "Image", ValueKind::Image);
57 YIO.enumCase(EN, "Pipe", ValueKind::Pipe);
58 YIO.enumCase(EN, "Queue", ValueKind::Queue);
59 YIO.enumCase(EN, "HiddenGlobalOffsetX", ValueKind::HiddenGlobalOffsetX);
60 YIO.enumCase(EN, "HiddenGlobalOffsetY", ValueKind::HiddenGlobalOffsetY);
61 YIO.enumCase(EN, "HiddenGlobalOffsetZ", ValueKind::HiddenGlobalOffsetZ);
62 YIO.enumCase(EN, "HiddenNone", ValueKind::HiddenNone);
63 YIO.enumCase(EN, "HiddenPrintfBuffer", ValueKind::HiddenPrintfBuffer);
64 YIO.enumCase(EN, "HiddenHostcallBuffer", ValueKind::HiddenHostcallBuffer);
65 YIO.enumCase(EN, "HiddenDefaultQueue", ValueKind::HiddenDefaultQueue);
66 YIO.enumCase(EN, "HiddenCompletionAction",
67 ValueKind::HiddenCompletionAction);
68 YIO.enumCase(EN, "HiddenMultiGridSyncArg",
69 ValueKind::HiddenMultiGridSyncArg);
73 template <>
74 struct ScalarEnumerationTraits<ValueType> {
75 static void enumeration(IO &YIO, ValueType &EN) {
76 YIO.enumCase(EN, "Struct", ValueType::Struct);
77 YIO.enumCase(EN, "I8", ValueType::I8);
78 YIO.enumCase(EN, "U8", ValueType::U8);
79 YIO.enumCase(EN, "I16", ValueType::I16);
80 YIO.enumCase(EN, "U16", ValueType::U16);
81 YIO.enumCase(EN, "F16", ValueType::F16);
82 YIO.enumCase(EN, "I32", ValueType::I32);
83 YIO.enumCase(EN, "U32", ValueType::U32);
84 YIO.enumCase(EN, "F32", ValueType::F32);
85 YIO.enumCase(EN, "I64", ValueType::I64);
86 YIO.enumCase(EN, "U64", ValueType::U64);
87 YIO.enumCase(EN, "F64", ValueType::F64);
91 template <>
92 struct MappingTraits<Kernel::Attrs::Metadata> {
93 static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD) {
94 YIO.mapOptional(Kernel::Attrs::Key::ReqdWorkGroupSize,
95 MD.mReqdWorkGroupSize, std::vector<uint32_t>());
96 YIO.mapOptional(Kernel::Attrs::Key::WorkGroupSizeHint,
97 MD.mWorkGroupSizeHint, std::vector<uint32_t>());
98 YIO.mapOptional(Kernel::Attrs::Key::VecTypeHint,
99 MD.mVecTypeHint, std::string());
100 YIO.mapOptional(Kernel::Attrs::Key::RuntimeHandle, MD.mRuntimeHandle,
101 std::string());
105 template <>
106 struct MappingTraits<Kernel::Arg::Metadata> {
107 static void mapping(IO &YIO, Kernel::Arg::Metadata &MD) {
108 YIO.mapOptional(Kernel::Arg::Key::Name, MD.mName, std::string());
109 YIO.mapOptional(Kernel::Arg::Key::TypeName, MD.mTypeName, std::string());
110 YIO.mapRequired(Kernel::Arg::Key::Size, MD.mSize);
111 YIO.mapRequired(Kernel::Arg::Key::Align, MD.mAlign);
112 YIO.mapRequired(Kernel::Arg::Key::ValueKind, MD.mValueKind);
114 // Removed. Accepted for parsing compatibility, but not emitted.
115 Optional<ValueType> Unused;
116 YIO.mapOptional(Kernel::Arg::Key::ValueType, Unused);
118 YIO.mapOptional(Kernel::Arg::Key::PointeeAlign, MD.mPointeeAlign,
119 uint32_t(0));
120 YIO.mapOptional(Kernel::Arg::Key::AddrSpaceQual, MD.mAddrSpaceQual,
121 AddressSpaceQualifier::Unknown);
122 YIO.mapOptional(Kernel::Arg::Key::AccQual, MD.mAccQual,
123 AccessQualifier::Unknown);
124 YIO.mapOptional(Kernel::Arg::Key::ActualAccQual, MD.mActualAccQual,
125 AccessQualifier::Unknown);
126 YIO.mapOptional(Kernel::Arg::Key::IsConst, MD.mIsConst, false);
127 YIO.mapOptional(Kernel::Arg::Key::IsRestrict, MD.mIsRestrict, false);
128 YIO.mapOptional(Kernel::Arg::Key::IsVolatile, MD.mIsVolatile, false);
129 YIO.mapOptional(Kernel::Arg::Key::IsPipe, MD.mIsPipe, false);
133 template <>
134 struct MappingTraits<Kernel::CodeProps::Metadata> {
135 static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD) {
136 YIO.mapRequired(Kernel::CodeProps::Key::KernargSegmentSize,
137 MD.mKernargSegmentSize);
138 YIO.mapRequired(Kernel::CodeProps::Key::GroupSegmentFixedSize,
139 MD.mGroupSegmentFixedSize);
140 YIO.mapRequired(Kernel::CodeProps::Key::PrivateSegmentFixedSize,
141 MD.mPrivateSegmentFixedSize);
142 YIO.mapRequired(Kernel::CodeProps::Key::KernargSegmentAlign,
143 MD.mKernargSegmentAlign);
144 YIO.mapRequired(Kernel::CodeProps::Key::WavefrontSize,
145 MD.mWavefrontSize);
146 YIO.mapOptional(Kernel::CodeProps::Key::NumSGPRs,
147 MD.mNumSGPRs, uint16_t(0));
148 YIO.mapOptional(Kernel::CodeProps::Key::NumVGPRs,
149 MD.mNumVGPRs, uint16_t(0));
150 YIO.mapOptional(Kernel::CodeProps::Key::MaxFlatWorkGroupSize,
151 MD.mMaxFlatWorkGroupSize, uint32_t(0));
152 YIO.mapOptional(Kernel::CodeProps::Key::IsDynamicCallStack,
153 MD.mIsDynamicCallStack, false);
154 YIO.mapOptional(Kernel::CodeProps::Key::IsXNACKEnabled,
155 MD.mIsXNACKEnabled, false);
156 YIO.mapOptional(Kernel::CodeProps::Key::NumSpilledSGPRs,
157 MD.mNumSpilledSGPRs, uint16_t(0));
158 YIO.mapOptional(Kernel::CodeProps::Key::NumSpilledVGPRs,
159 MD.mNumSpilledVGPRs, uint16_t(0));
163 template <>
164 struct MappingTraits<Kernel::DebugProps::Metadata> {
165 static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD) {
166 YIO.mapOptional(Kernel::DebugProps::Key::DebuggerABIVersion,
167 MD.mDebuggerABIVersion, std::vector<uint32_t>());
168 YIO.mapOptional(Kernel::DebugProps::Key::ReservedNumVGPRs,
169 MD.mReservedNumVGPRs, uint16_t(0));
170 YIO.mapOptional(Kernel::DebugProps::Key::ReservedFirstVGPR,
171 MD.mReservedFirstVGPR, uint16_t(-1));
172 YIO.mapOptional(Kernel::DebugProps::Key::PrivateSegmentBufferSGPR,
173 MD.mPrivateSegmentBufferSGPR, uint16_t(-1));
174 YIO.mapOptional(Kernel::DebugProps::Key::WavefrontPrivateSegmentOffsetSGPR,
175 MD.mWavefrontPrivateSegmentOffsetSGPR, uint16_t(-1));
179 template <>
180 struct MappingTraits<Kernel::Metadata> {
181 static void mapping(IO &YIO, Kernel::Metadata &MD) {
182 YIO.mapRequired(Kernel::Key::Name, MD.mName);
183 YIO.mapRequired(Kernel::Key::SymbolName, MD.mSymbolName);
184 YIO.mapOptional(Kernel::Key::Language, MD.mLanguage, std::string());
185 YIO.mapOptional(Kernel::Key::LanguageVersion, MD.mLanguageVersion,
186 std::vector<uint32_t>());
187 if (!MD.mAttrs.empty() || !YIO.outputting())
188 YIO.mapOptional(Kernel::Key::Attrs, MD.mAttrs);
189 if (!MD.mArgs.empty() || !YIO.outputting())
190 YIO.mapOptional(Kernel::Key::Args, MD.mArgs);
191 if (!MD.mCodeProps.empty() || !YIO.outputting())
192 YIO.mapOptional(Kernel::Key::CodeProps, MD.mCodeProps);
193 if (!MD.mDebugProps.empty() || !YIO.outputting())
194 YIO.mapOptional(Kernel::Key::DebugProps, MD.mDebugProps);
198 template <>
199 struct MappingTraits<HSAMD::Metadata> {
200 static void mapping(IO &YIO, HSAMD::Metadata &MD) {
201 YIO.mapRequired(Key::Version, MD.mVersion);
202 YIO.mapOptional(Key::Printf, MD.mPrintf, std::vector<std::string>());
203 if (!MD.mKernels.empty() || !YIO.outputting())
204 YIO.mapOptional(Key::Kernels, MD.mKernels);
208 } // end namespace yaml
210 namespace AMDGPU {
211 namespace HSAMD {
213 std::error_code fromString(StringRef String, Metadata &HSAMetadata) {
214 yaml::Input YamlInput(String);
215 YamlInput >> HSAMetadata;
216 return YamlInput.error();
219 std::error_code toString(Metadata HSAMetadata, std::string &String) {
220 raw_string_ostream YamlStream(String);
221 yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
222 YamlOutput << HSAMetadata;
223 return std::error_code();
226 } // end namespace HSAMD
227 } // end namespace AMDGPU
228 } // end namespace llvm