Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/lib/SPIRV/libSPIRV/SPIRVDecorate.h

raw
1 //===- SPIRVDecorate.h - SPIR-V Decorations ---------------------*- C++ -*-===//
2 //
3 // The LLVM/SPIRV Translator
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 // Copyright (c) 2014 Advanced Micro Devices, Inc. All rights reserved.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal with the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // Redistributions of source code must retain the above copyright notice,
18 // this list of conditions and the following disclaimers.
19 // Redistributions in binary form must reproduce the above copyright notice,
20 // this list of conditions and the following disclaimers in the documentation
21 // and/or other materials provided with the distribution.
22 // Neither the names of Advanced Micro Devices, Inc., nor the names of its
23 // contributors may be used to endorse or promote products derived from this
24 // Software without specific prior written permission.
25 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
31 // THE SOFTWARE.
32 //
33 //===----------------------------------------------------------------------===//
34 /// \file
35 ///
36 /// This file defines SPIR-V decorations.
37 ///
38 //===----------------------------------------------------------------------===//
39
40 #ifndef SPIRV_LIBSPIRV_SPIRVDECORATE_H
41 #define SPIRV_LIBSPIRV_SPIRVDECORATE_H
42
43 #include "SPIRVEntry.h"
44 #include "SPIRVStream.h"
45 #include "SPIRVUtil.h"
46 #include <string>
47 #include <utility>
48 #include <vector>
49
50 namespace SPIRV {
51 class SPIRVDecorationGroup;
52 class SPIRVDecorateGeneric : public SPIRVAnnotationGeneric {
53 public:
54 // Complete constructor for decorations without literals
55 SPIRVDecorateGeneric(Op OC, SPIRVWord WC, Decoration TheDec,
56 SPIRVEntry *TheTarget);
57 // Complete constructor for decorations with one word literal
58 SPIRVDecorateGeneric(Op OC, SPIRVWord WC, Decoration TheDec,
59 SPIRVEntry *TheTarget, SPIRVWord V);
60 // Complete constructor for decorations with two word literals
61 SPIRVDecorateGeneric(Op OC, SPIRVWord WC, Decoration TheDec,
62 SPIRVEntry *TheTarget, SPIRVWord V1, SPIRVWord V2);
63 // Incomplete constructor
64 SPIRVDecorateGeneric(Op OC);
65
66 SPIRVWord getLiteral(size_t) const;
67 std::vector<SPIRVWord> getVecLiteral() const;
68 Decoration getDecorateKind() const;
69 size_t getLiteralCount() const;
70 SPIRVDecorationGroup *getOwner() const { return Owner; }
71
72 void setOwner(SPIRVDecorationGroup *Owner) { this->Owner = Owner; }
73
74 SPIRVCapVec getRequiredCapability() const override {
75 switch (Dec) {
76 case DecorationBuiltIn: {
77 // Return the BuiltIn's capabilities.
78 BuiltIn BI = static_cast<BuiltIn>(Literals.back());
79 return getCapability(BI);
80 }
81 case DecorationUniform:
82 if (Module->isAllowedToUseVersion(VersionNumber::SPIRV_1_6))
83 return getVec(CapabilityUniformDecoration);
84 return getVec(CapabilityShader);
85
86 default:
87 return getCapability(Dec);
88 }
89 }
90
91 SPIRVWord getRequiredSPIRVVersion() const override {
92 switch (Dec) {
93 case DecorationSpecId:
94 if (getModule()->hasCapability(CapabilityKernel))
95 return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_1);
96 else
97 return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_0);
98
99 case DecorationMaxByteOffset:
100 return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_1);
101 case DecorationUserSemantic:
102 case DecorationCounterBuffer:
103 return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_4);
104
105 default:
106 return static_cast<SPIRVWord>(VersionNumber::SPIRV_1_0);
107 }
108 }
109
110 protected:
111 Decoration Dec;
112 std::vector<SPIRVWord> Literals;
113 SPIRVDecorationGroup *Owner; // Owning decorate group
114 };
115
116 typedef std::vector<SPIRVDecorateGeneric *> SPIRVDecorateVec;
117
118 class SPIRVDecorate : public SPIRVDecorateGeneric {
119 public:
120 static const Op OC = OpDecorate;
121 static const SPIRVWord FixedWC = 3;
122 // Complete constructor for decorations without literals
123 SPIRVDecorate(Decoration TheDec, SPIRVEntry *TheTarget)
124 : SPIRVDecorateGeneric(OC, 3, TheDec, TheTarget) {}
125 // Complete constructor for decorations with one word literal
126 SPIRVDecorate(Decoration TheDec, SPIRVEntry *TheTarget, SPIRVWord V)
127 : SPIRVDecorateGeneric(OC, 4, TheDec, TheTarget, V) {}
128 // Complete constructor for decorations with two word literals
129 SPIRVDecorate(Decoration TheDec, SPIRVEntry *TheTarget, SPIRVWord V1,
130 SPIRVWord V2)
131 : SPIRVDecorateGeneric(OC, 5, TheDec, TheTarget, V1, V2) {}
132 // Incomplete constructor
133 SPIRVDecorate() : SPIRVDecorateGeneric(OC) {}
134
135 std::optional<ExtensionID> getRequiredExtension() const override {
136 switch (static_cast<size_t>(Dec)) {
137 case DecorationRegisterINTEL:
138 case DecorationMemoryINTEL:
139 case DecorationNumbanksINTEL:
140 case DecorationBankwidthINTEL:
141 case DecorationMaxPrivateCopiesINTEL:
142 case DecorationSinglepumpINTEL:
143 case DecorationDoublepumpINTEL:
144 case DecorationMaxReplicatesINTEL:
145 case DecorationSimpleDualPortINTEL:
146 case DecorationMergeINTEL:
147 case DecorationBankBitsINTEL:
148 case DecorationForcePow2DepthINTEL:
149 return ExtensionID::SPV_INTEL_fpga_memory_attributes;
150 case DecorationBurstCoalesceINTEL:
151 case DecorationCacheSizeINTEL:
152 case DecorationDontStaticallyCoalesceINTEL:
153 case DecorationPrefetchINTEL:
154 return ExtensionID::SPV_INTEL_fpga_memory_accesses;
155 case DecorationReferencedIndirectlyINTEL:
156 case internal::DecorationArgumentAttributeINTEL:
157 return ExtensionID::SPV_INTEL_function_pointers;
158 case DecorationIOPipeStorageINTEL:
159 return ExtensionID::SPV_INTEL_io_pipes;
160 case DecorationBufferLocationINTEL:
161 return ExtensionID::SPV_INTEL_fpga_buffer_location;
162 case DecorationFunctionFloatingPointModeINTEL:
163 case DecorationFunctionRoundingModeINTEL:
164 case DecorationFunctionDenormModeINTEL:
165 return ExtensionID::SPV_INTEL_float_controls2;
166 case DecorationStallEnableINTEL:
167 return ExtensionID::SPV_INTEL_fpga_cluster_attributes;
168 case DecorationFuseLoopsInFunctionINTEL:
169 return ExtensionID::SPV_INTEL_loop_fuse;
170 case DecorationMathOpDSPModeINTEL:
171 return ExtensionID::SPV_INTEL_fpga_dsp_control;
172 case DecorationInitiationIntervalINTEL:
173 return ExtensionID::SPV_INTEL_fpga_invocation_pipelining_attributes;
174 case DecorationMaxConcurrencyINTEL:
175 return ExtensionID::SPV_INTEL_fpga_invocation_pipelining_attributes;
176 case DecorationPipelineEnableINTEL:
177 return ExtensionID::SPV_INTEL_fpga_invocation_pipelining_attributes;
178 case internal::DecorationRuntimeAlignedINTEL:
179 return ExtensionID::SPV_INTEL_runtime_aligned;
180 case internal::DecorationHostAccessINTEL:
181 case internal::DecorationInitModeINTEL:
182 case internal::DecorationImplementInCSRINTEL:
183 return ExtensionID::SPV_INTEL_global_variable_decorations;
184 case DecorationInitModeINTEL:
185 case DecorationImplementInRegisterMapINTEL:
186 return ExtensionID::SPV_INTEL_global_variable_fpga_decorations;
187 case DecorationHostAccessINTEL:
188 return ExtensionID::SPV_INTEL_global_variable_host_access;
189
190 case DecorationConduitKernelArgumentINTEL:
191 case DecorationRegisterMapKernelArgumentINTEL:
192 case DecorationStableKernelArgumentINTEL:
193 case DecorationMMHostInterfaceReadWriteModeINTEL:
194 case DecorationMMHostInterfaceAddressWidthINTEL:
195 case DecorationMMHostInterfaceDataWidthINTEL:
196 case DecorationMMHostInterfaceLatencyINTEL:
197 case DecorationMMHostInterfaceMaxBurstINTEL:
198 case DecorationMMHostInterfaceWaitRequestINTEL:
199 return ExtensionID::SPV_INTEL_fpga_argument_interfaces;
200 case DecorationFPMaxErrorDecorationINTEL:
201 return ExtensionID::SPV_INTEL_fp_max_error;
202 case DecorationCacheControlLoadINTEL:
203 case DecorationCacheControlStoreINTEL:
204 return ExtensionID::SPV_INTEL_cache_controls;
205 default:
206 return {};
207 }
208 }
209
210 _SPIRV_DCL_ENCDEC
211 void setWordCount(SPIRVWord) override;
212 void validate() const override {
213 SPIRVDecorateGeneric::validate();
214 assert(WordCount == Literals.size() + FixedWC);
215 }
216 };
217
218 class SPIRVDecorateString : public SPIRVDecorate {};
219
220 class SPIRVDecorateId : public SPIRVDecorateGeneric {
221 public:
222 static const Op OC = OpDecorateId;
223 static const SPIRVWord FixedWC = 3;
224 // Complete constructor for decorations with one id operand
225 SPIRVDecorateId(Decoration TheDec, SPIRVEntry *TheTarget, SPIRVId V)
226 : SPIRVDecorateGeneric(OC, 4, TheDec, TheTarget, V) {}
227 // Incomplete constructor
228 SPIRVDecorateId() : SPIRVDecorateGeneric(OC) {}
229
230 std::optional<ExtensionID> getRequiredExtension() const override {
231 switch (static_cast<int>(Dec)) {
232 case DecorationAliasScopeINTEL:
233 case DecorationNoAliasINTEL:
234 return ExtensionID::SPV_INTEL_memory_access_aliasing;
235 default:
236 return {};
237 }
238 }
239
240 _SPIRV_DCL_ENCDEC
241 void setWordCount(SPIRVWord) override;
242 void validate() const override {
243 SPIRVDecorateGeneric::validate();
244 assert(WordCount == Literals.size() + FixedWC);
245 }
246 };
247
248 class SPIRVDecorateLinkageAttr : public SPIRVDecorate {
249 public:
250 // Complete constructor for LinkageAttributes decorations
251 SPIRVDecorateLinkageAttr(SPIRVEntry *TheTarget, const std::string &Name,
252 SPIRVLinkageTypeKind Kind)
253 : SPIRVDecorate(DecorationLinkageAttributes, TheTarget) {
254 for (auto &I : getVec(Name))
255 Literals.push_back(I);
256 Literals.push_back(Kind);
257 WordCount += Literals.size();
258 }
259 // Incomplete constructor
260 SPIRVDecorateLinkageAttr() : SPIRVDecorate() {}
261
262 std::string getLinkageName() const {
263 return getString(Literals.cbegin(), Literals.cend() - 1);
264 }
265 SPIRVLinkageTypeKind getLinkageType() const {
266 return (SPIRVLinkageTypeKind)Literals.back();
267 }
268
269 static void encodeLiterals(SPIRVEncoder &Encoder,
270 const std::vector<SPIRVWord> &Literals) {
271 #ifdef _SPIRV_SUPPORT_TEXT_FMT
272 if (SPIRVUseTextFormat) {
273 Encoder << getString(Literals.cbegin(), Literals.cend() - 1);
274 Encoder << (SPIRVLinkageTypeKind)Literals.back();
275 } else
276 #endif
277 Encoder << Literals;
278 }
279
280 static void decodeLiterals(SPIRVDecoder &Decoder,
281 std::vector<SPIRVWord> &Literals) {
282 #ifdef _SPIRV_SUPPORT_TEXT_FMT
283 if (SPIRVUseTextFormat) {
284 std::string Name;
285 Decoder >> Name;
286 SPIRVLinkageTypeKind Kind;
287 Decoder >> Kind;
288 std::copy_n(getVec(Name).begin(), Literals.size() - 1, Literals.begin());
289 Literals.back() = Kind;
290 } else
291 #endif
292 Decoder >> Literals;
293 }
294
295 std::optional<ExtensionID> getRequiredExtension() const override {
296 if (getLinkageType() == SPIRVLinkageTypeKind::LinkageTypeLinkOnceODR)
297 return ExtensionID::SPV_KHR_linkonce_odr;
298 return {};
299 }
300 };
301
302 class SPIRVMemberDecorate : public SPIRVDecorateGeneric {
303 public:
304 static const Op OC = OpMemberDecorate;
305 static const SPIRVWord FixedWC = 4;
306 // Complete constructor for decorations without literals
307 SPIRVMemberDecorate(Decoration TheDec, SPIRVWord Member,
308 SPIRVEntry *TheTarget)
309 : SPIRVDecorateGeneric(OC, 4, TheDec, TheTarget), MemberNumber(Member) {}
310
311 // Complete constructor for decorations with one word literal
312 SPIRVMemberDecorate(Decoration TheDec, SPIRVWord Member,
313 SPIRVEntry *TheTarget, SPIRVWord V)
314 : SPIRVDecorateGeneric(OC, 5, TheDec, TheTarget, V),
315 MemberNumber(Member) {}
316
317 // Incomplete constructor
318 SPIRVMemberDecorate()
319 : SPIRVDecorateGeneric(OC), MemberNumber(SPIRVWORD_MAX) {}
320
321 std::optional<ExtensionID> getRequiredExtension() const override {
322 switch (static_cast<size_t>(Dec)) {
323 case DecorationRegisterINTEL:
324 case DecorationMemoryINTEL:
325 case DecorationNumbanksINTEL:
326 case DecorationBankwidthINTEL:
327 case DecorationMaxPrivateCopiesINTEL:
328 case DecorationSinglepumpINTEL:
329 case DecorationDoublepumpINTEL:
330 case DecorationMaxReplicatesINTEL:
331 case DecorationSimpleDualPortINTEL:
332 case DecorationMergeINTEL:
333 case DecorationBankBitsINTEL:
334 case DecorationForcePow2DepthINTEL:
335 return ExtensionID::SPV_INTEL_fpga_memory_attributes;
336 case DecorationBurstCoalesceINTEL:
337 case DecorationCacheSizeINTEL:
338 case DecorationDontStaticallyCoalesceINTEL:
339 case DecorationPrefetchINTEL:
340 return ExtensionID::SPV_INTEL_fpga_memory_accesses;
341 case DecorationIOPipeStorageINTEL:
342 return ExtensionID::SPV_INTEL_io_pipes;
343 case DecorationBufferLocationINTEL:
344 return ExtensionID::SPV_INTEL_fpga_buffer_location;
345 case internal::DecorationRuntimeAlignedINTEL:
346 return ExtensionID::SPV_INTEL_runtime_aligned;
347 default:
348 return {};
349 }
350 }
351
352 SPIRVWord getMemberNumber() const { return MemberNumber; }
353 std::pair<SPIRVWord, Decoration> getPair() const {
354 return std::make_pair(MemberNumber, Dec);
355 }
356
357 _SPIRV_DCL_ENCDEC
358 void setWordCount(SPIRVWord) override;
359
360 void validate() const override {
361 SPIRVDecorateGeneric::validate();
362 assert(WordCount == Literals.size() + FixedWC);
363 }
364
365 protected:
366 SPIRVWord MemberNumber;
367 };
368
369 class SPIRVMemberDecorateString : public SPIRVMemberDecorate {};
370
371 class SPIRVDecorationGroup : public SPIRVEntry {
372 public:
373 static const Op OC = OpDecorationGroup;
374 static const SPIRVWord WC = 2;
375 // Complete constructor. Does not populate Decorations.
376 SPIRVDecorationGroup(SPIRVModule *TheModule, SPIRVId TheId)
377 : SPIRVEntry(TheModule, WC, OC, TheId) {
378 validate();
379 };
380 // Incomplete constructor
381 SPIRVDecorationGroup() : SPIRVEntry(OC) {}
382 void encodeAll(spv_ostream &O) const override;
383 _SPIRV_DCL_ENCDEC
384 // Move the given decorates to the decoration group
385 void takeDecorates(SPIRVDecorateVec &Decs) {
386 Decorations = std::move(Decs);
387 for (auto &I : Decorations)
388 const_cast<SPIRVDecorateGeneric *>(I)->setOwner(this);
389 Decs.clear();
390 }
391
392 SPIRVDecorateVec &getDecorations() { return Decorations; }
393
394 protected:
395 SPIRVDecorateVec Decorations;
396 void validate() const override {
397 assert(OpCode == OC);
398 assert(WordCount == WC);
399 }
400 };
401
402 class SPIRVGroupDecorateGeneric : public SPIRVEntryNoIdGeneric {
403 public:
404 static const SPIRVWord FixedWC = 2;
405 // Complete constructor
406 SPIRVGroupDecorateGeneric(Op OC, SPIRVDecorationGroup *TheGroup,
407 const std::vector<SPIRVId> &TheTargets)
408 : SPIRVEntryNoIdGeneric(TheGroup->getModule(),
409 FixedWC + TheTargets.size(), OC),
410 DecorationGroup(TheGroup), Targets(TheTargets) {}
411 // Incomplete constructor
412 SPIRVGroupDecorateGeneric(Op OC)
413 : SPIRVEntryNoIdGeneric(OC), DecorationGroup(nullptr) {}
414
415 void setWordCount(SPIRVWord WC) override {
416 SPIRVEntryNoIdGeneric::setWordCount(WC);
417 Targets.resize(WC - FixedWC);
418 }
419 virtual void decorateTargets() = 0;
420 _SPIRV_DCL_ENCDEC
421 protected:
422 SPIRVDecorationGroup *DecorationGroup;
423 std::vector<SPIRVId> Targets;
424 };
425
426 class SPIRVGroupDecorate : public SPIRVGroupDecorateGeneric {
427 public:
428 static const Op OC = OpGroupDecorate;
429 // Complete constructor
430 SPIRVGroupDecorate(SPIRVDecorationGroup *TheGroup,
431 const std::vector<SPIRVId> &TheTargets)
432 : SPIRVGroupDecorateGeneric(OC, TheGroup, TheTargets) {}
433 // Incomplete constructor
434 SPIRVGroupDecorate() : SPIRVGroupDecorateGeneric(OC) {}
435
436 void decorateTargets() override;
437 };
438
439 class SPIRVGroupMemberDecorate : public SPIRVGroupDecorateGeneric {
440 public:
441 static const Op OC = OpGroupMemberDecorate;
442 // Complete constructor
443 SPIRVGroupMemberDecorate(SPIRVDecorationGroup *TheGroup,
444 const std::vector<SPIRVId> &TheTargets)
445 : SPIRVGroupDecorateGeneric(OC, TheGroup, TheTargets) {}
446 // Incomplete constructor
447 SPIRVGroupMemberDecorate() : SPIRVGroupDecorateGeneric(OC) {}
448
449 void decorateTargets() override;
450 };
451
452 template <Decoration D> class SPIRVDecorateStrAttrBase : public SPIRVDecorate {
453 public:
454 // Complete constructor for decoration with string literal
455 SPIRVDecorateStrAttrBase(SPIRVEntry *TheTarget, const std::string &Str)
456 : SPIRVDecorate(D, TheTarget) {
457 for (auto &I : getVec(Str))
458 Literals.push_back(I);
459 WordCount += Literals.size();
460 }
461 // Incomplete constructor
462 SPIRVDecorateStrAttrBase() : SPIRVDecorate() {}
463
464 static void encodeLiterals(SPIRVEncoder &Encoder,
465 const std::vector<SPIRVWord> &Literals) {
466 #ifdef _SPIRV_SUPPORT_TEXT_FMT
467 if (SPIRVUseTextFormat) {
468 Encoder << getString(Literals.cbegin(), Literals.cend());
469 } else
470 #endif
471 Encoder << Literals;
472 }
473
474 static void decodeLiterals(SPIRVDecoder &Decoder,
475 std::vector<SPIRVWord> &Literals) {
476 #ifdef _SPIRV_SUPPORT_TEXT_FMT
477 if (SPIRVUseTextFormat) {
478 std::string Str;
479 Decoder >> Str;
480 std::copy_n(getVec(Str).begin(), Literals.size(), Literals.begin());
481 } else
482 #endif
483 Decoder >> Literals;
484 }
485 };
486
487 class SPIRVDecorateMemoryINTELAttr
488 : public SPIRVDecorateStrAttrBase<DecorationMemoryINTEL> {
489 public:
490 // Complete constructor for MemoryINTEL decoration
491 SPIRVDecorateMemoryINTELAttr(SPIRVEntry *TheTarget,
492 const std::string &MemoryType)
493 : SPIRVDecorateStrAttrBase(TheTarget, MemoryType) {}
494 };
495
496 class SPIRVDecorateUserSemanticAttr
497 : public SPIRVDecorateStrAttrBase<DecorationUserSemantic> {
498 public:
499 // Complete constructor for UserSemantic decoration
500 SPIRVDecorateUserSemanticAttr(SPIRVEntry *TheTarget,
501 const std::string &AnnotateString)
502 : SPIRVDecorateStrAttrBase(TheTarget, AnnotateString) {}
503 };
504
505 class SPIRVDecorateMergeINTELAttr : public SPIRVDecorate {
506 public:
507 // Complete constructor for MergeINTEL decoration
508 SPIRVDecorateMergeINTELAttr(SPIRVEntry *TheTarget, const std::string &Name,
509 const std::string &Direction)
510 : SPIRVDecorate(DecorationMergeINTEL, TheTarget) {
511 for (auto &I : getVec(Name))
512 Literals.push_back(I);
513 for (auto &I : getVec(Direction))
514 Literals.push_back(I);
515 WordCount += Literals.size();
516 }
517
518 static void encodeLiterals(SPIRVEncoder &Encoder,
519 const std::vector<SPIRVWord> &Literals) {
520 #ifdef _SPIRV_SUPPORT_TEXT_FMT
521 if (SPIRVUseTextFormat) {
522 std::string FirstString = getString(Literals.cbegin(), Literals.cend());
523 Encoder << FirstString;
524 Encoder.OS << " ";
525 Encoder << getString(Literals.cbegin() + getVec(FirstString).size(),
526 Literals.cend());
527 } else
528 #endif
529 Encoder << Literals;
530 }
531
532 static void decodeLiterals(SPIRVDecoder &Decoder,
533 std::vector<SPIRVWord> &Literals) {
534 #ifdef _SPIRV_SUPPORT_TEXT_FMT
535 if (SPIRVUseTextFormat) {
536 std::string Name;
537 Decoder >> Name;
538 std::string Direction;
539 Decoder >> Direction;
540 std::string Buf = Name + ':' + Direction;
541 std::copy_n(getVec(Buf).begin(), Literals.size(), Literals.begin());
542 } else
543 #endif
544 Decoder >> Literals;
545 }
546 };
547
548 class SPIRVDecorateBankBitsINTELAttr : public SPIRVDecorate {
549 public:
550 // Complete constructor for BankBitsINTEL decoration
551 SPIRVDecorateBankBitsINTELAttr(SPIRVEntry *TheTarget,
552 const std::vector<SPIRVWord> &TheBits)
553 : SPIRVDecorate(DecorationBankBitsINTEL, TheTarget) {
554 Literals = TheBits;
555 WordCount += Literals.size();
556 }
557 };
558
559 template <Decoration D>
560 class SPIRVMemberDecorateStrAttrBase : public SPIRVMemberDecorate {
561 public:
562 // Complete constructor for decoration with string literal
563 SPIRVMemberDecorateStrAttrBase(SPIRVEntry *TheTarget, SPIRVWord MemberNumber,
564 const std::string &Str)
565 : SPIRVMemberDecorate(D, MemberNumber, TheTarget) {
566 for (auto &I : getVec(Str))
567 Literals.push_back(I);
568 WordCount += Literals.size();
569 }
570 // Incomplete constructor
571 SPIRVMemberDecorateStrAttrBase() : SPIRVMemberDecorate() {}
572 };
573
574 class SPIRVMemberDecorateMemoryINTELAttr
575 : public SPIRVMemberDecorateStrAttrBase<DecorationMemoryINTEL> {
576 public:
577 // Complete constructor for MemoryINTEL decoration
578 SPIRVMemberDecorateMemoryINTELAttr(SPIRVEntry *TheTarget,
579 SPIRVWord MemberNumber,
580 const std::string &MemoryType)
581 : SPIRVMemberDecorateStrAttrBase(TheTarget, MemberNumber, MemoryType) {}
582 };
583
584 class SPIRVMemberDecorateUserSemanticAttr
585 : public SPIRVMemberDecorateStrAttrBase<DecorationUserSemantic> {
586 public:
587 // Complete constructor for UserSemantic decoration
588 SPIRVMemberDecorateUserSemanticAttr(SPIRVEntry *TheTarget,
589 SPIRVWord MemberNumber,
590 const std::string &AnnotateString)
591 : SPIRVMemberDecorateStrAttrBase(TheTarget, MemberNumber,
592 AnnotateString) {}
593 };
594
595 class SPIRVMemberDecorateMergeINTELAttr : public SPIRVMemberDecorate {
596 public:
597 // Complete constructor for MergeINTEL decoration
598 SPIRVMemberDecorateMergeINTELAttr(SPIRVEntry *TheTarget,
599 SPIRVWord MemberNumber,
600 const std::string &Name,
601 const std::string &Direction)
602 : SPIRVMemberDecorate(DecorationMergeINTEL, MemberNumber, TheTarget) {
603 for (auto &I : getVec(Name))
604 Literals.push_back(I);
605 for (auto &I : getVec(Direction))
606 Literals.push_back(I);
607 WordCount += Literals.size();
608 }
609 };
610
611 class SPIRVMemberDecorateBankBitsINTELAttr : public SPIRVMemberDecorate {
612 public:
613 // Complete constructor for BankBitsINTEL decoration
614 SPIRVMemberDecorateBankBitsINTELAttr(SPIRVEntry *TheTarget,
615 SPIRVWord MemberNumber,
616 const std::vector<SPIRVWord> &TheBits)
617 : SPIRVMemberDecorate(DecorationBankBitsINTEL, MemberNumber, TheTarget) {
618 Literals = TheBits;
619 WordCount += Literals.size();
620 }
621 };
622
623 class SPIRVDecorateFunctionRoundingModeINTEL : public SPIRVDecorate {
624 public:
625 // Complete constructor for SPIRVDecorateFunctionRoundingModeINTEL
626 SPIRVDecorateFunctionRoundingModeINTEL(SPIRVEntry *TheTarget,
627 SPIRVWord TargetWidth,
628 spv::FPRoundingMode FloatControl)
629 : SPIRVDecorate(spv::DecorationFunctionRoundingModeINTEL, TheTarget,
630 TargetWidth, static_cast<SPIRVWord>(FloatControl)){};
631
632 SPIRVWord getTargetWidth() const { return Literals.at(0); };
633 spv::FPRoundingMode getRoundingMode() const {
634 return static_cast<spv::FPRoundingMode>(Literals.at(1));
635 };
636 };
637
638 class SPIRVDecorateFunctionDenormModeINTEL : public SPIRVDecorate {
639 public:
640 // Complete constructor for SPIRVDecorateFunctionDenormModeINTEL
641 SPIRVDecorateFunctionDenormModeINTEL(SPIRVEntry *TheTarget,
642 SPIRVWord TargetWidth,
643 spv::FPDenormMode FloatControl)
644 : SPIRVDecorate(spv::DecorationFunctionDenormModeINTEL, TheTarget,
645 TargetWidth, static_cast<SPIRVWord>(FloatControl)){};
646
647 SPIRVWord getTargetWidth() const { return Literals.at(0); };
648 spv::FPDenormMode getDenormMode() const {
649 return static_cast<spv::FPDenormMode>(Literals.at(1));
650 };
651 };
652
653 class SPIRVDecorateFunctionFloatingPointModeINTEL : public SPIRVDecorate {
654 public:
655 // Complete constructor for SPIRVDecorateFunctionOperationModeINTEL
656 SPIRVDecorateFunctionFloatingPointModeINTEL(SPIRVEntry *TheTarget,
657 SPIRVWord TargetWidth,
658 spv::FPOperationMode FloatControl)
659 : SPIRVDecorate(spv::DecorationFunctionFloatingPointModeINTEL, TheTarget,
660 TargetWidth, static_cast<SPIRVWord>(FloatControl)){};
661
662 SPIRVWord getTargetWidth() const { return Literals.at(0); };
663 spv::FPOperationMode getOperationMode() const {
664 return static_cast<spv::FPOperationMode>(Literals.at(1));
665 };
666 };
667
668 class SPIRVDecorateStallEnableINTEL : public SPIRVDecorate {
669 public:
670 // Complete constructor for SPIRVDecorateStallEnableINTEL
671 SPIRVDecorateStallEnableINTEL(SPIRVEntry *TheTarget)
672 : SPIRVDecorate(spv::DecorationStallEnableINTEL, TheTarget){};
673 };
674
675 class SPIRVDecorateFuseLoopsInFunctionINTEL : public SPIRVDecorate {
676 public:
677 // Complete constructor for SPIRVDecorateFuseLoopsInFunctionINTEL
678 SPIRVDecorateFuseLoopsInFunctionINTEL(SPIRVEntry *TheTarget, SPIRVWord Depth,
679 SPIRVWord Independent)
680 : SPIRVDecorate(spv::DecorationFuseLoopsInFunctionINTEL, TheTarget, Depth,
681 Independent){};
682 };
683
684 class SPIRVDecorateMathOpDSPModeINTEL : public SPIRVDecorate {
685 public:
686 // Complete constructor for SPIRVDecorateMathOpDSPModeINTEL
687 SPIRVDecorateMathOpDSPModeINTEL(SPIRVEntry *TheTarget, SPIRVWord Mode,
688 SPIRVWord Propagate)
689 : SPIRVDecorate(spv::DecorationMathOpDSPModeINTEL, TheTarget, Mode,
690 Propagate){};
691 };
692
693 class SPIRVDecorateAliasScopeINTEL : public SPIRVDecorateId {
694 public:
695 // Complete constructor for SPIRVDecorateAliasScopeINTEL
696 SPIRVDecorateAliasScopeINTEL(SPIRVEntry *TheTarget, SPIRVId AliasList)
697 : SPIRVDecorateId(spv::DecorationAliasScopeINTEL, TheTarget, AliasList){};
698 };
699
700 class SPIRVDecorateNoAliasINTEL : public SPIRVDecorateId {
701 public:
702 // Complete constructor for SPIRVDecorateNoAliasINTEL
703 SPIRVDecorateNoAliasINTEL(SPIRVEntry *TheTarget, SPIRVId AliasList)
704 : SPIRVDecorateId(spv::DecorationNoAliasINTEL, TheTarget, AliasList){};
705 };
706
707 class SPIRVDecorateInitiationIntervalINTEL : public SPIRVDecorate {
708 public:
709 // Complete constructor for SPIRVDecorateInitiationIntervalINTEL
710 SPIRVDecorateInitiationIntervalINTEL(SPIRVEntry *TheTarget, SPIRVWord Cycles)
711 : SPIRVDecorate(spv::DecorationInitiationIntervalINTEL, TheTarget,
712 Cycles){};
713 };
714
715 class SPIRVDecorateMaxConcurrencyINTEL : public SPIRVDecorate {
716 public:
717 // Complete constructor for SPIRVDecorateMaxConcurrencyINTEL
718 SPIRVDecorateMaxConcurrencyINTEL(SPIRVEntry *TheTarget, SPIRVWord Invocations)
719 : SPIRVDecorate(spv::DecorationMaxConcurrencyINTEL, TheTarget,
720 Invocations){};
721 };
722
723 class SPIRVDecoratePipelineEnableINTEL : public SPIRVDecorate {
724 public:
725 // Complete constructor for SPIRVDecoratePipelineEnableINTEL
726 SPIRVDecoratePipelineEnableINTEL(SPIRVEntry *TheTarget, SPIRVWord Enable)
727 : SPIRVDecorate(spv::DecorationPipelineEnableINTEL, TheTarget, Enable){};
728 };
729
730 class SPIRVDecorateHostAccessINTELBase : public SPIRVDecorate {
731 public:
732 // Complete constructor for SPIRVHostAccessINTEL
733 SPIRVDecorateHostAccessINTELBase(Decoration D, SPIRVEntry *TheTarget,
734 HostAccessQualifier AccessMode,
735 const std::string &VarName)
736 : SPIRVDecorate(D, TheTarget) {
737 Literals.push_back(AccessMode);
738 for (auto &I : getVec(VarName))
739 Literals.push_back(I);
740 WordCount += Literals.size();
741 };
742
743 SPIRVWord getAccessMode() const { return Literals.front(); }
744 std::string getVarName() const {
745 return getString(Literals.cbegin() + 1, Literals.cend());
746 }
747 };
748
749 class SPIRVDecorateHostAccessINTEL : public SPIRVDecorateHostAccessINTELBase {
750 public:
751 SPIRVDecorateHostAccessINTEL(SPIRVEntry *TheTarget,
752 HostAccessQualifier AccessMode,
753 const std::string &VarName)
754 : SPIRVDecorateHostAccessINTELBase(DecorationHostAccessINTEL, TheTarget,
755 AccessMode, VarName) {}
756 static void encodeLiterals(SPIRVEncoder &Encoder,
757 const std::vector<SPIRVWord> &Literals) {
758 #ifdef _SPIRV_SUPPORT_TEXT_FMT
759 if (SPIRVUseTextFormat) {
760 Encoder << (HostAccessQualifier)Literals.front();
761 std::string Name = getString(Literals.cbegin() + 1, Literals.cend());
762 Encoder << Name;
763 } else
764 #endif
765 Encoder << Literals;
766 }
767
768 static void decodeLiterals(SPIRVDecoder &Decoder,
769 std::vector<SPIRVWord> &Literals) {
770 #ifdef _SPIRV_SUPPORT_TEXT_FMT
771 if (SPIRVUseTextFormat) {
772 HostAccessQualifier Mode;
773 Decoder >> Mode;
774 std::string Name;
775 Decoder >> Name;
776 Literals.front() = Mode;
777 std::copy_n(getVec(Name).begin(), Literals.size() - 1,
778 Literals.begin() + 1);
779
780 } else
781 #endif
782 Decoder >> Literals;
783 }
784 };
785
786 class SPIRVDecorateHostAccessINTELLegacy
787 : public SPIRVDecorateHostAccessINTELBase {
788 public:
789 SPIRVDecorateHostAccessINTELLegacy(SPIRVEntry *TheTarget,
790 HostAccessQualifier AccessMode,
791 const std::string &VarName)
792 : SPIRVDecorateHostAccessINTELBase(internal::DecorationHostAccessINTEL,
793 TheTarget, AccessMode, VarName) {}
794 static void encodeLiterals(SPIRVEncoder &Encoder,
795 const std::vector<SPIRVWord> &Literals) {
796 #ifdef _SPIRV_SUPPORT_TEXT_FMT
797 if (SPIRVUseTextFormat) {
798 Encoder << Literals.front();
799 std::string Name = getString(Literals.cbegin() + 1, Literals.cend());
800 Encoder << Name;
801 } else
802 #endif
803 Encoder << Literals;
804 }
805
806 static void decodeLiterals(SPIRVDecoder &Decoder,
807 std::vector<SPIRVWord> &Literals) {
808 #ifdef _SPIRV_SUPPORT_TEXT_FMT
809 if (SPIRVUseTextFormat) {
810 SPIRVWord Mode;
811 Decoder >> Mode;
812 std::string Name;
813 Decoder >> Name;
814 Literals.front() = Mode;
815 std::copy_n(getVec(Name).begin(), Literals.size() - 1,
816 Literals.begin() + 1);
817
818 } else
819 #endif
820 Decoder >> Literals;
821 }
822 };
823
824 class SPIRVDecorateInitModeINTELBase : public SPIRVDecorate {
825 public:
826 // Complete constructor for SPIRVInitModeINTEL
827 SPIRVDecorateInitModeINTELBase(Decoration D, SPIRVEntry *TheTarget,
828 InitializationModeQualifier Trigger)
829 : SPIRVDecorate(D, TheTarget) {
830 Literals.push_back(Trigger);
831 WordCount += Literals.size();
832 }
833 };
834
835 class SPIRVDecorateInitModeINTEL : public SPIRVDecorateInitModeINTELBase {
836 public:
837 SPIRVDecorateInitModeINTEL(SPIRVEntry *TheTarget,
838 InitializationModeQualifier Trigger)
839 : SPIRVDecorateInitModeINTELBase(DecorationInitModeINTEL, TheTarget,
840 Trigger) {}
841
842 static void encodeLiterals(SPIRVEncoder &Encoder,
843 const std::vector<SPIRVWord> &Literals) {
844 #ifdef _SPIRV_SUPPORT_TEXT_FMT
845 if (SPIRVUseTextFormat) {
846 Encoder << (InitializationModeQualifier)Literals.back();
847 } else
848 #endif
849 Encoder << Literals;
850 }
851
852 static void decodeLiterals(SPIRVDecoder &Decoder,
853 std::vector<SPIRVWord> &Literals) {
854 #ifdef _SPIRV_SUPPORT_TEXT_FMT
855 if (SPIRVUseTextFormat) {
856 InitializationModeQualifier Q;
857 Decoder >> Q;
858 Literals.back() = Q;
859 } else
860 #endif
861 Decoder >> Literals;
862 }
863 };
864
865 class SPIRVDecorateInitModeINTELLegacy : public SPIRVDecorateInitModeINTELBase {
866 public:
867 SPIRVDecorateInitModeINTELLegacy(SPIRVEntry *TheTarget,
868 InitializationModeQualifier Trigger)
869 : SPIRVDecorateInitModeINTELBase(internal::DecorationInitModeINTEL,
870 TheTarget, Trigger) {}
871
872 static void encodeLiterals(SPIRVEncoder &Encoder,
873 const std::vector<SPIRVWord> &Literals) {
874 #ifdef _SPIRV_SUPPORT_TEXT_FMT
875 if (SPIRVUseTextFormat) {
876 Encoder << Literals.back();
877 } else
878 #endif
879 Encoder << Literals;
880 }
881
882 static void decodeLiterals(SPIRVDecoder &Decoder,
883 std::vector<SPIRVWord> &Literals) {
884 #ifdef _SPIRV_SUPPORT_TEXT_FMT
885 if (SPIRVUseTextFormat) {
886 SPIRVWord Q;
887 Decoder >> Q;
888 Literals.back() = Q;
889 } else
890 #endif
891 Decoder >> Literals;
892 }
893 };
894
895 class SPIRVDecorateImplementInCSRINTEL : public SPIRVDecorate {
896 public:
897 // Complete constructor for SPIRVImplementInCSRINTEL
898 SPIRVDecorateImplementInCSRINTEL(SPIRVEntry *TheTarget, SPIRVWord Value)
899 : SPIRVDecorate(spv::internal::DecorationImplementInCSRINTEL, TheTarget,
900 Value) {}
901 };
902
903 class SPIRVDecorateImplementInRegisterMapINTEL : public SPIRVDecorate {
904 public:
905 // Complete constructor for SPIRVImplementInCSRINTEL
906 SPIRVDecorateImplementInRegisterMapINTEL(SPIRVEntry *TheTarget,
907 SPIRVWord Value)
908 : SPIRVDecorate(DecorationImplementInRegisterMapINTEL, TheTarget, Value) {
909 }
910 };
911
912 class SPIRVDecorateCacheControlLoadINTEL : public SPIRVDecorate {
913 public:
914 // Complete constructor for SPIRVDecorateCacheControlLoadINTEL
915 SPIRVDecorateCacheControlLoadINTEL(SPIRVEntry *TheTarget,
916 SPIRVWord CacheLevel,
917 LoadCacheControl CacheControl)
918 : SPIRVDecorate(DecorationCacheControlLoadINTEL, TheTarget, CacheLevel,
919 static_cast<SPIRVWord>(CacheControl)) {}
920
921 SPIRVWord getCacheLevel() const { return Literals.at(0); }
922 LoadCacheControl getCacheControl() const {
923 return static_cast<LoadCacheControl>(Literals.at(1));
924 }
925 };
926
927 class SPIRVDecorateCacheControlStoreINTEL : public SPIRVDecorate {
928 public:
929 // Complete constructor for SPIRVDecorateCacheControlStoreINTEL
930 SPIRVDecorateCacheControlStoreINTEL(SPIRVEntry *TheTarget,
931 SPIRVWord CacheLevel,
932 StoreCacheControl CacheControl)
933 : SPIRVDecorate(DecorationCacheControlStoreINTEL, TheTarget, CacheLevel,
934 static_cast<SPIRVWord>(CacheControl)) {}
935
936 SPIRVWord getCacheLevel() const { return Literals.at(0); }
937 StoreCacheControl getCacheControl() const {
938 return static_cast<StoreCacheControl>(Literals.at(1));
939 }
940 };
941
942 } // namespace SPIRV
943
944 #endif // SPIRV_LIBSPIRV_SPIRVDECORATE_H