Author: Chris Morin Date: 2020-12-29T23:31:42Z New Revision: 2c8f5bd53945a209cd3cd851c63df3713fa0f9bd
URL: https://github.com/llvm/llvm-project/commit/2c8f5bd53945a209cd3cd851c63df3713fa0f9bd DIFF: https://github.com/llvm/llvm-project/commit/2c8f5bd53945a209cd3cd851c63df3713fa0f9bd.diff LOG: [MLIR] Make ComplexType buildable if its element type is buildable If a ComplexType's element type is buildable, then that ComplexType should be buildable. This is accomplished by the introduction of a new ODS class called `SameBuildabilityAs`. This can be used by other types that are conditionally buildable. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D93892 Added: Modified: mlir/include/mlir/IR/OpBase.td mlir/test/mlir-tblgen/types.mlir Removed: ################################################################################ diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 857a652f17d9..c65cc22c90f0 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -333,6 +333,13 @@ class BuildableType<code builder> { code builderCall = builder; } +// A type that's buildable iff the type passed as an argument is buildable. +// This is intended for use by types like container types, which are only +// buildable if the type of their elements is buildable. +class SameBuildabilityAs<Type type, code builder> { + code builderCall = !if(!empty(type.builderCall), "", builder); +} + // Any type at all. def AnyType : Type<CPred<"true">, "any type">; @@ -479,7 +486,9 @@ class Complex<Type type> "$_self.cast<::mlir::ComplexType>().getElementType()", type.predicate>]>, "complex type with " # type.description # " elements", - "::mlir::ComplexType"> { + "::mlir::ComplexType">, + SameBuildabilityAs<type, "::mlir::ComplexType::get($_builder.get" # type # + "Type())"> { Type elementType = type; } diff --git a/mlir/test/mlir-tblgen/types.mlir b/mlir/test/mlir-tblgen/types.mlir index 5e4dac33012b..61727d18e68f 100644 --- a/mlir/test/mlir-tblgen/types.mlir +++ b/mlir/test/mlir-tblgen/types.mlir @@ -58,7 +58,7 @@ func @complex_f64_tensor_success() { // ----- func @complex_f64_failure() { - // expected-error@+1 {{must be complex type with 64-bit float elements}} + // expected-error@+1 {{op inferred type incompatible with return type of operation}} "test.complex_f64"() : () -> (f64) return } _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits