20 changes: 16 additions & 4 deletions mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,7 @@ def {0} : LinalgStructuredBase_Op<"{1}", !listconcat([AttrSizedOperandSegments],
}]>
{5}
];
let printer = [{{ return ::printNamedStructuredOp(p, *this); }];
let parser = [{{
return ::parseNamedStructuredOp<{0}>(parser, result);
}];
let hasCustomAssemblyFormat = 1;
let hasFolder = 1;
let extraClassDeclaration = structuredOpsBaseDecls # [{{
Expand Down Expand Up @@ -588,6 +585,18 @@ void {0}::getEffects(SmallVectorImpl<
}
)FMT";

// Implementation of parse/print.
// Parameters:
// {0}: Class name
static const char structuredOpParserFormat[] = R"FMT(
ParseResult {0}::parse(OpAsmParser &parser, OperationState &result) {{
return ::parseNamedStructuredOp<{0}>(parser, result);
}
void {0}::print(OpAsmPrinter &p) {{
::printNamedStructuredOp(p, *this);
}
)FMT";

static LogicalResult generateNamedGenericOpOds(LinalgOpConfig &opConfig,
GenerationContext &genContext) {
if (!genContext.shouldGenerateOds())
Expand Down Expand Up @@ -1008,6 +1017,9 @@ void {0}::regionBuilder(ImplicitLocOpBuilder &b, Block &block) {{
interleaveToString(stmts, "\n "));
}

// Parser and printer.
os << llvm::formatv(structuredOpParserFormat, className);

// Canonicalizers and folders.
os << llvm::formatv(structuredOpFoldersFormat, className);

Expand Down