14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/FunctionExtras.h"
16 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/ADT/StringRef.h"
19 #include <type_traits>
31 template <
typename Ty>
34 if (enumValues.empty()) {
38 enumValStrs.reserve(enumValues.size());
39 for (
auto val : enumValues) {
40 enumValStrs.emplace_back(stringifyFn(val));
47 template <
typename EnumClass,
typename ParserType>
50 StringRef attrName = spirv::attributeName<EnumClass>()) {
53 auto loc = parser.getCurrentLocation();
54 if (parser.parseKeyword(&keyword))
57 if (std::optional<EnumClass> attr =
58 spirv::symbolizeEnum<EnumClass>(keyword)) {
62 return parser.emitError(loc,
"invalid ")
63 << attrName <<
" attribute specification: " << keyword;
68 template <
typename EnumClass>
71 StringRef attrName = spirv::attributeName<EnumClass>()) {
72 static_assert(std::is_enum_v<EnumClass>);
79 if (!llvm::isa<StringAttr>(attrVal))
81 << attrName <<
" attribute specified as string";
82 auto attrOptional = spirv::symbolizeEnum<EnumClass>(
83 llvm::cast<StringAttr>(attrVal).getValue());
86 << attrName <<
" attribute specification: " << attrVal;
87 value = *attrOptional;
94 template <
typename EnumAttrClass,
95 typename EnumClass =
typename EnumAttrClass::ValueType>
98 StringRef attrName = spirv::attributeName<EnumClass>()) {
99 static_assert(std::is_enum_v<EnumClass>);
102 state.addAttribute(attrName,
110 template <
typename EnumAttrClass,
111 typename EnumClass =
typename EnumAttrClass::ValueType>
115 StringRef attrName = spirv::attributeName<EnumClass>()) {
116 static_assert(std::is_enum_v<EnumClass>);
119 state.addAttribute(attrName,
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseAttribute(Attribute &result, Type type={})=0
Parse an arbitrary attribute of a given type and return it in result.
Attributes are known-constant values of operations.
This class is a general helper class for creating context-global objects like types,...
ArrayAttr getStrArrayAttr(ArrayRef< StringRef > values)
Attr getAttr(Args &&...args)
Get or construct an instance of the attribute Attr with provided arguments.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
constexpr char kFnNameAttrName[]
constexpr char kSpecIdAttrName[]
constexpr char kControl[]
constexpr char kClusterSize[]
ParseResult parseEnumStrAttr(EnumClass &value, OpAsmParser &parser, StringRef attrName=spirv::attributeName< EnumClass >())
Parses the next string attribute in parser as an enumerant of the given EnumClass.
ParseResult parseEnumKeywordAttr(EnumClass &value, ParserType &parser, StringRef attrName=spirv::attributeName< EnumClass >())
Parses the next keyword in parser as an enumerant of the given EnumClass.
ArrayAttr getStrArrayAttrForEnumList(Builder &builder, ArrayRef< Ty > enumValues, function_ref< StringRef(Ty)> stringifyFn)
ParseResult parseVariableDecorations(OpAsmParser &parser, OperationState &state)
This represents an operation in an abstracted form, suitable for use with the builder APIs.