diff --git a/mlir/include/mlir/IR/DialectBase.td b/mlir/include/mlir/IR/DialectBase.td --- a/mlir/include/mlir/IR/DialectBase.td +++ b/mlir/include/mlir/IR/DialectBase.td @@ -35,19 +35,6 @@ // Dialect definitions //===----------------------------------------------------------------------===// -class EmitFolderBase; -// Generate 'fold' method with 'ArrayRef' parameter. -// New code should prefer using 'kEmitFoldAdaptorFolder' and -// consider 'kEmitRawAttributesFolder' deprecated and to be -// removed in the future. -def kEmitRawAttributesFolder : EmitFolderBase, Deprecated< - "'useFoldAPI' of 'kEmitRawAttributesFolder' (default) has been deprecated " - # "and is pending removal. Please switch to 'kEmitFoldAdaptorFolder'. See " - # "https://discourse.llvm.org/t/psa-new-improved-fold-method-signature-has-landed-please-update-your-downstream-projects/67618" -> {} -// Generate 'fold' method with 'FoldAdaptor' parameter. -def kEmitFoldAdaptorFolder : EmitFolderBase {} - class Dialect { // The name of the dialect. string name = ?; @@ -116,9 +103,6 @@ // If this dialect can be extended at runtime with new operations or types. bit isExtensible = 0; - - // Fold API to use for operations in this dialect. - EmitFolderBase useFoldAPI = kEmitFoldAdaptorFolder; } #endif // DIALECTBASE_TD diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -1688,33 +1688,17 @@ /// Trait to check if T provides a 'fold' method for a single result op. template using has_single_result_fold_t = - decltype(std::declval().fold(std::declval>())); + decltype(std::declval().fold(std::declval())); template constexpr static bool has_single_result_fold_v = llvm::is_detected::value; /// Trait to check if T provides a general 'fold' method. template using has_fold_t = decltype(std::declval().fold( - std::declval>(), + std::declval(), std::declval &>())); template constexpr static bool has_fold_v = llvm::is_detected::value; - /// Trait to check if T provides a 'fold' method with a FoldAdaptor for a - /// single result op. - template - using has_fold_adaptor_single_result_fold_t = - decltype(std::declval().fold(std::declval())); - template - constexpr static bool has_fold_adaptor_single_result_v = - llvm::is_detected::value; - /// Trait to check if T provides a general 'fold' method with a FoldAdaptor. - template - using has_fold_adaptor_fold_t = decltype(std::declval().fold( - std::declval(), - std::declval &>())); - template - constexpr static bool has_fold_adaptor_v = - llvm::is_detected::value; /// Trait to check if T provides a 'print' method. template @@ -1764,14 +1748,13 @@ // If the operation is single result and defines a `fold` method. if constexpr (llvm::is_one_of, Traits...>::value && - (has_single_result_fold_v || - has_fold_adaptor_single_result_v)) + has_single_result_fold_v) return [](Operation *op, ArrayRef operands, SmallVectorImpl &results) { return foldSingleResultHook(op, operands, results); }; // The operation is not single result and defines a `fold` method. - if constexpr (has_fold_v || has_fold_adaptor_v) + if constexpr (has_fold_v) return [](Operation *op, ArrayRef operands, SmallVectorImpl &results) { return foldHook(op, operands, results); @@ -1790,12 +1773,9 @@ static LogicalResult foldSingleResultHook(Operation *op, ArrayRef operands, SmallVectorImpl &results) { - OpFoldResult result; - if constexpr (has_fold_adaptor_single_result_v) - result = cast(op).fold(typename ConcreteOpT::FoldAdaptor( - operands, op->getAttrDictionary(), op->getRegions())); - else - result = cast(op).fold(operands); + OpFoldResult result = + cast(op).fold(typename ConcreteOpT::FoldAdaptor( + operands, op->getAttrDictionary(), op->getRegions())); // If the fold failed or was in-place, try to fold the traits of the // operation. @@ -1812,15 +1792,10 @@ template static LogicalResult foldHook(Operation *op, ArrayRef operands, SmallVectorImpl &results) { - auto result = LogicalResult::failure(); - if constexpr (has_fold_adaptor_v) { - result = cast(op).fold( - typename ConcreteOpT::FoldAdaptor(operands, op->getAttrDictionary(), - op->getRegions()), - results); - } else { - result = cast(op).fold(operands, results); - } + LogicalResult result = cast(op).fold( + typename ConcreteOpT::FoldAdaptor(operands, op->getAttrDictionary(), + op->getRegions()), + results); // If the fold failed or was in-place, try to fold the traits of the // operation. diff --git a/mlir/include/mlir/TableGen/Dialect.h b/mlir/include/mlir/TableGen/Dialect.h --- a/mlir/include/mlir/TableGen/Dialect.h +++ b/mlir/include/mlir/TableGen/Dialect.h @@ -86,15 +86,6 @@ /// operations or types. bool isExtensible() const; - enum class FolderAPI { - RawAttributes = 0, /// fold method with ArrayRef. - FolderAdaptor = 1, /// fold method with the operation's FoldAdaptor. - }; - - /// Returns the folder API that should be emitted for operations in this - /// dialect. - FolderAPI getFolderAPI() const; - // Returns whether two dialects are equal by checking the equality of the // underlying record. bool operator==(const Dialect &other) const; diff --git a/mlir/lib/TableGen/Dialect.cpp b/mlir/lib/TableGen/Dialect.cpp --- a/mlir/lib/TableGen/Dialect.cpp +++ b/mlir/lib/TableGen/Dialect.cpp @@ -103,21 +103,6 @@ return def->getValueAsBit("isExtensible"); } -Dialect::FolderAPI Dialect::getFolderAPI() const { - llvm::Record *value = def->getValueAsDef("useFoldAPI"); - auto converted = - llvm::StringSwitch>(value->getName()) - .Case("kEmitRawAttributesFolder", FolderAPI::RawAttributes) - .Case("kEmitFoldAdaptorFolder", FolderAPI::FolderAdaptor) - .Default(std::nullopt); - - if (!converted) - llvm::PrintFatalError(def->getLoc(), - "Invalid value for dialect field `useFoldAPI`"); - - return *converted; -} - bool Dialect::operator==(const Dialect &other) const { return def == other.def; } diff --git a/mlir/test/mlir-tblgen/has-fold-invalid-values.td b/mlir/test/mlir-tblgen/has-fold-invalid-values.td deleted file mode 100644 --- a/mlir/test/mlir-tblgen/has-fold-invalid-values.td +++ /dev/null @@ -1,17 +0,0 @@ -// RUN: not mlir-tblgen -gen-op-decls -I %S/../../include %s 2>&1 | FileCheck %s - -include "mlir/IR/OpBase.td" - -def Bad : EmitFolderBase; - -def Test_Dialect : Dialect { - let name = "test"; - let cppNamespace = "NS"; - let useFoldAPI = Bad; -} - -def InvalidValue_Op : Op { - let hasFolder = 1; -} - -// CHECK: Invalid value for dialect field `useFoldAPI` diff --git a/mlir/test/mlir-tblgen/op-decl-and-defs.td b/mlir/test/mlir-tblgen/op-decl-and-defs.td --- a/mlir/test/mlir-tblgen/op-decl-and-defs.td +++ b/mlir/test/mlir-tblgen/op-decl-and-defs.td @@ -12,7 +12,6 @@ def Test_Dialect : Dialect { let name = "test"; let cppNamespace = "NS"; - let useFoldAPI = kEmitRawAttributesFolder; } class NS_Op traits> : Op; @@ -120,7 +119,7 @@ // CHECK: void print(::mlir::OpAsmPrinter &p); // CHECK: ::mlir::LogicalResult verifyInvariants(); // CHECK: static void getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context); -// CHECK: ::mlir::LogicalResult fold(::llvm::ArrayRef<::mlir::Attribute> operands, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results); +// CHECK: ::mlir::LogicalResult fold(FoldAdaptor adaptor, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results); // CHECK: // Display a graph for debugging purposes. // CHECK: void displayGraph(); // CHECK: }; @@ -322,12 +321,7 @@ // CHECK: static void build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); // CHECK: static void build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes = {}); -def TestWithNewFold_Dialect : Dialect { - let name = "test"; - let cppNamespace = "::mlir::testWithFold"; -} - -def NS_MOp : Op { +def NS_MOp : NS_Op<"op_with_single_result_and_fold_adaptor_fold", []> { let results = (outs AnyType:$res); let hasFolder = 1; @@ -336,15 +330,6 @@ // CHECK-LABEL: class MOp : // CHECK: ::mlir::OpFoldResult fold(FoldAdaptor adaptor); -def NS_NOp : Op { - let results = (outs AnyType:$res1, AnyType:$res2); - - let hasFolder = 1; -} - -// CHECK-LABEL: class NOp : -// CHECK: ::mlir::LogicalResult fold(FoldAdaptor adaptor, ::llvm::SmallVectorImpl<::mlir::OpFoldResult> &results); - // Test that type defs have the proper namespaces when used as a constraint. // --- diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -2342,12 +2342,8 @@ if (!op.hasFolder()) return; - Dialect::FolderAPI folderApi = op.getDialect().getFolderAPI(); SmallVector paramList; - if (folderApi == Dialect::FolderAPI::RawAttributes) - paramList.emplace_back("::llvm::ArrayRef<::mlir::Attribute>", "operands"); - else - paramList.emplace_back("FoldAdaptor", "adaptor"); + paramList.emplace_back("FoldAdaptor", "adaptor"); StringRef retType; bool hasSingleResult =