MLIR 24.0.0git
SPIRVAttributes.cpp
Go to the documentation of this file.
1//===- SPIRVAttributes.cpp - SPIR-V attribute definitions -----------------===//
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
12#include "mlir/IR/Builders.h"
14#include "llvm/ADT/TypeSwitch.h"
15#include "llvm/Support/InterleavedRange.h"
16
17using namespace mlir;
18using namespace mlir::spirv;
19
20//===----------------------------------------------------------------------===//
21// TableGen'erated attribute utility functions
22//===----------------------------------------------------------------------===//
23
24namespace mlir {
25namespace spirv {
26#include "mlir/Dialect/SPIRV/IR/SPIRVAttrUtils.inc"
27} // namespace spirv
28
29//===----------------------------------------------------------------------===//
30// Attribute storage classes
31//===----------------------------------------------------------------------===//
32
33namespace spirv {
34namespace detail {
35
37 using KeyTy = std::tuple<Attribute, Attribute, Attribute>;
38
43
44 bool operator==(const KeyTy &key) const {
45 return std::get<0>(key) == descriptorSet && std::get<1>(key) == binding &&
46 std::get<2>(key) == storageClass;
47 }
48
50 construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
51 return new (allocator.allocate<InterfaceVarABIAttributeStorage>())
52 InterfaceVarABIAttributeStorage(std::get<0>(key), std::get<1>(key),
53 std::get<2>(key));
54 }
55
59};
60
62 using KeyTy = std::tuple<Attribute, Attribute, Attribute>;
63
67
68 bool operator==(const KeyTy &key) const {
69 return std::get<0>(key) == version && std::get<1>(key) == capabilities &&
70 std::get<2>(key) == extensions;
71 }
72
74 construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
75 return new (allocator.allocate<VerCapExtAttributeStorage>())
76 VerCapExtAttributeStorage(std::get<0>(key), std::get<1>(key),
77 std::get<2>(key));
78 }
79
83};
84
86 using KeyTy =
87 std::tuple<Attribute, ClientAPI, Vendor, DeviceType, uint32_t, Attribute>;
88
94
95 bool operator==(const KeyTy &key) const {
96 return key == std::make_tuple(triple, clientAPI, vendorID, deviceType,
98 }
99
101 construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
102 return new (allocator.allocate<TargetEnvAttributeStorage>())
103 TargetEnvAttributeStorage(std::get<0>(key), std::get<1>(key),
104 std::get<2>(key), std::get<3>(key),
105 std::get<4>(key), std::get<5>(key));
106 }
107
110 ClientAPI clientAPI;
111 Vendor vendorID;
112 DeviceType deviceType;
113 uint32_t deviceID;
114};
115} // namespace detail
116} // namespace spirv
117} // namespace mlir
118
119//===----------------------------------------------------------------------===//
120// EntryPointABIAttr
121//===----------------------------------------------------------------------===//
122
123LogicalResult
124spirv::EntryPointABIAttr::verify(function_ref<InFlightDiagnostic()> emitError,
125 DenseI32ArrayAttr workgroupSize,
126 std::optional<int> subgroupSize,
127 std::optional<int> targetWidth) {
128 if (!workgroupSize)
129 return success();
130 if (workgroupSize.size() != 3)
131 return emitError() << "expected 3 workgroup size values, but got "
132 << workgroupSize.size();
133 if (llvm::any_of(workgroupSize.asArrayRef(),
134 [](int32_t v) { return v <= 0; }))
135 return emitError() << "expected positive workgroup size values";
136 return success();
137}
138
139//===----------------------------------------------------------------------===//
140// InterfaceVarABIAttr
141//===----------------------------------------------------------------------===//
142
144spirv::InterfaceVarABIAttr::get(uint32_t descriptorSet, uint32_t binding,
145 std::optional<spirv::StorageClass> storageClass,
146 MLIRContext *context) {
147 Builder b(context);
148 auto descriptorSetAttr = b.getI32IntegerAttr(descriptorSet);
149 auto bindingAttr = b.getI32IntegerAttr(binding);
150 auto storageClassAttr =
151 storageClass ? b.getI32IntegerAttr(static_cast<uint32_t>(*storageClass))
152 : IntegerAttr();
153 return get(descriptorSetAttr, bindingAttr, storageClassAttr);
154}
155
156spirv::InterfaceVarABIAttr
157spirv::InterfaceVarABIAttr::get(IntegerAttr descriptorSet, IntegerAttr binding,
158 IntegerAttr storageClass) {
159 assert(descriptorSet && binding);
160 MLIRContext *context = descriptorSet.getContext();
161 return Base::get(context, descriptorSet, binding, storageClass);
162}
163
165 return "interface_var_abi";
166}
167
169 return cast<IntegerAttr>(getImpl()->binding).getInt();
170}
171
173 return cast<IntegerAttr>(getImpl()->descriptorSet).getInt();
174}
175
176std::optional<spirv::StorageClass>
178 if (getImpl()->storageClass)
179 return static_cast<spirv::StorageClass>(
180 cast<IntegerAttr>(getImpl()->storageClass).getValue().getZExtValue());
181 return std::nullopt;
182}
183
185 function_ref<InFlightDiagnostic()> emitError, IntegerAttr descriptorSet,
186 IntegerAttr binding, IntegerAttr storageClass) {
187 if (!descriptorSet.getType().isSignlessInteger(32))
188 return emitError() << "expected 32-bit integer for descriptor set";
189
190 if (!binding.getType().isSignlessInteger(32))
191 return emitError() << "expected 32-bit integer for binding";
192
193 if (storageClass) {
194 if (auto storageClassAttr = cast<IntegerAttr>(storageClass)) {
195 auto storageClassValue =
196 spirv::symbolizeStorageClass(storageClassAttr.getInt());
197 if (!storageClassValue)
198 return emitError() << "unknown storage class";
199 } else {
200 return emitError() << "expected valid storage class";
201 }
202 }
203
204 return success();
205}
206
207//===----------------------------------------------------------------------===//
208// VerCapExtAttr
209//===----------------------------------------------------------------------===//
210
212 spirv::Version version, ArrayRef<spirv::Capability> capabilities,
213 ArrayRef<spirv::Extension> extensions, MLIRContext *context) {
214 Builder b(context);
215
216 auto versionAttr = b.getI32IntegerAttr(static_cast<uint32_t>(version));
217
219 capAttrs.reserve(capabilities.size());
220 for (spirv::Capability cap : capabilities)
221 capAttrs.push_back(b.getI32IntegerAttr(static_cast<uint32_t>(cap)));
222
224 extAttrs.reserve(extensions.size());
225 for (spirv::Extension ext : extensions)
226 extAttrs.push_back(b.getStringAttr(spirv::stringifyExtension(ext)));
227
228 return get(versionAttr, b.getArrayAttr(capAttrs), b.getArrayAttr(extAttrs));
229}
230
232 ArrayAttr capabilities,
233 ArrayAttr extensions) {
234 assert(version && capabilities && extensions);
235 MLIRContext *context = version.getContext();
236 return Base::get(context, version, capabilities, extensions);
237}
238
239StringRef spirv::VerCapExtAttr::getKindName() { return "vce"; }
240
242 return static_cast<spirv::Version>(
243 cast<IntegerAttr>(getImpl()->version).getValue().getZExtValue());
244}
245
247 : llvm::mapped_iterator<ArrayAttr::iterator,
248 spirv::Extension (*)(Attribute)>(
249 it, [](Attribute attr) {
250 return *symbolizeExtension(cast<StringAttr>(attr).getValue());
251 }) {}
252
254 auto range = getExtensionsAttr().getValue();
255 return {ext_iterator(range.begin()), ext_iterator(range.end())};
256}
257
259 return cast<ArrayAttr>(getImpl()->extensions);
260}
261
263 : llvm::mapped_iterator<ArrayAttr::iterator,
264 spirv::Capability (*)(Attribute)>(
265 it, [](Attribute attr) {
266 return *symbolizeCapability(
267 cast<IntegerAttr>(attr).getValue().getZExtValue());
268 }) {}
269
271 auto range = getCapabilitiesAttr().getValue();
272 return {cap_iterator(range.begin()), cap_iterator(range.end())};
273}
274
276 return cast<ArrayAttr>(getImpl()->capabilities);
277}
278
280 function_ref<InFlightDiagnostic()> emitError, IntegerAttr version,
281 ArrayAttr capabilities, ArrayAttr extensions) {
282 if (!version.getType().isSignlessInteger(32))
283 return emitError() << "expected 32-bit integer for version";
284
285 if (!llvm::all_of(capabilities.getValue(), [](Attribute attr) {
286 if (auto intAttr = dyn_cast<IntegerAttr>(attr))
287 if (spirv::symbolizeCapability(intAttr.getValue().getZExtValue()))
288 return true;
289 return false;
290 }))
291 return emitError() << "unknown capability in capability list";
292
293 if (!llvm::all_of(extensions.getValue(), [](Attribute attr) {
294 if (auto strAttr = dyn_cast<StringAttr>(attr))
295 if (spirv::symbolizeExtension(strAttr.getValue()))
296 return true;
297 return false;
298 }))
299 return emitError() << "unknown extension in extension list";
300
301 return success();
302}
303
304//===----------------------------------------------------------------------===//
305// TargetEnvAttr
306//===----------------------------------------------------------------------===//
307
309 spirv::VerCapExtAttr triple, ResourceLimitsAttr limits, ClientAPI clientAPI,
310 Vendor vendorID, DeviceType deviceType, uint32_t deviceID) {
311 assert(triple && limits && "expected valid triple and limits");
312 MLIRContext *context = triple.getContext();
313 return Base::get(context, triple, clientAPI, vendorID, deviceType, deviceID,
314 limits);
315}
316
317StringRef spirv::TargetEnvAttr::getKindName() { return "target_env"; }
318
320 return cast<spirv::VerCapExtAttr>(getImpl()->triple);
321}
322
323spirv::Version spirv::TargetEnvAttr::getVersion() const {
324 return getTripleAttr().getVersion();
325}
326
330
332 return getTripleAttr().getExtensionsAttr();
333}
334
338
340 return getTripleAttr().getCapabilitiesAttr();
341}
342
343spirv::ClientAPI spirv::TargetEnvAttr::getClientAPI() const {
344 return getImpl()->clientAPI;
345}
346
348 return getImpl()->vendorID;
349}
350
351spirv::DeviceType spirv::TargetEnvAttr::getDeviceType() const {
352 return getImpl()->deviceType;
353}
354
356 return getImpl()->deviceID;
357}
358
359spirv::ResourceLimitsAttr spirv::TargetEnvAttr::getResourceLimits() const {
360 return cast<spirv::ResourceLimitsAttr>(getImpl()->limits);
361}
362
363//===----------------------------------------------------------------------===//
364// ODS Generated Attributes
365//===----------------------------------------------------------------------===//
366
367#define GET_ATTRDEF_CLASSES
368#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.cpp.inc"
369
370//===----------------------------------------------------------------------===//
371// Attribute Parsing
372//===----------------------------------------------------------------------===//
373
374/// Parses a comma-separated list of keywords, invokes `processKeyword` on each
375/// of the parsed keyword, and returns failure if any error occurs.
376static ParseResult
378 function_ref<LogicalResult(SMLoc, StringRef)> processKeyword) {
379 if (parser.parseLSquare())
380 return failure();
381
382 // Special case for empty list.
383 if (succeeded(parser.parseOptionalRSquare()))
384 return success();
385
386 // Keep parsing the keyword and an optional comma following it. If the comma
387 // is successfully parsed, then we have more keywords to parse.
388 if (failed(parser.parseCommaSeparatedList([&]() {
389 auto loc = parser.getCurrentLocation();
390 StringRef keyword;
391 if (parser.parseKeyword(&keyword) ||
392 failed(processKeyword(loc, keyword)))
393 return failure();
394 return success();
395 })))
396 return failure();
397 return parser.parseRSquare();
398}
399
400/// Parses a spirv::InterfaceVarABIAttr.
402 if (parser.parseLess())
403 return {};
404
405 Builder &builder = parser.getBuilder();
406
407 if (parser.parseLParen())
408 return {};
409
410 IntegerAttr descriptorSetAttr;
411 {
412 auto loc = parser.getCurrentLocation();
413 uint32_t descriptorSet = 0;
414 auto descriptorSetParseResult = parser.parseOptionalInteger(descriptorSet);
415
416 if (!descriptorSetParseResult.has_value() ||
417 failed(*descriptorSetParseResult)) {
418 parser.emitError(loc, "missing descriptor set");
419 return {};
420 }
421 descriptorSetAttr = builder.getI32IntegerAttr(descriptorSet);
422 }
423
424 if (parser.parseComma())
425 return {};
426
427 IntegerAttr bindingAttr;
428 {
429 auto loc = parser.getCurrentLocation();
430 uint32_t binding = 0;
431 auto bindingParseResult = parser.parseOptionalInteger(binding);
432
433 if (!bindingParseResult.has_value() || failed(*bindingParseResult)) {
434 parser.emitError(loc, "missing binding");
435 return {};
436 }
437 bindingAttr = builder.getI32IntegerAttr(binding);
438 }
439
440 if (parser.parseRParen())
441 return {};
442
443 IntegerAttr storageClassAttr;
444 {
445 if (succeeded(parser.parseOptionalComma())) {
446 auto loc = parser.getCurrentLocation();
447 StringRef storageClass;
448 if (parser.parseKeyword(&storageClass))
449 return {};
450
451 if (auto storageClassSymbol =
452 spirv::symbolizeStorageClass(storageClass)) {
453 storageClassAttr = builder.getI32IntegerAttr(
454 static_cast<uint32_t>(*storageClassSymbol));
455 } else {
456 parser.emitError(loc, "unknown storage class: ") << storageClass;
457 return {};
458 }
459 }
460 }
461
462 if (parser.parseGreater())
463 return {};
464
465 return spirv::InterfaceVarABIAttr::get(descriptorSetAttr, bindingAttr,
466 storageClassAttr);
467}
468
470 if (parser.parseLess())
471 return {};
472
473 Builder &builder = parser.getBuilder();
474
475 IntegerAttr versionAttr;
476 {
477 auto loc = parser.getCurrentLocation();
478 StringRef version;
479 if (parser.parseKeyword(&version) || parser.parseComma())
480 return {};
481
482 if (auto versionSymbol = spirv::symbolizeVersion(version)) {
483 versionAttr =
484 builder.getI32IntegerAttr(static_cast<uint32_t>(*versionSymbol));
485 } else {
486 parser.emitError(loc, "unknown version: ") << version;
487 return {};
488 }
489 }
490
491 ArrayAttr capabilitiesAttr;
492 {
493 SmallVector<Attribute, 4> capabilities;
494 SMLoc errorloc;
495 StringRef errorKeyword;
496
497 auto processCapability = [&](SMLoc loc, StringRef capability) {
498 if (auto capSymbol = spirv::symbolizeCapability(capability)) {
499 capabilities.push_back(
500 builder.getI32IntegerAttr(static_cast<uint32_t>(*capSymbol)));
501 return success();
502 }
503 return errorloc = loc, errorKeyword = capability, failure();
504 };
505 if (parseKeywordList(parser, processCapability) || parser.parseComma()) {
506 if (!errorKeyword.empty())
507 parser.emitError(errorloc, "unknown capability: ") << errorKeyword;
508 return {};
509 }
510
511 capabilitiesAttr = builder.getArrayAttr(capabilities);
512 }
513
514 ArrayAttr extensionsAttr;
515 {
516 SmallVector<Attribute, 1> extensions;
517 SMLoc errorloc;
518 StringRef errorKeyword;
519
520 auto processExtension = [&](SMLoc loc, StringRef extension) {
521 if (spirv::symbolizeExtension(extension)) {
522 extensions.push_back(builder.getStringAttr(extension));
523 return success();
524 }
525 return errorloc = loc, errorKeyword = extension, failure();
526 };
527 if (parseKeywordList(parser, processExtension)) {
528 if (!errorKeyword.empty())
529 parser.emitError(errorloc, "unknown extension: ") << errorKeyword;
530 return {};
531 }
532
533 extensionsAttr = builder.getArrayAttr(extensions);
534 }
535
536 if (parser.parseGreater())
537 return {};
538
539 return spirv::VerCapExtAttr::get(versionAttr, capabilitiesAttr,
540 extensionsAttr);
541}
542
543/// Parses a spirv::TargetEnvAttr.
545 if (parser.parseLess())
546 return {};
547
548 spirv::VerCapExtAttr tripleAttr;
549 if (parser.parseAttribute(tripleAttr) || parser.parseComma())
550 return {};
551
552 auto clientAPI = spirv::ClientAPI::Unknown;
553 if (succeeded(parser.parseOptionalKeyword("api"))) {
554 if (parser.parseEqual())
555 return {};
556 auto loc = parser.getCurrentLocation();
557 StringRef apiStr;
558 if (parser.parseKeyword(&apiStr))
559 return {};
560 if (auto apiSymbol = spirv::symbolizeClientAPI(apiStr))
561 clientAPI = *apiSymbol;
562 else
563 parser.emitError(loc, "unknown client API: ") << apiStr;
564 if (parser.parseComma())
565 return {};
566 }
567
568 // Parse [vendor[:device-type[:device-id]]]
569 Vendor vendorID = Vendor::Unknown;
570 DeviceType deviceType = DeviceType::Unknown;
571 uint32_t deviceID = spirv::TargetEnvAttr::kUnknownDeviceID;
572 {
573 auto loc = parser.getCurrentLocation();
574 StringRef vendorStr;
575 if (succeeded(parser.parseOptionalKeyword(&vendorStr))) {
576 if (auto vendorSymbol = spirv::symbolizeVendor(vendorStr))
577 vendorID = *vendorSymbol;
578 else
579 parser.emitError(loc, "unknown vendor: ") << vendorStr;
580
581 if (succeeded(parser.parseOptionalColon())) {
582 loc = parser.getCurrentLocation();
583 StringRef deviceTypeStr;
584 if (parser.parseKeyword(&deviceTypeStr))
585 return {};
586 if (auto deviceTypeSymbol = spirv::symbolizeDeviceType(deviceTypeStr))
587 deviceType = *deviceTypeSymbol;
588 else
589 parser.emitError(loc, "unknown device type: ") << deviceTypeStr;
590
591 if (succeeded(parser.parseOptionalColon())) {
592 loc = parser.getCurrentLocation();
593 if (parser.parseInteger(deviceID))
594 return {};
595 }
596 }
597 if (parser.parseComma())
598 return {};
599 }
600 }
601
602 ResourceLimitsAttr limitsAttr;
603 if (parser.parseAttribute(limitsAttr) || parser.parseGreater())
604 return {};
605
606 return spirv::TargetEnvAttr::get(tripleAttr, limitsAttr, clientAPI, vendorID,
607 deviceType, deviceID);
608}
609
610Attribute SPIRVDialect::parseAttribute(DialectAsmParser &parser,
611 Type type) const {
612 // Parse the kind keyword first.
613 StringRef attrKind;
614 Attribute attr;
615 OptionalParseResult result =
616 generatedAttributeParser(parser, &attrKind, type, attr);
617 if (result.has_value()) {
618 if (type && attr && !isa<TypedAttr>(attr)) {
619 parser.emitError(parser.getNameLoc(), "unexpected type");
620 return {};
621 }
622 return attr;
623 }
624
625 // The remaining SPIR-V attributes are dictionaries so they do not have type.
626 if (type) {
627 parser.emitError(parser.getNameLoc(), "unexpected type");
628 return {};
629 }
630
631 if (attrKind == spirv::TargetEnvAttr::getKindName())
632 return parseTargetEnvAttr(parser);
633 if (attrKind == spirv::VerCapExtAttr::getKindName())
634 return parseVerCapExtAttr(parser);
636 return parseInterfaceVarABIAttr(parser);
637
638 parser.emitError(parser.getNameLoc(), "unknown SPIR-V attribute kind: ")
639 << attrKind;
640 return {};
641}
642
643//===----------------------------------------------------------------------===//
644// Attribute Printing
645//===----------------------------------------------------------------------===//
646
647static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer) {
648 printer << spirv::VerCapExtAttr::getKindName() << "<"
649 << spirv::stringifyVersion(triple.getVersion()) << ", "
650 << llvm::interleaved_array(llvm::map_range(
651 triple.getCapabilities(), spirv::stringifyCapability))
652 << ", "
653 << llvm::interleaved_array(
654 triple.getExtensionsAttr().getAsValueRange<StringAttr>())
655 << ">";
656}
657
658static void print(spirv::TargetEnvAttr targetEnv, DialectAsmPrinter &printer) {
659 printer << spirv::TargetEnvAttr::getKindName() << "<#spirv.";
660 print(targetEnv.getTripleAttr(), printer);
661 auto clientAPI = targetEnv.getClientAPI();
662 if (clientAPI != spirv::ClientAPI::Unknown)
663 printer << ", api=" << clientAPI;
664 spirv::Vendor vendorID = targetEnv.getVendorID();
665 spirv::DeviceType deviceType = targetEnv.getDeviceType();
666 uint32_t deviceID = targetEnv.getDeviceID();
667 if (vendorID != spirv::Vendor::Unknown) {
668 printer << ", " << spirv::stringifyVendor(vendorID);
669 if (deviceType != spirv::DeviceType::Unknown) {
670 printer << ":" << spirv::stringifyDeviceType(deviceType);
672 printer << ":" << deviceID;
673 }
674 }
675 printer << ", " << targetEnv.getResourceLimits() << ">";
676}
677
678static void print(spirv::InterfaceVarABIAttr interfaceVarABIAttr,
679 DialectAsmPrinter &printer) {
680 printer << spirv::InterfaceVarABIAttr::getKindName() << "<("
681 << interfaceVarABIAttr.getDescriptorSet() << ", "
682 << interfaceVarABIAttr.getBinding() << ")";
683 auto storageClass = interfaceVarABIAttr.getStorageClass();
684 if (storageClass)
685 printer << ", " << spirv::stringifyStorageClass(*storageClass);
686 printer << ">";
687}
688
689void SPIRVDialect::printAttribute(Attribute attr,
690 DialectAsmPrinter &printer) const {
691 if (succeeded(generatedAttributePrinter(attr, printer)))
692 return;
693
694 if (auto targetEnv = dyn_cast<TargetEnvAttr>(attr))
695 print(targetEnv, printer);
696 else if (auto vceAttr = dyn_cast<VerCapExtAttr>(attr))
697 print(vceAttr, printer);
698 else if (auto interfaceVarABIAttr = dyn_cast<InterfaceVarABIAttr>(attr))
699 print(interfaceVarABIAttr, printer);
700 else
701 llvm_unreachable("unhandled SPIR-V attribute kind");
702}
703
704//===----------------------------------------------------------------------===//
705// SPIR-V Dialect
706//===----------------------------------------------------------------------===//
707
708void spirv::SPIRVDialect::registerAttributes() {
709 addAttributes<InterfaceVarABIAttr, TargetEnvAttr, VerCapExtAttr>();
710}
return success()
b
Return true if permutation is a valid permutation of the outer_dims_perm (case OuterOrInnerPerm::Oute...
ArrayAttr()
static Attribute parseTargetEnvAttr(DialectAsmParser &parser)
Parses a spirv::TargetEnvAttr.
static ParseResult parseKeywordList(DialectAsmParser &parser, function_ref< LogicalResult(SMLoc, StringRef)> processKeyword)
Parses a comma-separated list of keywords, invokes processKeyword on each of the parsed keyword,...
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
static Attribute parseVerCapExtAttr(DialectAsmParser &parser)
static Attribute parseInterfaceVarABIAttr(DialectAsmParser &parser)
Parses a spirv::InterfaceVarABIAttr.
static LogicalResult generatedAttributePrinter(Attribute def, AsmPrinter &printer)
static OptionalParseResult generatedAttributeParser(AsmParser &parser, StringRef *mnemonic, Type type, Attribute &value)
virtual OptionalParseResult parseOptionalInteger(APInt &result)=0
Parse an optional integer value from the stream.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseOptionalColon()=0
Parse a : token if present.
virtual ParseResult parseLSquare()=0
Parse a [ token.
virtual ParseResult parseRSquare()=0
Parse a ] token.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseLess()=0
Parse a '<' token.
virtual ParseResult parseEqual()=0
Parse a = token.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseOptionalComma()=0
Parse a , token if present.
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
virtual ParseResult parseOptionalRSquare()=0
Parse a ] token if present.
virtual ParseResult parseGreater()=0
Parse a '>' token.
virtual ParseResult parseLParen()=0
Parse a ( token.
virtual ParseResult parseComma()=0
Parse a , token.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
virtual ParseResult parseAttribute(Attribute &result, Type type={})=0
Parse an arbitrary attribute of a given type and return it in result.
Base storage class appearing in an attribute.
Attributes are known-constant values of operations.
Definition Attributes.h:25
This class is a general helper class for creating context-global objects like types,...
Definition Builders.h:51
IntegerAttr getI32IntegerAttr(int32_t value)
Definition Builders.cpp:208
StringAttr getStringAttr(const Twine &bytes)
Definition Builders.cpp:271
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
Definition Builders.cpp:275
The DialectAsmParser has methods for interacting with the asm parser when parsing attributes and type...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
This class represents a diagnostic that is inflight and set to be reported.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:71
T * allocate()
Allocate an instance of the provided type.
An attribute that specifies the information regarding the interface variable: descriptor set,...
uint32_t getBinding()
Returns binding.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spirv.' prefix).
uint32_t getDescriptorSet()
Returns descriptor set.
static InterfaceVarABIAttr get(uint32_t descriptorSet, uint32_t binding, std::optional< StorageClass > storageClass, MLIRContext *context)
Gets a InterfaceVarABIAttr.
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, IntegerAttr descriptorSet, IntegerAttr binding, IntegerAttr storageClass)
std::optional< StorageClass > getStorageClass()
Returns spirv::StorageClass.
An attribute that specifies the target version, allowed extensions and capabilities,...
Version getVersion() const
Returns the target version.
VerCapExtAttr::cap_range getCapabilities()
Returns the target capabilities.
ResourceLimitsAttr getResourceLimits() const
Returns the target resource limits.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spirv.' prefix).
VerCapExtAttr getTripleAttr() const
Returns the (version, capabilities, extensions) triple attribute.
ArrayAttr getCapabilitiesAttr()
Returns the target capabilities as an integer array attribute.
VerCapExtAttr::ext_range getExtensions()
Returns the target extensions.
Vendor getVendorID() const
Returns the vendor ID.
DeviceType getDeviceType() const
Returns the device type.
ClientAPI getClientAPI() const
Returns the client API.
ArrayAttr getExtensionsAttr()
Returns the target extensions as a string array attribute.
uint32_t getDeviceID() const
Returns the device ID.
static constexpr uint32_t kUnknownDeviceID
ID for unknown devices.
static TargetEnvAttr get(VerCapExtAttr triple, ResourceLimitsAttr limits, ClientAPI clientAPI=ClientAPI::Unknown, Vendor vendorID=Vendor::Unknown, DeviceType deviceType=DeviceType::Unknown, uint32_t deviceId=kUnknownDeviceID)
Gets a TargetEnvAttr instance.
An attribute that specifies the SPIR-V (version, capabilities, extensions) triple.
cap_range getCapabilities()
Returns the capabilities.
static LogicalResult verifyInvariants(function_ref< InFlightDiagnostic()> emitError, IntegerAttr version, ArrayAttr capabilities, ArrayAttr extensions)
Version getVersion()
Returns the version.
static StringRef getKindName()
Returns the attribute kind's name (without the 'spirv.' prefix).
static VerCapExtAttr get(Version version, ArrayRef< Capability > capabilities, ArrayRef< Extension > extensions, MLIRContext *context)
Gets a VerCapExtAttr instance.
ArrayAttr getCapabilitiesAttr()
Returns the capabilities as an integer array attribute.
llvm::iterator_range< ext_iterator > ext_range
ext_range getExtensions()
Returns the extensions.
ArrayAttr getExtensionsAttr()
Returns the extensions as a string array attribute.
llvm::iterator_range< cap_iterator > cap_range
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
StorageUniquer::StorageAllocator AttributeStorageAllocator
detail::DenseArrayAttrImpl< int32_t > DenseI32ArrayAttr
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
llvm::function_ref< Fn > function_ref
Definition LLVM.h:155
InterfaceVarABIAttributeStorage(Attribute descriptorSet, Attribute binding, Attribute storageClass)
std::tuple< Attribute, Attribute, Attribute > KeyTy
static InterfaceVarABIAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
std::tuple< Attribute, ClientAPI, Vendor, DeviceType, uint32_t, Attribute > KeyTy
TargetEnvAttributeStorage(Attribute triple, ClientAPI clientAPI, Vendor vendorID, DeviceType deviceType, uint32_t deviceID, Attribute limits)
static TargetEnvAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
std::tuple< Attribute, Attribute, Attribute > KeyTy
static VerCapExtAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
VerCapExtAttributeStorage(Attribute version, Attribute capabilities, Attribute extensions)