[PATCH] D119700: [flang] Enable complex type in function lowering

Valentin Clement via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 14 13:09:14 PST 2022


clementval updated this revision to Diff 408589.
clementval added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119700/new/

https://reviews.llvm.org/D119700

Files:
  flang/lib/Lower/ConvertType.cpp
  flang/test/Lower/basic-function.f90


Index: flang/test/Lower/basic-function.f90
===================================================================
--- flang/test/Lower/basic-function.f90
+++ flang/test/Lower/basic-function.f90
@@ -67,3 +67,33 @@
 end
 ! CHECK-LABEL: func @_QPlfct4() -> !fir.logical<8>
 ! CHECK:         return %{{.*}} : !fir.logical<8>
+
+complex(2) function cplxfct1()
+end
+! CHECK-LABEL: func @_QPcplxfct1() -> !fir.complex<2>
+! CHECK:         return %{{.*}} : !fir.complex<2>
+
+complex(3) function cplxfct2()
+end
+! CHECK-LABEL: func @_QPcplxfct2() -> !fir.complex<3>
+! CHECK:         return %{{.*}} : !fir.complex<3>
+
+complex(4) function cplxfct3()
+end
+! CHECK-LABEL: func @_QPcplxfct3() -> !fir.complex<4>
+! CHECK:         return %{{.*}} : !fir.complex<4>
+
+complex(8) function cplxfct4()
+end
+! CHECK-LABEL: func @_QPcplxfct4() -> !fir.complex<8>
+! CHECK:         return %{{.*}} : !fir.complex<8>
+
+complex(10) function cplxfct5()
+end
+! CHECK-LABEL: func @_QPcplxfct5() -> !fir.complex<10>
+! CHECK:         return %{{.*}} : !fir.complex<10>
+
+complex(16) function cplxfct6()
+end
+! CHECK-LABEL: func @_QPcplxfct6() -> !fir.complex<16>
+! CHECK:         return %{{.*}} : !fir.complex<16>
Index: flang/lib/Lower/ConvertType.cpp
===================================================================
--- flang/lib/Lower/ConvertType.cpp
+++ flang/lib/Lower/ConvertType.cpp
@@ -54,6 +54,13 @@
   return {};
 }
 
+static mlir::Type genComplexType(mlir::MLIRContext *context, int KIND) {
+  if (Fortran::evaluate::IsValidKindOfIntrinsicType(
+          Fortran::common::TypeCategory::Complex, KIND))
+    return fir::ComplexType::get(context, KIND);
+  return {};
+}
+
 static mlir::Type genFIRType(mlir::MLIRContext *context,
                              Fortran::common::TypeCategory tc, int kind) {
   switch (tc) {
@@ -62,7 +69,7 @@
   case Fortran::common::TypeCategory::Integer:
     return genIntegerType(context, kind);
   case Fortran::common::TypeCategory::Complex:
-    TODO_NOLOC("genFIRType Complex");
+    return genComplexType(context, kind);
   case Fortran::common::TypeCategory::Logical:
     return genLogicalType(context, kind);
   case Fortran::common::TypeCategory::Character:
@@ -177,16 +184,6 @@
   return {};
 }
 
-template <>
-mlir::Type
-genFIRType<Fortran::common::TypeCategory::Complex>(mlir::MLIRContext *context,
-                                                   int KIND) {
-  if (Fortran::evaluate::IsValidKindOfIntrinsicType(
-          Fortran::common::TypeCategory::Complex, KIND))
-    return fir::ComplexType::get(context, KIND);
-  return {};
-}
-
 namespace {
 
 /// Discover the type of an Fortran::evaluate::Expr<T> and convert it to an


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119700.408589.patch
Type: text/x-patch
Size: 2679 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220214/63d639c5/attachment.bin>


More information about the llvm-commits mailing list