diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -1150,6 +1150,11 @@ return verifySingleInputPoolingOp(op); } +namespace { +struct EraseDeadLinalgOp; +struct FoldTensorCastOp; +} // namespace + #include "mlir/Dialect/Linalg/IR/LinalgStructuredOpsInterfaces.cpp.inc" #include "mlir/Dialect/Linalg/IR/LinalgNamedStructuredOps.cpp.inc" @@ -1578,18 +1583,4 @@ CANONICALIZERS_AND_FOLDERS(GenericOp) CANONICALIZERS_AND_FOLDERS(IndexedGenericOp) -// TODO: Determine whether we can generate the folders and verifiers. -CANONICALIZERS_AND_FOLDERS(BatchMatmulOp) -CANONICALIZERS_AND_FOLDERS(DotOp) -CANONICALIZERS_AND_FOLDERS(MatmulOp) -CANONICALIZERS_AND_FOLDERS(MatvecOp) -CANONICALIZERS_AND_FOLDERS(VecmatOp) -CANONICALIZERS_AND_FOLDERS(ConvWOp) -CANONICALIZERS_AND_FOLDERS(ConvNWCOp) -CANONICALIZERS_AND_FOLDERS(ConvNCWOp) -CANONICALIZERS_AND_FOLDERS(ConvHWOp) -CANONICALIZERS_AND_FOLDERS(ConvNHWCOp) -CANONICALIZERS_AND_FOLDERS(ConvNCHWOp) -CANONICALIZERS_AND_FOLDERS(ConvDHWOp) -CANONICALIZERS_AND_FOLDERS(ConvNDHWCOp) -CANONICALIZERS_AND_FOLDERS(ConvNCDHWOp) +// All named ops canonicalizers and folders are auto-generated in the .cpp.inc. diff --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp --- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp +++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp @@ -994,6 +994,10 @@ void printRegionBuilder(llvm::raw_ostream &os, StringRef cppOpName, ComprehensionParsingState &state); + /// Print the C++ impl for named ops canonicalizers and fodlers. + void printCanonicalizersAndFolders(llvm::raw_ostream &os, + StringRef cppOpName); + private: //===--------------------------------------------------------------------===// // Internal bookkeeping of tensors. @@ -1430,6 +1434,7 @@ printReferenceIterators(ss, cppOpName, state); printReferenceIndexingMaps(ss, cppOpName, state); printRegionBuilder(ss, cppOpName, state); + printCanonicalizersAndFolders(ss, cppOpName); ss.flush(); os << extraMethods << "\n"; } @@ -1571,6 +1576,22 @@ os << llvm::formatv(referenceReferenceIteratorsFmt, cppOpName, iteratorsStr); } +void TCParser::printCanonicalizersAndFolders(llvm::raw_ostream &os, + StringRef cppOpName) { + const char *canonicalizersAndFoldersFmt = R"FMT( + void {0}::getCanonicalizationPatterns( + OwningRewritePatternList &results, + MLIRContext *context) {{ + results.insert(); + results.insert(); + } + LogicalResult {0}::fold(ArrayRef, + SmallVectorImpl &) {{ + return foldMemRefCast(*this); + })FMT"; + os << llvm::formatv(canonicalizersAndFoldersFmt, cppOpName); +} + /// Print the C++ StructuredOpsInterface impl of `referenceIndexingMaps`. void TCParser::printReferenceIndexingMaps(llvm::raw_ostream &os, StringRef cppOpName,