Line data Source code
1 : //===--- AMDGPUCodeObjectMetadata.cpp ---------------------------*- C++ -*-===//
2 : //
3 : // The LLVM Compiler Infrastructure
4 : //
5 : // This file is distributed under the University of Illinois Open Source
6 : // License. See LICENSE.TXT for details.
7 : //
8 : //===----------------------------------------------------------------------===//
9 : //
10 : /// \file
11 : /// \brief AMDGPU Code Object Metadata definitions and in-memory
12 : /// representations.
13 : ///
14 : //
15 : //===----------------------------------------------------------------------===//
16 :
17 : #include "llvm/Support/AMDGPUCodeObjectMetadata.h"
18 : #include "llvm/Support/YAMLTraits.h"
19 :
20 : using namespace llvm::AMDGPU;
21 : using namespace llvm::AMDGPU::CodeObject;
22 :
23 : LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Arg::Metadata)
24 : LLVM_YAML_IS_SEQUENCE_VECTOR(Kernel::Metadata)
25 :
26 : namespace llvm {
27 : namespace yaml {
28 :
29 : template <>
30 : struct ScalarEnumerationTraits<AccessQualifier> {
31 1386 : static void enumeration(IO &YIO, AccessQualifier &EN) {
32 1386 : YIO.enumCase(EN, "Default", AccessQualifier::Default);
33 1386 : YIO.enumCase(EN, "ReadOnly", AccessQualifier::ReadOnly);
34 1386 : YIO.enumCase(EN, "WriteOnly", AccessQualifier::WriteOnly);
35 1386 : YIO.enumCase(EN, "ReadWrite", AccessQualifier::ReadWrite);
36 1386 : }
37 : };
38 :
39 : template <>
40 : struct ScalarEnumerationTraits<AddressSpaceQualifier> {
41 6680 : static void enumeration(IO &YIO, AddressSpaceQualifier &EN) {
42 6680 : YIO.enumCase(EN, "Private", AddressSpaceQualifier::Private);
43 6680 : YIO.enumCase(EN, "Global", AddressSpaceQualifier::Global);
44 6680 : YIO.enumCase(EN, "Constant", AddressSpaceQualifier::Constant);
45 6680 : YIO.enumCase(EN, "Local", AddressSpaceQualifier::Local);
46 6680 : YIO.enumCase(EN, "Generic", AddressSpaceQualifier::Generic);
47 6680 : YIO.enumCase(EN, "Region", AddressSpaceQualifier::Region);
48 6680 : }
49 : };
50 :
51 : template <>
52 : struct ScalarEnumerationTraits<ValueKind> {
53 11861 : static void enumeration(IO &YIO, ValueKind &EN) {
54 11861 : YIO.enumCase(EN, "ByValue", ValueKind::ByValue);
55 11861 : YIO.enumCase(EN, "GlobalBuffer", ValueKind::GlobalBuffer);
56 11861 : YIO.enumCase(EN, "DynamicSharedPointer", ValueKind::DynamicSharedPointer);
57 11861 : YIO.enumCase(EN, "Sampler", ValueKind::Sampler);
58 11861 : YIO.enumCase(EN, "Image", ValueKind::Image);
59 11861 : YIO.enumCase(EN, "Pipe", ValueKind::Pipe);
60 11861 : YIO.enumCase(EN, "Queue", ValueKind::Queue);
61 11861 : YIO.enumCase(EN, "HiddenGlobalOffsetX", ValueKind::HiddenGlobalOffsetX);
62 11861 : YIO.enumCase(EN, "HiddenGlobalOffsetY", ValueKind::HiddenGlobalOffsetY);
63 11861 : YIO.enumCase(EN, "HiddenGlobalOffsetZ", ValueKind::HiddenGlobalOffsetZ);
64 11861 : YIO.enumCase(EN, "HiddenNone", ValueKind::HiddenNone);
65 11861 : YIO.enumCase(EN, "HiddenPrintfBuffer", ValueKind::HiddenPrintfBuffer);
66 11861 : YIO.enumCase(EN, "HiddenDefaultQueue", ValueKind::HiddenDefaultQueue);
67 11861 : YIO.enumCase(EN, "HiddenCompletionAction",
68 : ValueKind::HiddenCompletionAction);
69 11861 : }
70 : };
71 :
72 : template <>
73 : struct ScalarEnumerationTraits<ValueType> {
74 11861 : static void enumeration(IO &YIO, ValueType &EN) {
75 11861 : YIO.enumCase(EN, "Struct", ValueType::Struct);
76 11861 : YIO.enumCase(EN, "I8", ValueType::I8);
77 11861 : YIO.enumCase(EN, "U8", ValueType::U8);
78 11861 : YIO.enumCase(EN, "I16", ValueType::I16);
79 11861 : YIO.enumCase(EN, "U16", ValueType::U16);
80 11861 : YIO.enumCase(EN, "F16", ValueType::F16);
81 11861 : YIO.enumCase(EN, "I32", ValueType::I32);
82 11861 : YIO.enumCase(EN, "U32", ValueType::U32);
83 11861 : YIO.enumCase(EN, "F32", ValueType::F32);
84 11861 : YIO.enumCase(EN, "I64", ValueType::I64);
85 11861 : YIO.enumCase(EN, "U64", ValueType::U64);
86 11861 : YIO.enumCase(EN, "F64", ValueType::F64);
87 11861 : }
88 : };
89 :
90 : template <>
91 : struct MappingTraits<Kernel::Attrs::Metadata> {
92 276 : static void mapping(IO &YIO, Kernel::Attrs::Metadata &MD) {
93 552 : YIO.mapOptional(Kernel::Attrs::Key::ReqdWorkGroupSize,
94 552 : MD.mReqdWorkGroupSize, std::vector<uint32_t>());
95 552 : YIO.mapOptional(Kernel::Attrs::Key::WorkGroupSizeHint,
96 552 : MD.mWorkGroupSizeHint, std::vector<uint32_t>());
97 552 : YIO.mapOptional(Kernel::Attrs::Key::VecTypeHint,
98 552 : MD.mVecTypeHint, std::string());
99 276 : }
100 : };
101 :
102 : template <>
103 : struct MappingTraits<Kernel::Arg::Metadata> {
104 11861 : static void mapping(IO &YIO, Kernel::Arg::Metadata &MD) {
105 23722 : YIO.mapRequired(Kernel::Arg::Key::Size, MD.mSize);
106 23722 : YIO.mapRequired(Kernel::Arg::Key::Align, MD.mAlign);
107 23722 : YIO.mapRequired(Kernel::Arg::Key::ValueKind, MD.mValueKind);
108 23722 : YIO.mapRequired(Kernel::Arg::Key::ValueType, MD.mValueType);
109 23722 : YIO.mapOptional(Kernel::Arg::Key::PointeeAlign, MD.mPointeeAlign,
110 : uint32_t(0));
111 23722 : YIO.mapOptional(Kernel::Arg::Key::AccQual, MD.mAccQual,
112 : AccessQualifier::Unknown);
113 23722 : YIO.mapOptional(Kernel::Arg::Key::AddrSpaceQual, MD.mAddrSpaceQual,
114 : AddressSpaceQualifier::Unknown);
115 23722 : YIO.mapOptional(Kernel::Arg::Key::IsConst, MD.mIsConst, false);
116 23722 : YIO.mapOptional(Kernel::Arg::Key::IsPipe, MD.mIsPipe, false);
117 23722 : YIO.mapOptional(Kernel::Arg::Key::IsRestrict, MD.mIsRestrict, false);
118 23722 : YIO.mapOptional(Kernel::Arg::Key::IsVolatile, MD.mIsVolatile, false);
119 35583 : YIO.mapOptional(Kernel::Arg::Key::Name, MD.mName, std::string());
120 35583 : YIO.mapOptional(Kernel::Arg::Key::TypeName, MD.mTypeName, std::string());
121 11861 : }
122 : };
123 :
124 : template <>
125 : struct MappingTraits<Kernel::CodeProps::Metadata> {
126 5365 : static void mapping(IO &YIO, Kernel::CodeProps::Metadata &MD) {
127 10730 : YIO.mapOptional(Kernel::CodeProps::Key::KernargSegmentSize,
128 : MD.mKernargSegmentSize, uint64_t(0));
129 10730 : YIO.mapOptional(Kernel::CodeProps::Key::WorkgroupGroupSegmentSize,
130 : MD.mWorkgroupGroupSegmentSize, uint32_t(0));
131 10730 : YIO.mapOptional(Kernel::CodeProps::Key::WorkitemPrivateSegmentSize,
132 : MD.mWorkitemPrivateSegmentSize, uint32_t(0));
133 10730 : YIO.mapOptional(Kernel::CodeProps::Key::WavefrontNumSGPRs,
134 : MD.mWavefrontNumSGPRs, uint16_t(0));
135 10730 : YIO.mapOptional(Kernel::CodeProps::Key::WorkitemNumVGPRs,
136 : MD.mWorkitemNumVGPRs, uint16_t(0));
137 10730 : YIO.mapOptional(Kernel::CodeProps::Key::KernargSegmentAlign,
138 : MD.mKernargSegmentAlign, uint8_t(0));
139 10730 : YIO.mapOptional(Kernel::CodeProps::Key::GroupSegmentAlign,
140 : MD.mGroupSegmentAlign, uint8_t(0));
141 10730 : YIO.mapOptional(Kernel::CodeProps::Key::PrivateSegmentAlign,
142 : MD.mPrivateSegmentAlign, uint8_t(0));
143 10730 : YIO.mapOptional(Kernel::CodeProps::Key::WavefrontSize,
144 : MD.mWavefrontSize, uint8_t(0));
145 5365 : }
146 : };
147 :
148 : template <>
149 : struct MappingTraits<Kernel::DebugProps::Metadata> {
150 15 : static void mapping(IO &YIO, Kernel::DebugProps::Metadata &MD) {
151 30 : YIO.mapOptional(Kernel::DebugProps::Key::DebuggerABIVersion,
152 30 : MD.mDebuggerABIVersion, std::vector<uint32_t>());
153 30 : YIO.mapOptional(Kernel::DebugProps::Key::ReservedNumVGPRs,
154 : MD.mReservedNumVGPRs, uint16_t(0));
155 30 : YIO.mapOptional(Kernel::DebugProps::Key::ReservedFirstVGPR,
156 : MD.mReservedFirstVGPR, uint16_t(-1));
157 30 : YIO.mapOptional(Kernel::DebugProps::Key::PrivateSegmentBufferSGPR,
158 : MD.mPrivateSegmentBufferSGPR, uint16_t(-1));
159 30 : YIO.mapOptional(Kernel::DebugProps::Key::WavefrontPrivateSegmentOffsetSGPR,
160 : MD.mWavefrontPrivateSegmentOffsetSGPR, uint16_t(-1));
161 15 : }
162 : };
163 :
164 : template <>
165 : struct MappingTraits<Kernel::Metadata> {
166 5397 : static void mapping(IO &YIO, Kernel::Metadata &MD) {
167 10794 : YIO.mapRequired(Kernel::Key::Name, MD.mName);
168 16191 : YIO.mapOptional(Kernel::Key::Language, MD.mLanguage, std::string());
169 10794 : YIO.mapOptional(Kernel::Key::LanguageVersion, MD.mLanguageVersion,
170 10794 : std::vector<uint32_t>());
171 10575 : if (!MD.mAttrs.empty() || !YIO.outputting())
172 2036 : YIO.mapOptional(Kernel::Key::Attrs, MD.mAttrs);
173 10794 : if (!MD.mArgs.empty() || !YIO.outputting())
174 4763 : YIO.mapOptional(Kernel::Key::Args, MD.mArgs);
175 5620 : if (!MD.mCodeProps.empty() || !YIO.outputting())
176 5384 : YIO.mapOptional(Kernel::Key::CodeProps, MD.mCodeProps);
177 10794 : if (!MD.mDebugProps.empty() || !YIO.outputting())
178 1880 : YIO.mapOptional(Kernel::Key::DebugProps, MD.mDebugProps);
179 5397 : }
180 : };
181 :
182 : template <>
183 : struct MappingTraits<CodeObject::Metadata> {
184 770 : static void mapping(IO &YIO, CodeObject::Metadata &MD) {
185 1540 : YIO.mapRequired(Key::Version, MD.mVersion);
186 1540 : YIO.mapOptional(Key::Printf, MD.mPrintf, std::vector<std::string>());
187 1540 : if (!MD.mKernels.empty() || !YIO.outputting())
188 689 : YIO.mapOptional(Key::Kernels, MD.mKernels);
189 770 : }
190 : };
191 :
192 : } // end namespace yaml
193 :
194 : namespace AMDGPU {
195 : namespace CodeObject {
196 :
197 : /* static */
198 268 : std::error_code Metadata::fromYamlString(
199 : std::string YamlString, Metadata &CodeObjectMetadata) {
200 536 : yaml::Input YamlInput(YamlString);
201 268 : YamlInput >> CodeObjectMetadata;
202 536 : return YamlInput.error();
203 : }
204 :
205 : /* static */
206 502 : std::error_code Metadata::toYamlString(
207 : Metadata CodeObjectMetadata, std::string &YamlString) {
208 1004 : raw_string_ostream YamlStream(YamlString);
209 1004 : yaml::Output YamlOutput(YamlStream, nullptr, std::numeric_limits<int>::max());
210 502 : YamlOutput << CodeObjectMetadata;
211 1004 : return std::error_code();
212 : }
213 :
214 : } // end namespace CodeObject
215 : } // end namespace AMDGPU
216 : } // end namespace llvm
|