16 using namespace mlir::pdl_interp;
18 #include "mlir/Dialect/PDLInterp/IR/PDLInterpOpsDialect.cpp.inc"
24 void PDLInterpDialect::initialize() {
27 #include "mlir/Dialect/PDLInterp/IR/PDLInterpOps.cpp.inc"
31 template <
typename OpT>
35 size_t numDests = op.getCases().size();
36 size_t numValues = op.getCaseValues().size();
37 if (numDests != numValues) {
38 return op.emitOpError(
39 "expected number of cases to match the number of case "
41 << numDests <<
" but expected " << numValues;
51 if (!getInferredResultTypes())
53 if (!getInputResultTypes().empty()) {
54 return emitOpError(
"with inferred results cannot also have "
55 "explicit result types");
58 if (!opName.hasInterface<InferTypeOpInterface>()) {
60 <<
"has inferred results, but the created operation '" << opName
61 <<
"' does not support result type inference (or is not "
70 ArrayAttr &attrNamesAttr) {
74 auto parseOperands = [&]() {
80 attrNames.push_back(nameAttr);
81 attrOperands.push_back(operand);
94 ArrayAttr attrNames) {
95 if (attrNames.empty())
98 interleaveComma(llvm::seq<int>(0, attrNames.size()), p,
99 [&](
int i) { p << attrNames[i] <<
" = " << attrArgs[i]; });
126 UnitAttr inferredResultTypes) {
128 if (inferredResultTypes) {
129 p <<
" -> <inferred>";
134 if (!resultTypes.empty())
135 p <<
" -> (" << resultOperands <<
" : " << resultTypes <<
")";
143 Value range,
Block *successor,
bool initLoop) {
144 build(builder, state, range, successor);
148 auto rangeType = llvm::cast<pdl::RangeType>(range.
getType());
149 state.regions.front()->emplaceBlock();
150 state.regions.front()->addArgument(rangeType.getElementType(),
185 p <<
' ' << arg <<
" : " << arg.
getType() <<
" in " << getValues() <<
' ';
194 if (getRegion().getNumArguments() != 1)
195 return emitOpError(
"requires exactly one argument");
201 if (rangeType != getValues().
getType())
202 return emitOpError(
"operand must be a range of loop variable type");
213 buildWithEntryBlock(builder, state, name, type, attrs, type.getInputs());
223 parser, result,
false,
224 getFunctionTypeAttrName(result.
name), buildFuncType,
225 getArgAttrsAttrName(result.
name), getResAttrsAttrName(result.
name));
230 p, *
this,
false, getFunctionTypeAttrName(),
231 getArgAttrsAttrName(), getResAttrsAttrName());
252 if (!argumentTypes.empty()) {
263 if (argumentTypes.empty())
264 p <<
": " << resultType;
269 for (
Type operandType : getOperandTypes()) {
271 if (operandElementType != elementType) {
272 return emitOpError(
"expected operand to have element type ")
273 << elementType <<
", but got " << operandElementType;
319 #define GET_OP_CLASSES
320 #include "mlir/Dialect/PDLInterp/IR/PDLInterpOps.cpp.inc"
static MLIRContext * getContext(OpFoldResult val)
static void printRangeType(OpAsmPrinter &p, CreateRangeOp op, TypeRange argumentTypes, Type resultType)
static void printCreateOperationOpResults(OpAsmPrinter &p, CreateOperationOp op, OperandRange resultOperands, TypeRange resultTypes, UnitAttr inferredResultTypes)
static Type getGetValueTypeOpValueType(Type type)
Given the result type of a GetValueTypeOp, return the expected input type.
static ParseResult parseCreateOperationOpResults(OpAsmParser &p, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &resultOperands, SmallVectorImpl< Type > &resultTypes, UnitAttr &inferredResultTypes)
static ParseResult parseCreateOperationOpAttributes(OpAsmParser &p, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &attrOperands, ArrayAttr &attrNamesAttr)
static LogicalResult verifySwitchOp(OpT op)
static ParseResult parseRangeType(OpAsmParser &p, TypeRange argumentTypes, Type &resultType)
static void printCreateOperationOpAttributes(OpAsmPrinter &p, CreateOperationOp op, OperandRange attrArgs, ArrayAttr attrNames)
static void print(spirv::VerCapExtAttr triple, DialectAsmPrinter &printer)
virtual ParseResult parseColonTypeList(SmallVectorImpl< Type > &result)=0
Parse a colon followed by a type list, which must have at least one type.
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 parseOptionalAttrDict(NamedAttrList &result)=0
Parse a named dictionary into 'result' if it is present.
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual ParseResult parseOptionalArrow()=0
Parse a '->' token if present.
virtual ParseResult parseRBrace()=0
Parse a } token.
virtual ParseResult parseEqual()=0
Parse a = token.
virtual ParseResult parseColonType(Type &result)=0
Parse a colon followed by a type.
virtual ParseResult parseOptionalLess()=0
Parse a '<' token if present.
virtual ParseResult parseArrow()=0
Parse a '->' token.
virtual ParseResult parseGreater()=0
Parse a '>' token.
virtual ParseResult parseLParen()=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 ParseResult parseOptionalLBrace()=0
Parse a { token if present.
This class represents an argument of a Block.
Block represents an ordered list of Operations.
This class is a general helper class for creating context-global objects like types,...
FunctionType getFunctionType(TypeRange inputs, TypeRange results)
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual ParseResult parseRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region.
virtual ParseResult parseSuccessor(Block *&dest)=0
Parse a single operation successor.
virtual ParseResult parseArgument(Argument &result, bool allowType=false, bool allowAttrs=false)=0
Parse a single argument with the following syntax:
virtual ParseResult resolveOperand(const UnresolvedOperand &operand, Type type, SmallVectorImpl< Value > &result)=0
Resolve an operand to an SSA value, emitting an error on failure.
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.
virtual ParseResult parseOperandList(SmallVectorImpl< UnresolvedOperand > &result, Delimiter delimiter=Delimiter::None, bool allowResultNumber=true, int requiredOperandCount=-1)=0
Parse zero or more SSA comma-separated operand references with a specified surrounding delimiter,...
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
virtual void printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary with their values.
virtual void printSuccessor(Block *successor)=0
Print the given successor.
virtual void printRegion(Region &blocks, bool printEntryBlockArgs=true, bool printBlockTerminators=true, bool printEmptyBlock=false)=0
Prints a region.
This class helps build Operations.
This class implements the operand iterators for the Operation class.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
A named class for passing around the variadic flag.
void printFunctionOp(OpAsmPrinter &p, FunctionOpInterface op, bool isVariadic, StringRef typeAttrName, StringAttr argAttrsName, StringAttr resAttrsName)
Printer implementation for function-like operations.
ParseResult parseFunctionOp(OpAsmParser &parser, OperationState &result, bool allowVariadic, StringAttr typeAttrName, FuncTypeBuilder funcTypeBuilder, StringAttr argAttrsName, StringAttr resAttrsName)
Parser implementation for function-like operations.
Type getRangeElementTypeOrSelf(Type type)
If the given type is a range, return its element type, otherwise return the type itself.
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
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,...
This is the representation of an operand reference.
This represents an operation in an abstracted form, suitable for use with the builder APIs.
SmallVector< Value, 4 > operands
void addSuccessors(Block *successor)
Adds a successor to the operation sate. successor must not be null.
Region * addRegion()
Create a region that should be attached to the operation.