// Dialect definitions
//===----------------------------------------------------------------------===//
-class EmitFolderBase;
-// Generate 'fold' method with 'ArrayRef<Attribute>' 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 = ?;
// 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
/// Trait to check if T provides a 'fold' method for a single result op.
template <typename T, typename... Args>
using has_single_result_fold_t =
- decltype(std::declval<T>().fold(std::declval<ArrayRef<Attribute>>()));
+ decltype(std::declval<T>().fold(std::declval<typename T::FoldAdaptor>()));
template <typename T>
constexpr static bool has_single_result_fold_v =
llvm::is_detected<has_single_result_fold_t, T>::value;
/// Trait to check if T provides a general 'fold' method.
template <typename T, typename... Args>
using has_fold_t = decltype(std::declval<T>().fold(
- std::declval<ArrayRef<Attribute>>(),
+ std::declval<typename T::FoldAdaptor>(),
std::declval<SmallVectorImpl<OpFoldResult> &>()));
template <typename T>
constexpr static bool has_fold_v = llvm::is_detected<has_fold_t, T>::value;
- /// Trait to check if T provides a 'fold' method with a FoldAdaptor for a
- /// single result op.
- template <typename T, typename... Args>
- using has_fold_adaptor_single_result_fold_t =
- decltype(std::declval<T>().fold(std::declval<typename T::FoldAdaptor>()));
- template <class T>
- constexpr static bool has_fold_adaptor_single_result_v =
- llvm::is_detected<has_fold_adaptor_single_result_fold_t, T>::value;
- /// Trait to check if T provides a general 'fold' method with a FoldAdaptor.
- template <typename T, typename... Args>
- using has_fold_adaptor_fold_t = decltype(std::declval<T>().fold(
- std::declval<typename T::FoldAdaptor>(),
- std::declval<SmallVectorImpl<OpFoldResult> &>()));
- template <class T>
- constexpr static bool has_fold_adaptor_v =
- llvm::is_detected<has_fold_adaptor_fold_t, T>::value;
/// Trait to check if T provides a 'print' method.
template <typename T, typename... Args>
// If the operation is single result and defines a `fold` method.
if constexpr (llvm::is_one_of<OpTrait::OneResult<ConcreteType>,
Traits<ConcreteType>...>::value &&
- (has_single_result_fold_v<ConcreteType> ||
- has_fold_adaptor_single_result_v<ConcreteType>))
+ has_single_result_fold_v<ConcreteType>)
return [](Operation *op, ArrayRef<Attribute> operands,
SmallVectorImpl<OpFoldResult> &results) {
return foldSingleResultHook<ConcreteType>(op, operands, results);
};
// The operation is not single result and defines a `fold` method.
- if constexpr (has_fold_v<ConcreteType> || has_fold_adaptor_v<ConcreteType>)
+ if constexpr (has_fold_v<ConcreteType>)
return [](Operation *op, ArrayRef<Attribute> operands,
SmallVectorImpl<OpFoldResult> &results) {
return foldHook<ConcreteType>(op, operands, results);
static LogicalResult
foldSingleResultHook(Operation *op, ArrayRef<Attribute> operands,
SmallVectorImpl<OpFoldResult> &results) {
- OpFoldResult result;
- if constexpr (has_fold_adaptor_single_result_v<ConcreteOpT>)
- result = cast<ConcreteOpT>(op).fold(typename ConcreteOpT::FoldAdaptor(
- operands, op->getAttrDictionary(), op->getRegions()));
- else
- result = cast<ConcreteOpT>(op).fold(operands);
+ OpFoldResult result =
+ cast<ConcreteOpT>(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.
template <typename ConcreteOpT>
static LogicalResult foldHook(Operation *op, ArrayRef<Attribute> operands,
SmallVectorImpl<OpFoldResult> &results) {
- auto result = LogicalResult::failure();
- if constexpr (has_fold_adaptor_v<ConcreteOpT>) {
- result = cast<ConcreteOpT>(op).fold(
- typename ConcreteOpT::FoldAdaptor(operands, op->getAttrDictionary(),
- op->getRegions()),
- results);
- } else {
- result = cast<ConcreteOpT>(op).fold(operands, results);
- }
+ LogicalResult result = cast<ConcreteOpT>(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.
def Test_Dialect : Dialect {
let name = "test";
let cppNamespace = "NS";
- let useFoldAPI = kEmitRawAttributesFolder;
}
class NS_Op<string mnemonic, list<Trait> traits> :
Op<Test_Dialect, mnemonic, traits>;
// 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: };
// 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<TestWithNewFold_Dialect, "op_with_single_result_and_fold_adaptor_fold", []> {
+def NS_MOp : NS_Op<"op_with_single_result_and_fold_adaptor_fold", []> {
let results = (outs AnyType:$res);
let hasFolder = 1;
// CHECK-LABEL: class MOp :
// CHECK: ::mlir::OpFoldResult fold(FoldAdaptor adaptor);
-def NS_NOp : Op<TestWithNewFold_Dialect, "op_with_multiple_results_and_fold_adaptor_fold", []> {
- 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.
// ---