20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/TypeSwitch.h"
22 #include "llvm/IR/Metadata.h"
23 #include "llvm/Support/Casting.h"
32 #include "mlir/Dialect/IRDL/IR/IRDL.cpp.inc"
34 #include "mlir/Dialect/IRDL/IR/IRDLDialect.cpp.inc"
36 void IRDLDialect::initialize() {
39 #include "mlir/Dialect/IRDL/IR/IRDLOps.cpp.inc"
42 #define GET_TYPEDEF_LIST
43 #include "mlir/Dialect/IRDL/IR/IRDLTypesGen.cpp.inc"
46 #define GET_ATTRDEF_LIST
47 #include "mlir/Dialect/IRDL/IR/IRDLAttributes.cpp.inc"
59 if (regionParseRes.has_value() &&
failed(regionParseRes.value()))
77 return emitOpError(
"invalid dialect name");
82 size_t numVariadicities = getVariadicity().size();
83 size_t numOperands = getNumOperands();
85 if (numOperands != numVariadicities)
87 <<
"the number of operands and their variadicities must be "
89 << numOperands <<
" and " << numVariadicities <<
" respectively";
95 size_t numVariadicities = getVariadicity().size();
96 size_t numOperands = this->getNumOperands();
98 if (numOperands != numVariadicities)
100 <<
"the number of operands and their variadicities must be "
102 << numOperands <<
" and " << numVariadicities <<
" respectively";
108 size_t namesSize = getAttributeValueNames().size();
109 size_t valuesSize = getAttributeValues().size();
111 if (namesSize != valuesSize)
113 <<
"the number of attribute names and their constraints must be "
115 << namesSize <<
" and " << valuesSize <<
" respectively";
127 VariadicityAttr &variadicityAttr) {
155 VariadicityArrayAttr &variadicityAttr) {
161 auto parseOne = [&] {
163 VariadicityAttr variadicity;
166 operands.push_back(operand);
167 variadicities.push_back(variadicity);
185 VariadicityArrayAttr variadicityAttr) {
187 interleaveComma(llvm::seq<int>(0, operands.size()), p, [&](
int i) {
188 Variadicity variadicity = variadicityAttr[i].getValue();
189 if (variadicity != Variadicity::single) {
190 p << stringifyVariadicity(variadicity) <<
" ";
200 ArrayAttr &attrNamesAttr) {
204 auto parseOperands = [&]() {
219 if (attrNames.empty())
222 interleaveComma(llvm::seq<int>(0, attrNames.size()), p,
223 [&](
int i) { p << attrNames[i] <<
" = " << attrArgs[i]; });
228 if (IntegerAttr numberOfBlocks = getNumberOfBlocksAttr())
229 if (int64_t number = numberOfBlocks.getInt(); number <= 0) {
230 return emitOpError(
"the number of blocks is expected to be >= 1 but got ")
236 #include "mlir/Dialect/IRDL/IR/IRDLInterfaces.cpp.inc"
238 #define GET_TYPEDEF_CLASSES
239 #include "mlir/Dialect/IRDL/IR/IRDLTypesGen.cpp.inc"
241 #include "mlir/Dialect/IRDL/IR/IRDLEnums.cpp.inc"
243 #define GET_ATTRDEF_CLASSES
244 #include "mlir/Dialect/IRDL/IR/IRDLAttributes.cpp.inc"
246 #define GET_OP_CLASSES
247 #include "mlir/Dialect/IRDL/IR/IRDLOps.cpp.inc"
static ParseResult parseValueWithVariadicity(OpAsmParser &p, OpAsmParser::UnresolvedOperand &operand, VariadicityAttr &variadicityAttr)
Parse a value with its variadicity first.
static void printAttributesOp(OpAsmPrinter &p, AttributesOp op, OperandRange attrArgs, ArrayAttr attrNames)
static ParseResult parseValuesWithVariadicity(OpAsmParser &p, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &operands, VariadicityArrayAttr &variadicityAttr)
Parse a list of values with their variadicities first.
static ParseResult parseSingleBlockRegion(OpAsmParser &p, Region ®ion)
Parse a region, and add a single block if the region is empty.
static ParseResult parseAttributesOp(OpAsmParser &p, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &attrOperands, ArrayAttr &attrNamesAttr)
static void printSingleBlockRegion(OpAsmPrinter &p, Operation *op, Region ®ion)
static void printValuesWithVariadicity(OpAsmPrinter &p, Operation *op, OperandRange operands, VariadicityArrayAttr variadicityAttr)
Print a list of values with their variadicities first.
@ Paren
Parens surrounding zero or more operands.
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 parseRBrace()=0
Parse a } token.
virtual ParseResult parseEqual()=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.
virtual ParseResult parseOptionalLBrace()=0
Parse a { token if present.
Block represents an ordered list of Operations.
This class is a general helper class for creating context-global objects like types,...
MLIRContext * getContext() const
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
static bool isValidNamespace(StringRef str)
Utility function that returns if the given string is a valid dialect namespace.
MLIRContext is the top-level object for a collection of MLIR operations.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual OptionalParseResult parseOptionalRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region if present.
virtual ParseResult parseOperand(UnresolvedOperand &result, bool allowResultNumber=true)=0
Parse a single SSA value operand name along with a result number if allowResultNumber is true.
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
virtual void printRegion(Region &blocks, bool printEntryBlockArgs=true, bool printBlockTerminators=true, bool printEmptyBlock=false)=0
Prints a region.
This class implements the operand iterators for the Operation class.
Operation is the basic unit of execution within MLIR.
This class represents success/failure for parsing-like operations that find it important to chain tog...
This class contains a list of basic blocks and a link to the parent operation it is attached to.
void push_back(Block *block)
BlockListType & getBlocks()
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value.
This class represents an efficient way to signal success or failure.
bool succeeded() const
Returns true if the provided LogicalResult corresponds to a success value.
This is the representation of an operand reference.