[Alignment][NFC] Convert StoreInst to MaybeAlign
[llvm-complete.git] / lib / Support / AMDGPUMetadata.cpp
blob5f8102299f47a9479df37196e7e776f08b98685c
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/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)
25 namespace llvm {
26 namespace yaml {
28 template <>
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);
38 template <>
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);
50 template <>
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);
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);
113 YIO.mapRequired(Kernel::Arg::Key::ValueType, MD.mValueType);
114 YIO.mapOptional(Kernel::Arg::Key::PointeeAlign, MD.mPointeeAlign,
115 uint32_t(0));
116 YIO.mapOptional(Kernel::Arg::Key::AddrSpaceQual, MD.mAddrSpaceQual,
117 AddressSpaceQualifier::Unknown);
118 YIO.mapOptional(Kernel::Arg::Key::AccQual, MD.mAccQual,
119 AccessQualifier::Unknown);
120 YIO.mapOptional(Kernel::Arg::Key::ActualAccQual, MD.mActualAccQual,
121 AccessQualifier::Unknown);
122 YIO.mapOptional(Kernel::Arg::Key::IsConst, MD.mIsConst, false);
123 YIO.mapOptional(Kernel::Arg::Key::IsRestrict, MD.mIsRestrict, false);
124 YIO.mapOptional(Kernel::Arg::Key::IsVolatile, MD.mIsVolatile, false);
125 YIO.mapOptional(Kernel::Arg::Key::IsPipe, MD.mIsPipe, false);
129 template <>
130 struct MappingTraits<Kernel::CodeProps::Metadata> {
131 static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD) {
132 YIO.mapRequired(Kernel::CodeProps::Key::KernargSegmentSize,
133 MD.mKernargSegmentSize);
134 YIO.mapRequired(Kernel::CodeProps::Key::GroupSegmentFixedSize,
135 MD.mGroupSegmentFixedSize);
136 YIO.mapRequired(Kernel::CodeProps::Key::PrivateSegmentFixedSize,
137 MD.mPrivateSegmentFixedSize);
138 YIO.mapRequired(Kernel::CodeProps::Key::KernargSegmentAlign,
139 MD.mKernargSegmentAlign);
140 YIO.mapRequired(Kernel::CodeProps::Key::WavefrontSize,
141 MD.mWavefrontSize);
142 YIO.mapOptional(Kernel::CodeProps::Key::NumSGPRs,
143 MD.mNumSGPRs, uint16_t(0));
144 YIO.mapOptional(Kernel::CodeProps::Key::NumVGPRs,
145 MD.mNumVGPRs, uint16_t(0));
146 YIO.mapOptional(Kernel::CodeProps::Key::MaxFlatWorkGroupSize,
147 MD.mMaxFlatWorkGroupSize, uint32_t(0));
148 YIO.mapOptional(Kernel::CodeProps::Key::IsDynamicCallStack,
149 MD.mIsDynamicCallStack, false);
150 YIO.mapOptional(Kernel::CodeProps::Key::IsXNACKEnabled,
151 MD.mIsXNACKEnabled, false);
152 YIO.mapOptional(Kernel::CodeProps::Key::NumSpilledSGPRs,
153 MD.mNumSpilledSGPRs, uint16_t(0));
154 YIO.mapOptional(Kernel::CodeProps::Key::NumSpilledVGPRs,
155 MD.mNumSpilledVGPRs, uint16_t(0));
159 template <>
160 struct MappingTraits<Kernel::DebugProps::Metadata> {
161 static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD) {
162 YIO.mapOptional(Kernel::DebugProps::Key::DebuggerABIVersion,
163 MD.mDebuggerABIVersion, std::vector<uint32_t>());
164 YIO.mapOptional(Kernel::DebugProps::Key::ReservedNumVGPRs,
165 MD.mReservedNumVGPRs, uint16_t(0));
166 YIO.mapOptional(Kernel::DebugProps::Key::ReservedFirstVGPR,
167 MD.mReservedFirstVGPR, uint16_t(-1));
168 YIO.mapOptional(Kernel::DebugProps::Key::PrivateSegmentBufferSGPR,
169 MD.mPrivateSegmentBufferSGPR, uint16_t(-1));
170 YIO.mapOptional(Kernel::DebugProps::Key::WavefrontPrivateSegmentOffsetSGPR,
171 MD.mWavefrontPrivateSegmentOffsetSGPR, uint16_t(-1));
175 template <>
176 struct MappingTraits<Kernel::Metadata> {
177 static void mapping(IO &YIO, Kernel::Metadata &MD) {
178 YIO.mapRequired(Kernel::Key::Name, MD.mName);
179 YIO.mapRequired(Kernel::Key::SymbolName, MD.mSymbolName);
180 YIO.mapOptional(Kernel::Key::Language, MD.mLanguage, std::string());
181 YIO.mapOptional(Kernel::Key::LanguageVersion, MD.mLanguageVersion,
182 std::vector<uint32_t>());
183 if (!MD.mAttrs.empty() || !YIO.outputting())
184 YIO.mapOptional(Kernel::Key::Attrs, MD.mAttrs);
185 if (!MD.mArgs.empty() || !YIO.outputting())
186 YIO.mapOptional(Kernel::Key::Args, MD.mArgs);
187 if (!MD.mCodeProps.empty() || !YIO.outputting())
188 YIO.mapOptional(Kernel::Key::CodeProps, MD.mCodeProps);
189 if (!MD.mDebugProps.empty() || !YIO.outputting())
190 YIO.mapOptional(Kernel::Key::DebugProps, MD.mDebugProps);
194 template <>
195 struct MappingTraits<HSAMD::Metadata> {
196 static void mapping(IO &YIO, HSAMD::Metadata &MD) {
197 YIO.mapRequired(Key::Version, MD.mVersion);
198 YIO.mapOptional(Key::Printf, MD.mPrintf, std::vector<std::string>());
199 if (!MD.mKernels.empty() || !YIO.outputting())
200 YIO.mapOptional(Key::Kernels, MD.mKernels);
204 } // end namespace yaml
206 namespace AMDGPU {
207 namespace HSAMD {
209 std::error_code fromString(std::string String, Metadata &HSAMetadata) {
210 yaml::Input YamlInput(String);
211 YamlInput >> HSAMetadata;
212 return YamlInput.error();
215 std::error_code toString(Metadata HSAMetadata, std::string &String) {
216 raw_string_ostream YamlStream(String);
217 yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
218 YamlOutput << HSAMetadata;
219 return std::error_code();
222 } // end namespace HSAMD
223 } // end namespace AMDGPU
224 } // end namespace llvm