[MLIR] Make ComplexType buildable if its element type is buildable
authorChris Morin <cmtm@google.com>
Tue, 29 Dec 2020 22:04:55 +0000 (22:04 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Tue, 29 Dec 2020 23:31:42 +0000 (23:31 +0000)
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

mlir/include/mlir/IR/OpBase.td
mlir/test/mlir-tblgen/types.mlir

index 857a652..c65cc22 100644 (file)
@@ -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;
 }
 
index 5e4dac3..61727d1 100644 (file)
@@ -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
 }