15using namespace mlir::pdl_interp;
17#include "mlir/Dialect/PDLInterp/IR/PDLInterpOpsDialect.cpp.inc"
23void PDLInterpDialect::initialize() {
26#include "mlir/Dialect/PDLInterp/IR/PDLInterpOps.cpp.inc"
30template <
typename OpT>
34 size_t numDests = op.getCases().size();
35 size_t numValues = op.getCaseValues().size();
36 if (numDests != numValues) {
37 return op.emitOpError(
38 "expected number of cases to match the number of case "
40 << numDests <<
" but expected " << numValues;
49LogicalResult CreateOperationOp::verify() {
50 if (!getInferredResultTypes())
52 if (!getInputResultTypes().empty()) {
53 return emitOpError(
"with inferred results cannot also have "
54 "explicit result types");
57 if (!opName.hasInterface<InferTypeOpInterface>()) {
59 <<
"has inferred results, but the created operation '" << opName
60 <<
"' does not support result type inference (or is not "
73 auto parseOperands = [&]() {
79 attrNames.push_back(nameAttr);
80 attrOperands.push_back(operand);
94 if (attrNames.empty())
97 interleaveComma(llvm::seq<int>(0, attrNames.size()), p,
98 [&](
int i) { p << attrNames[i] <<
" = " << attrArgs[i]; });
125 UnitAttr inferredResultTypes) {
127 if (inferredResultTypes) {
128 p <<
" -> <inferred>";
133 if (!resultTypes.empty())
134 p <<
" -> (" << resultOperands <<
" : " << resultTypes <<
")";
142 Value range,
Block *successor,
bool initLoop) {
143 build(builder, state, range, successor);
147 auto rangeType = llvm::cast<pdl::RangeType>(range.
getType());
148 state.
regions.front()->emplaceBlock();
149 state.
regions.front()->addArgument(rangeType.getElementType(),
165 Type rangeType = pdl::RangeType::get(loopVariable.
type);
178 result.addSuccessors(successor);
184 p <<
' ' << arg <<
" : " << arg.
getType() <<
" in " << getValues() <<
' ';
191LogicalResult ForEachOp::verify() {
193 if (getRegion().getNumArguments() != 1)
194 return emitOpError(
"requires exactly one argument");
199 Type rangeType = pdl::RangeType::get(arg.
getType());
200 if (rangeType != getValues().
getType())
201 return emitOpError(
"operand must be a range of loop variable type");
212 buildWithEntryBlock(builder, state, name, type, attrs, type.getInputs());
223 getFunctionTypeAttrName(
result.name), buildFuncType,
224 getArgAttrsAttrName(
result.name), getResAttrsAttrName(
result.name));
229 p, *
this,
false, getFunctionTypeAttrName(),
230 getArgAttrsAttrName(), getResAttrsAttrName());
240 return llvm::isa<pdl::RangeType>(type) ? pdl::RangeType::get(valueTy)
251 if (!argumentTypes.empty()) {
262 if (argumentTypes.empty())
263 p <<
": " << resultType;
266LogicalResult CreateRangeOp::verify() {
268 for (
Type operandType : getOperandTypes()) {
270 if (operandElementType != elementType) {
271 return emitOpError(
"expected operand to have element type ")
272 << elementType <<
", but got " << operandElementType;
282LogicalResult SwitchAttributeOp::verify() {
return verifySwitchOp(*
this); }
288LogicalResult SwitchOperandCountOp::verify() {
return verifySwitchOp(*
this); }
294LogicalResult SwitchOperationNameOp::verify() {
return verifySwitchOp(*
this); }
300LogicalResult SwitchResultCountOp::verify() {
return verifySwitchOp(*
this); }
306LogicalResult SwitchTypeOp::verify() {
return verifySwitchOp(*
this); }
312LogicalResult SwitchTypesOp::verify() {
return verifySwitchOp(*
this); }
318#define GET_OP_CLASSES
319#include "mlir/Dialect/PDLInterp/IR/PDLInterpOps.cpp.inc"
p<< " : "<< getMemRefType()<< ", "<< getType();}static LogicalResult verifyVectorMemoryOp(Operation *op, MemRefType memrefType, VectorType vectorType) { if(memrefType.getElementType() !=vectorType.getElementType()) return op-> emitOpError("requires memref and vector types of the same elemental type")
Given a list of lists of parsed operands, populates uniqueOperands with unique operands.
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)
virtual ParseResult parseColonTypeList(SmallVectorImpl< Type > &result)=0
Parse a colon followed by a type list, which must have at least one type.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
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 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.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
This is the representation of an operand reference.
This represents an operation in an abstracted form, suitable for use with the builder APIs.
SmallVector< std::unique_ptr< Region >, 1 > regions
Regions that the op will hold.