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>
26 inline constexpr
char kCallee[] =
"callee";
53 template <
typename Ty>
56 if (enumValues.empty()) {
60 enumValStrs.reserve(enumValues.size());
61 for (
auto val : enumValues) {
62 enumValStrs.emplace_back(stringifyFn(val));
69 template <
typename EnumClass,
typename ParserType>
72 StringRef attrName = spirv::attributeName<EnumClass>()) {
75 auto loc = parser.getCurrentLocation();
76 if (parser.parseKeyword(&keyword))
79 if (std::optional<EnumClass> attr =
80 spirv::symbolizeEnum<EnumClass>(keyword)) {
84 return parser.emitError(loc,
"invalid ")
85 << attrName <<
" attribute specification: " << keyword;
90 template <
typename EnumClass>
93 StringRef attrName = spirv::attributeName<EnumClass>()) {
94 static_assert(std::is_enum_v<EnumClass>);
101 if (!llvm::isa<StringAttr>(attrVal))
102 return parser.
emitError(loc,
"expected ")
103 << attrName <<
" attribute specified as string";
104 auto attrOptional = spirv::symbolizeEnum<EnumClass>(
105 llvm::cast<StringAttr>(attrVal).getValue());
108 << attrName <<
" attribute specification: " << attrVal;
109 value = *attrOptional;
116 template <
typename EnumAttrClass,
117 typename EnumClass =
typename EnumAttrClass::ValueType>
120 StringRef attrName = spirv::attributeName<EnumClass>()) {
121 static_assert(std::is_enum_v<EnumClass>);
124 state.addAttribute(attrName,
132 template <
typename EnumAttrClass,
133 typename EnumClass =
typename EnumAttrClass::ValueType>
137 StringRef attrName = spirv::attributeName<EnumClass>()) {
138 static_assert(std::is_enum_v<EnumClass>);
141 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,...
This class represents success/failure for parsing-like operations that find it important to chain tog...
constexpr char kFnNameAttrName[]
constexpr char kMemoryAccessAttrName[]
constexpr char kInitializerAttrName[]
constexpr char kPackedVectorFormatAttrName[]
constexpr char kSourceMemoryAccessAttrName[]
constexpr char kIndicesAttrName[]
constexpr char kExecutionScopeAttrName[]
constexpr char kEqualSemanticsAttrName[]
constexpr char kMemoryOperandAttrName[]
constexpr char kKhrCooperativeMatrixLayoutAttrName[]
constexpr char kSpecIdAttrName[]
constexpr char kValuesAttrName[]
constexpr char kValueAttrName[]
constexpr char kGroupOperationAttrName[]
constexpr char kBranchWeightAttrName[]
constexpr char kCompositeSpecConstituentsName[]
constexpr char kControl[]
constexpr char kSourceAlignmentAttrName[]
constexpr char kInterfaceAttrName[]
constexpr char kMemoryScopeAttrName[]
constexpr char kTypeAttrName[]
constexpr char kAlignmentAttrName[]
constexpr char kDefaultValueAttrName[]
constexpr char kClusterSize[]
constexpr char kSemanticsAttrName[]
constexpr char kUnequalSemanticsAttrName[]
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 parseMemoryAccessAttributes(OpAsmParser &parser, OperationState &state, StringRef attrName)
Parses optional memory access (a.k.a.
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)
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
This represents an operation in an abstracted form, suitable for use with the builder APIs.