MLIR 22.0.0git
SPIRVParsingUtils.cpp
Go to the documentation of this file.
1//===- SPIRVParsingUtilities.cpp - MLIR SPIR-V Dialect Parsing Utils-------===//
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//
9// Implements common SPIR-V dialect parsing functions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SPIRVParsingUtils.h"
14
15#include "llvm/ADT/StringExtras.h"
16
17using namespace mlir::spirv::AttrNames;
18
19namespace mlir::spirv {
20
22 OperationState &state) {
23 auto builtInName = llvm::convertToSnakeFromCamelCase(
24 stringifyDecoration(spirv::Decoration::BuiltIn));
25 if (succeeded(parser.parseOptionalKeyword("bind"))) {
26 Attribute set, binding;
27 // Parse optional descriptor binding
28 auto descriptorSetName = llvm::convertToSnakeFromCamelCase(
29 stringifyDecoration(spirv::Decoration::DescriptorSet));
30 auto bindingName = llvm::convertToSnakeFromCamelCase(
31 stringifyDecoration(spirv::Decoration::Binding));
32 Type i32Type = parser.getBuilder().getIntegerType(32);
33 if (parser.parseLParen() ||
34 parser.parseAttribute(set, i32Type, descriptorSetName,
35 state.attributes) ||
36 parser.parseComma() ||
37 parser.parseAttribute(binding, i32Type, bindingName,
38 state.attributes) ||
39 parser.parseRParen()) {
40 return failure();
41 }
42 } else if (succeeded(parser.parseOptionalKeyword(builtInName))) {
43 StringAttr builtIn;
44 if (parser.parseLParen() ||
45 parser.parseAttribute(builtIn, builtInName, state.attributes) ||
46 parser.parseRParen()) {
47 return failure();
48 }
49 }
50
51 // Parse other attributes
52 if (parser.parseOptionalAttrDict(state.attributes))
53 return failure();
54
55 return success();
56}
57
58} // namespace mlir::spirv
return success()
static std::string bindingName()
Returns the string name of the Binding decoration.
static std::string descriptorSetName()
Returns the string name of the DescriptorSet decoration.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
virtual ParseResult parseOptionalAttrDict(NamedAttrList &result)=0
Parse a named dictionary into 'result' if it is present.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual ParseResult parseLParen()=0
Parse a ( token.
virtual ParseResult parseComma()=0
Parse a , token.
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.
Definition Attributes.h:25
IntegerType getIntegerType(unsigned width)
Definition Builders.cpp:67
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
ParseResult parseVariableDecorations(OpAsmParser &parser, OperationState &state)
This represents an operation in an abstracted form, suitable for use with the builder APIs.