MLIR  17.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 
16 using namespace mlir;
17 using namespace mlir::spirv;
18 
19 //===----------------------------------------------------------------------===//
20 // TableGen'erated attribute utility functions
21 //===----------------------------------------------------------------------===//
22 
23 namespace mlir {
24 namespace spirv {
25 #include "mlir/Dialect/SPIRV/IR/SPIRVAttrUtils.inc"
26 } // namespace spirv
27 
28 //===----------------------------------------------------------------------===//
29 // Attribute storage classes
30 //===----------------------------------------------------------------------===//
31 
32 namespace spirv {
33 namespace detail {
34 
36  using KeyTy = std::tuple<Attribute, Attribute, Attribute>;
37 
39  Attribute storageClass)
40  : descriptorSet(descriptorSet), binding(binding),
41  storageClass(storageClass) {}
42 
43  bool operator==(const KeyTy &key) const {
44  return std::get<0>(key) == descriptorSet && std::get<1>(key) == binding &&
45  std::get<2>(key) == storageClass;
46  }
47 
49  construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
50  return new (allocator.allocate<InterfaceVarABIAttributeStorage>())
51  InterfaceVarABIAttributeStorage(std::get<0>(key), std::get<1>(key),
52  std::get<2>(key));
53  }
54 
58 };
59 
61  using KeyTy = std::tuple<Attribute, Attribute, Attribute>;
62 
64  Attribute extensions)
65  : version(version), capabilities(capabilities), extensions(extensions) {}
66 
67  bool operator==(const KeyTy &key) const {
68  return std::get<0>(key) == version && std::get<1>(key) == capabilities &&
69  std::get<2>(key) == extensions;
70  }
71 
73  construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
74  return new (allocator.allocate<VerCapExtAttributeStorage>())
75  VerCapExtAttributeStorage(std::get<0>(key), std::get<1>(key),
76  std::get<2>(key));
77  }
78 
82 };
83 
85  using KeyTy =
86  std::tuple<Attribute, ClientAPI, Vendor, DeviceType, uint32_t, Attribute>;
87 
88  TargetEnvAttributeStorage(Attribute triple, ClientAPI clientAPI,
89  Vendor vendorID, DeviceType deviceType,
90  uint32_t deviceID, Attribute limits)
91  : triple(triple), limits(limits), clientAPI(clientAPI),
92  vendorID(vendorID), deviceType(deviceType), deviceID(deviceID) {}
93 
94  bool operator==(const KeyTy &key) const {
95  return key == std::make_tuple(triple, clientAPI, vendorID, deviceType,
96  deviceID, limits);
97  }
98 
100  construct(AttributeStorageAllocator &allocator, const KeyTy &key) {
101  return new (allocator.allocate<TargetEnvAttributeStorage>())
102  TargetEnvAttributeStorage(std::get<0>(key), std::get<1>(key),
103  std::get<2>(key), std::get<3>(key),
104  std::get<4>(key), std::get<5>(key));
105  }
106 
109  ClientAPI clientAPI;
110  Vendor vendorID;
111  DeviceType deviceType;
112  uint32_t deviceID;
113 };
114 } // namespace detail
115 } // namespace spirv
116 } // namespace mlir
117 
118 //===----------------------------------------------------------------------===//
119 // InterfaceVarABIAttr
120 //===----------------------------------------------------------------------===//
121 
123 spirv::InterfaceVarABIAttr::get(uint32_t descriptorSet, uint32_t binding,
124  std::optional<spirv::StorageClass> storageClass,
125  MLIRContext *context) {
126  Builder b(context);
127  auto descriptorSetAttr = b.getI32IntegerAttr(descriptorSet);
128  auto bindingAttr = b.getI32IntegerAttr(binding);
129  auto storageClassAttr =
130  storageClass ? b.getI32IntegerAttr(static_cast<uint32_t>(*storageClass))
131  : IntegerAttr();
132  return get(descriptorSetAttr, bindingAttr, storageClassAttr);
133 }
134 
136 spirv::InterfaceVarABIAttr::get(IntegerAttr descriptorSet, IntegerAttr binding,
137  IntegerAttr storageClass) {
138  assert(descriptorSet && binding);
139  MLIRContext *context = descriptorSet.getContext();
140  return Base::get(context, descriptorSet, binding, storageClass);
141 }
142 
144  return "interface_var_abi";
145 }
146 
148  return getImpl()->binding.cast<IntegerAttr>().getInt();
149 }
150 
152  return getImpl()->descriptorSet.cast<IntegerAttr>().getInt();
153 }
154 
155 std::optional<spirv::StorageClass>
157  if (getImpl()->storageClass)
158  return static_cast<spirv::StorageClass>(
159  getImpl()->storageClass.cast<IntegerAttr>().getValue().getZExtValue());
160  return std::nullopt;
161 }
162 
164  function_ref<InFlightDiagnostic()> emitError, IntegerAttr descriptorSet,
165  IntegerAttr binding, IntegerAttr storageClass) {
166  if (!descriptorSet.getType().isSignlessInteger(32))
167  return emitError() << "expected 32-bit integer for descriptor set";
168 
169  if (!binding.getType().isSignlessInteger(32))
170  return emitError() << "expected 32-bit integer for binding";
171 
172  if (storageClass) {
173  if (auto storageClassAttr = storageClass.cast<IntegerAttr>()) {
174  auto storageClassValue =
175  spirv::symbolizeStorageClass(storageClassAttr.getInt());
176  if (!storageClassValue)
177  return emitError() << "unknown storage class";
178  } else {
179  return emitError() << "expected valid storage class";
180  }
181  }
182 
183  return success();
184 }
185 
186 //===----------------------------------------------------------------------===//
187 // VerCapExtAttr
188 //===----------------------------------------------------------------------===//
189 
191  spirv::Version version, ArrayRef<spirv::Capability> capabilities,
192  ArrayRef<spirv::Extension> extensions, MLIRContext *context) {
193  Builder b(context);
194 
195  auto versionAttr = b.getI32IntegerAttr(static_cast<uint32_t>(version));
196 
197  SmallVector<Attribute, 4> capAttrs;
198  capAttrs.reserve(capabilities.size());
199  for (spirv::Capability cap : capabilities)
200  capAttrs.push_back(b.getI32IntegerAttr(static_cast<uint32_t>(cap)));
201 
202  SmallVector<Attribute, 4> extAttrs;
203  extAttrs.reserve(extensions.size());
204  for (spirv::Extension ext : extensions)
205  extAttrs.push_back(b.getStringAttr(spirv::stringifyExtension(ext)));
206 
207  return get(versionAttr, b.getArrayAttr(capAttrs), b.getArrayAttr(extAttrs));
208 }
209 
211  ArrayAttr capabilities,
212  ArrayAttr extensions) {
213  assert(version && capabilities && extensions);
214  MLIRContext *context = version.getContext();
215  return Base::get(context, version, capabilities, extensions);
216 }
217 
218 StringRef spirv::VerCapExtAttr::getKindName() { return "vce"; }
219 
221  return static_cast<spirv::Version>(
222  getImpl()->version.cast<IntegerAttr>().getValue().getZExtValue());
223 }
224 
226  : llvm::mapped_iterator<ArrayAttr::iterator,
227  spirv::Extension (*)(Attribute)>(
228  it, [](Attribute attr) {
229  return *symbolizeExtension(attr.cast<StringAttr>().getValue());
230  }) {}
231 
233  auto range = getExtensionsAttr().getValue();
234  return {ext_iterator(range.begin()), ext_iterator(range.end())};
235 }
236 
238  return getImpl()->extensions.cast<ArrayAttr>();
239 }
240 
242  : llvm::mapped_iterator<ArrayAttr::iterator,
243  spirv::Capability (*)(Attribute)>(
244  it, [](Attribute attr) {
245  return *symbolizeCapability(
246  attr.cast<IntegerAttr>().getValue().getZExtValue());
247  }) {}
248 
250  auto range = getCapabilitiesAttr().getValue();
251  return {cap_iterator(range.begin()), cap_iterator(range.end())};
252 }
253 
255  return getImpl()->capabilities.cast<ArrayAttr>();
256 }
257 
260  IntegerAttr version, ArrayAttr capabilities,
261  ArrayAttr extensions) {
262  if (!version.getType().isSignlessInteger(32))
263  return emitError() << "expected 32-bit integer for version";
264 
265  if (!llvm::all_of(capabilities.getValue(), [](Attribute attr) {
266  if (auto intAttr = attr.dyn_cast<IntegerAttr>())
267  if (spirv::symbolizeCapability(intAttr.getValue().getZExtValue()))
268  return true;
269  return false;
270  }))
271  return emitError() << "unknown capability in capability list";
272 
273  if (!llvm::all_of(extensions.getValue(), [](Attribute attr) {
274  if (auto strAttr = attr.dyn_cast<StringAttr>())
275  if (spirv::symbolizeExtension(strAttr.getValue()))
276  return true;
277  return false;
278  }))
279  return emitError() << "unknown extension in extension list";
280 
281  return success();
282 }
283 
284 //===----------------------------------------------------------------------===//
285 // TargetEnvAttr
286 //===----------------------------------------------------------------------===//
287 
289  spirv::VerCapExtAttr triple, ResourceLimitsAttr limits, ClientAPI clientAPI,
290  Vendor vendorID, DeviceType deviceType, uint32_t deviceID) {
291  assert(triple && limits && "expected valid triple and limits");
292  MLIRContext *context = triple.getContext();
293  return Base::get(context, triple, clientAPI, vendorID, deviceType, deviceID,
294  limits);
295 }
296 
297 StringRef spirv::TargetEnvAttr::getKindName() { return "target_env"; }
298 
300  return getImpl()->triple.cast<spirv::VerCapExtAttr>();
301 }
302 
303 spirv::Version spirv::TargetEnvAttr::getVersion() const {
304  return getTripleAttr().getVersion();
305 }
306 
308  return getTripleAttr().getExtensions();
309 }
310 
312  return getTripleAttr().getExtensionsAttr();
313 }
314 
316  return getTripleAttr().getCapabilities();
317 }
318 
320  return getTripleAttr().getCapabilitiesAttr();
321 }
322 
323 spirv::ClientAPI spirv::TargetEnvAttr::getClientAPI() const {
324  return getImpl()->clientAPI;
325 }
326 
327 spirv::Vendor spirv::TargetEnvAttr::getVendorID() const {
328  return getImpl()->vendorID;
329 }
330 
331 spirv::DeviceType spirv::TargetEnvAttr::getDeviceType() const {
332  return getImpl()->deviceType;
333 }
334 
336  return getImpl()->deviceID;
337 }
338 
339 spirv::ResourceLimitsAttr spirv::TargetEnvAttr::getResourceLimits() const {
340  return getImpl()->limits.cast<spirv::ResourceLimitsAttr>();
341 }
342 
343 //===----------------------------------------------------------------------===//
344 // ODS Generated Attributes
345 //===----------------------------------------------------------------------===//
346 
347 #define GET_ATTRDEF_CLASSES
348 #include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.cpp.inc"
349 
350 //===----------------------------------------------------------------------===//
351 // Attribute Parsing
352 //===----------------------------------------------------------------------===//
353 
354 /// Parses a comma-separated list of keywords, invokes `processKeyword` on each
355 /// of the parsed keyword, and returns failure if any error occurs.
356 static ParseResult
358  function_ref<LogicalResult(SMLoc, StringRef)> processKeyword) {
359  if (parser.parseLSquare())
360  return failure();
361 
362  // Special case for empty list.
363  if (succeeded(parser.parseOptionalRSquare()))
364  return success();
365 
366  // Keep parsing the keyword and an optional comma following it. If the comma
367  // is successfully parsed, then we have more keywords to parse.
368  if (failed(parser.parseCommaSeparatedList([&]() {
369  auto loc = parser.getCurrentLocation();
370  StringRef keyword;
371  if (parser.parseKeyword(&keyword) ||
372  failed(processKeyword(loc, keyword)))
373  return failure();
374  return success();
375  })))
376  return failure();
377  return parser.parseRSquare();
378 }
379 
380 /// Parses a spirv::InterfaceVarABIAttr.
382  if (parser.parseLess())
383  return {};
384 
385  Builder &builder = parser.getBuilder();
386 
387  if (parser.parseLParen())
388  return {};
389 
390  IntegerAttr descriptorSetAttr;
391  {
392  auto loc = parser.getCurrentLocation();
393  uint32_t descriptorSet = 0;
394  auto descriptorSetParseResult = parser.parseOptionalInteger(descriptorSet);
395 
396  if (!descriptorSetParseResult.has_value() ||
397  failed(*descriptorSetParseResult)) {
398  parser.emitError(loc, "missing descriptor set");
399  return {};
400  }
401  descriptorSetAttr = builder.getI32IntegerAttr(descriptorSet);
402  }
403 
404  if (parser.parseComma())
405  return {};
406 
407  IntegerAttr bindingAttr;
408  {
409  auto loc = parser.getCurrentLocation();
410  uint32_t binding = 0;
411  auto bindingParseResult = parser.parseOptionalInteger(binding);
412 
413  if (!bindingParseResult.has_value() || failed(*bindingParseResult)) {
414  parser.emitError(loc, "missing binding");
415  return {};
416  }
417  bindingAttr = builder.getI32IntegerAttr(binding);
418  }
419 
420  if (parser.parseRParen())
421  return {};
422 
423  IntegerAttr storageClassAttr;
424  {
425  if (succeeded(parser.parseOptionalComma())) {
426  auto loc = parser.getCurrentLocation();
427  StringRef storageClass;
428  if (parser.parseKeyword(&storageClass))
429  return {};
430 
431  if (auto storageClassSymbol =
432  spirv::symbolizeStorageClass(storageClass)) {
433  storageClassAttr = builder.getI32IntegerAttr(
434  static_cast<uint32_t>(*storageClassSymbol));
435  } else {
436  parser.emitError(loc, "unknown storage class: ") << storageClass;
437  return {};
438  }
439  }
440  }
441 
442  if (parser.parseGreater())
443  return {};
444 
445  return spirv::InterfaceVarABIAttr::get(descriptorSetAttr, bindingAttr,
446  storageClassAttr);
447 }
448 
450  if (parser.parseLess())
451  return {};
452 
453  Builder &builder = parser.getBuilder();
454 
455  IntegerAttr versionAttr;
456  {
457  auto loc = parser.getCurrentLocation();
458  StringRef version;
459  if (parser.parseKeyword(&version) || parser.parseComma())
460  return {};
461 
462  if (auto versionSymbol = spirv::symbolizeVersion(version)) {
463  versionAttr =
464  builder.getI32IntegerAttr(static_cast<uint32_t>(*versionSymbol));
465  } else {
466  parser.emitError(loc, "unknown version: ") << version;
467  return {};
468  }
469  }
470 
471  ArrayAttr capabilitiesAttr;
472  {
473  SmallVector<Attribute, 4> capabilities;
474  SMLoc errorloc;
475  StringRef errorKeyword;
476 
477  auto processCapability = [&](SMLoc loc, StringRef capability) {
478  if (auto capSymbol = spirv::symbolizeCapability(capability)) {
479  capabilities.push_back(
480  builder.getI32IntegerAttr(static_cast<uint32_t>(*capSymbol)));
481  return success();
482  }
483  return errorloc = loc, errorKeyword = capability, failure();
484  };
485  if (parseKeywordList(parser, processCapability) || parser.parseComma()) {
486  if (!errorKeyword.empty())
487  parser.emitError(errorloc, "unknown capability: ") << errorKeyword;
488  return {};
489  }
490 
491  capabilitiesAttr = builder.getArrayAttr(capabilities);
492  }
493 
494  ArrayAttr extensionsAttr;
495  {
496  SmallVector<Attribute, 1> extensions;
497  SMLoc errorloc;
498  StringRef errorKeyword;
499 
500  auto processExtension = [&](SMLoc loc, StringRef extension) {
501  if (spirv::symbolizeExtension(extension)) {
502  extensions.push_back(builder.getStringAttr(extension));
503  return success();
504  }
505  return errorloc = loc, errorKeyword = extension, failure();
506  };
507  if (parseKeywordList(parser, processExtension)) {
508  if (!errorKeyword.empty())
509  parser.emitError(errorloc, "unknown extension: ") << errorKeyword;
510  return {};
511  }
512 
513  extensionsAttr = builder.getArrayAttr(extensions);
514  }
515 
516  if (parser.parseGreater())
517  return {};
518 
519  return spirv::VerCapExtAttr::get(versionAttr, capabilitiesAttr,
520  extensionsAttr);
521 }
522 
523 /// Parses a spirv::TargetEnvAttr.
525  if (parser.parseLess())
526  return {};
527 
528  spirv::VerCapExtAttr tripleAttr;
529  if (parser.parseAttribute(tripleAttr) || parser.parseComma())
530  return {};
531 
532  auto clientAPI = spirv::ClientAPI::Unknown;
533  if (succeeded(parser.parseOptionalKeyword("api"))) {
534  if (parser.parseEqual())
535  return {};
536  auto loc = parser.getCurrentLocation();
537  StringRef apiStr;
538  if (parser.parseKeyword(&apiStr))
539  return {};
540  if (auto apiSymbol = spirv::symbolizeClientAPI(apiStr))
541  clientAPI = *apiSymbol;
542  else
543  parser.emitError(loc, "unknown client API: ") << apiStr;
544  if (parser.parseComma())
545  return {};
546  }
547 
548  // Parse [vendor[:device-type[:device-id]]]
549  Vendor vendorID = Vendor::Unknown;
550  DeviceType deviceType = DeviceType::Unknown;
551  uint32_t deviceID = spirv::TargetEnvAttr::kUnknownDeviceID;
552  {
553  auto loc = parser.getCurrentLocation();
554  StringRef vendorStr;
555  if (succeeded(parser.parseOptionalKeyword(&vendorStr))) {
556  if (auto vendorSymbol = spirv::symbolizeVendor(vendorStr))
557  vendorID = *vendorSymbol;
558  else
559  parser.emitError(loc, "unknown vendor: ") << vendorStr;
560 
561  if (succeeded(parser.parseOptionalColon())) {
562  loc = parser.getCurrentLocation();
563  StringRef deviceTypeStr;
564  if (parser.parseKeyword(&deviceTypeStr))
565  return {};
566  if (auto deviceTypeSymbol = spirv::symbolizeDeviceType(deviceTypeStr))
567  deviceType = *deviceTypeSymbol;
568  else
569  parser.emitError(loc, "unknown device type: ") << deviceTypeStr;
570 
571  if (succeeded(parser.parseOptionalColon())) {
572  loc = parser.getCurrentLocation();
573  if (parser.parseInteger(deviceID))
574  return {};
575  }
576  }
577  if (parser.parseComma())
578  return {};
579  }
580  }
581 
582  ResourceLimitsAttr limitsAttr;
583  if (parser.parseAttribute(limitsAttr) || parser.parseGreater())
584  return {};
585 
586  return spirv::TargetEnvAttr::get(tripleAttr, limitsAttr, clientAPI, vendorID,
587  deviceType, deviceID);
588 }
589 
591  Type type) const {
592  // SPIR-V attributes are dictionaries so they do not have type.
593  if (type) {
594  parser.emitError(parser.getNameLoc(), "unexpected type");
595  return {};
596  }
597 
598  // Parse the kind keyword first.
599  StringRef attrKind;
600  Attribute attr;
601  OptionalParseResult result =
602  generatedAttributeParser(parser, &attrKind, type, attr);
603  if (result.has_value())
604  return attr;
605 
606  if (attrKind == spirv::TargetEnvAttr::getKindName())
607  return parseTargetEnvAttr(parser);
608  if (attrKind == spirv::VerCapExtAttr::getKindName())
609  return parseVerCapExtAttr(parser);
610  if (attrKind == spirv::InterfaceVarABIAttr::getKindName())
611  return parseInterfaceVarABIAttr(parser);
612 
613  parser.emitError(parser.getNameLoc(), "unknown SPIR-V attribute kind: ")
614  << attrKind;
615  return {};
616 }
617 
618 //===----------------------------------------------------------------------===//
619 // Attribute Printing
620 //===----------------------------------------------------------------------===//
621 
622 static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer) {
623  auto &os = printer.getStream();
624  printer << spirv::VerCapExtAttr::getKindName() << "<"
625  << spirv::stringifyVersion(triple.getVersion()) << ", [";
626  llvm::interleaveComma(
627  triple.getCapabilities(), os,
628  [&](spirv::Capability cap) { os << spirv::stringifyCapability(cap); });
629  printer << "], [";
630  llvm::interleaveComma(triple.getExtensionsAttr(), os, [&](Attribute attr) {
631  os << attr.cast<StringAttr>().getValue();
632  });
633  printer << "]>";
634 }
635 
636 static void print(spirv::TargetEnvAttr targetEnv, DialectAsmPrinter &printer) {
637  printer << spirv::TargetEnvAttr::getKindName() << "<#spirv.";
638  print(targetEnv.getTripleAttr(), printer);
639  auto clientAPI = targetEnv.getClientAPI();
640  if (clientAPI != spirv::ClientAPI::Unknown)
641  printer << ", api=" << clientAPI;
642  spirv::Vendor vendorID = targetEnv.getVendorID();
643  spirv::DeviceType deviceType = targetEnv.getDeviceType();
644  uint32_t deviceID = targetEnv.getDeviceID();
645  if (vendorID != spirv::Vendor::Unknown) {
646  printer << ", " << spirv::stringifyVendor(vendorID);
647  if (deviceType != spirv::DeviceType::Unknown) {
648  printer << ":" << spirv::stringifyDeviceType(deviceType);
650  printer << ":" << deviceID;
651  }
652  }
653  printer << ", " << targetEnv.getResourceLimits() << ">";
654 }
655 
656 static void print(spirv::InterfaceVarABIAttr interfaceVarABIAttr,
657  DialectAsmPrinter &printer) {
658  printer << spirv::InterfaceVarABIAttr::getKindName() << "<("
659  << interfaceVarABIAttr.getDescriptorSet() << ", "
660  << interfaceVarABIAttr.getBinding() << ")";
661  auto storageClass = interfaceVarABIAttr.getStorageClass();
662  if (storageClass)
663  printer << ", " << spirv::stringifyStorageClass(*storageClass);
664  printer << ">";
665 }
666 
667 void SPIRVDialect::printAttribute(Attribute attr,
668  DialectAsmPrinter &printer) const {
669  if (succeeded(generatedAttributePrinter(attr, printer)))
670  return;
671 
672  if (auto targetEnv = attr.dyn_cast<TargetEnvAttr>())
673  print(targetEnv, printer);
674  else if (auto vceAttr = attr.dyn_cast<VerCapExtAttr>())
675  print(vceAttr, printer);
676  else if (auto interfaceVarABIAttr = attr.dyn_cast<InterfaceVarABIAttr>())
677  print(interfaceVarABIAttr, printer);
678  else
679  llvm_unreachable("unhandled SPIR-V attribute kind");
680 }
681 
682 //===----------------------------------------------------------------------===//
683 // SPIR-V Dialect
684 //===----------------------------------------------------------------------===//
685 
686 void spirv::SPIRVDialect::registerAttributes() {
687  addAttributes<InterfaceVarABIAttr, TargetEnvAttr, VerCapExtAttr>();
688  addAttributes<
689 #define GET_ATTRDEF_LIST
690 #include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.cpp.inc"
691  >();
692 }
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.
virtual OptionalParseResult parseOptionalInteger(APInt &result)=0
Parse an optional integer value from the stream.
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 Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
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.
virtual raw_ostream & getStream() const
Return the raw output stream used by this printer.
Base storage class appearing in an attribute.
Attributes are known-constant values of operations.
Definition: Attributes.h:25
U dyn_cast() const
Definition: Attributes.h:127
This class is a general helper class for creating context-global objects like types,...
Definition: Builders.h:50
IntegerAttr getI32IntegerAttr(int32_t value)
Definition: Builders.cpp:190
StringAttr getStringAttr(const Twine &bytes)
Definition: Builders.cpp:243
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
Definition: Builders.cpp:247
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.
Definition: Diagnostics.h:308
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:56
This class implements Optional functionality for ParseResult.
Definition: OpDefinition.h:38
bool has_value() const
Returns true if we contain a valid ParseResult value.
Definition: OpDefinition.h:48
This class represents success/failure for parsing-like operations that find it important to chain tog...
This is a utility allocator used to allocate memory for instances of derived types.
T * allocate()
Allocate an instance of the provided type.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition: Types.h:74
ImplType * getImpl() const
Utility for easy access to the storage instance.
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).
static LogicalResult verify(function_ref< InFlightDiagnostic()> emitError, IntegerAttr descriptorSet, IntegerAttr binding, IntegerAttr storageClass)
uint32_t getDescriptorSet()
Returns descriptor set.
static InterfaceVarABIAttr get(uint32_t descriptorSet, uint32_t binding, std::optional< StorageClass > storageClass, MLIRContext *context)
Gets a InterfaceVarABIAttr.
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 verify(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.
ext_range getExtensions()
Returns the extensions.
ArrayAttr getExtensionsAttr()
Returns the extensions as a string array attribute.
Include the generated interface declarations.
Definition: CallGraph.h:229
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
Definition: LogicalResult.h:68
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:56
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
Definition: LogicalResult.h:72
Attribute parseAttribute(llvm::StringRef attrStr, MLIRContext *context)
This parses a single MLIR attribute to an MLIR context if it was valid.
This class represents an efficient way to signal success or failure.
Definition: LogicalResult.h:26
InterfaceVarABIAttributeStorage(Attribute descriptorSet, Attribute binding, Attribute storageClass)
std::tuple< Attribute, Attribute, Attribute > KeyTy
static InterfaceVarABIAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
static TargetEnvAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
TargetEnvAttributeStorage(Attribute triple, ClientAPI clientAPI, Vendor vendorID, DeviceType deviceType, uint32_t deviceID, Attribute limits)
std::tuple< Attribute, ClientAPI, Vendor, DeviceType, uint32_t, Attribute > KeyTy
static VerCapExtAttributeStorage * construct(AttributeStorageAllocator &allocator, const KeyTy &key)
std::tuple< Attribute, Attribute, Attribute > KeyTy
VerCapExtAttributeStorage(Attribute version, Attribute capabilities, Attribute extensions)