[flang-commits] [PATCH] D139180: [flang] Lower complex constructor to HLFIR

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Dec 2 05:20:59 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rG26ceeee7575f: [flang] Lower complex constructor to HLFIR (authored by jeanPerier).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139180

Files:
  flang/lib/Lower/ConvertExprToHLFIR.cpp
  flang/test/Lower/HLFIR/binary-ops.f90


Index: flang/test/Lower/HLFIR/binary-ops.f90
===================================================================
--- flang/test/Lower/HLFIR/binary-ops.f90
+++ flang/test/Lower/HLFIR/binary-ops.f90
@@ -323,3 +323,30 @@
 end subroutine
 ! CHECK-LABEL: func.func @_QPlogical_neqv(
 ! CHECK:  %[[VAL_10:.*]] = arith.cmpi ne
+
+subroutine cmplx_ctor(z, x, y)
+  complex :: z
+  real :: x, y
+  z = cmplx(x, y)
+end subroutine
+! CHECK-LABEL: func.func @_QPcmplx_ctor(
+! CHECK:  %[[VAL_3:.*]]:2 = hlfir.declare %{{.*}}x"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! CHECK:  %[[VAL_4:.*]]:2 = hlfir.declare %{{.*}}y"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! CHECK:  %[[VAL_6:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref<f32>
+! CHECK:  %[[VAL_7:.*]] = fir.load %[[VAL_4]]#0 : !fir.ref<f32>
+! CHECK:  %[[VAL_8:.*]] = fir.undefined !fir.complex<4>
+! CHECK:  %[[VAL_9:.*]] = fir.insert_value %[[VAL_8]], %[[VAL_6]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
+! CHECK:  %[[VAL_10:.*]] = fir.insert_value %[[VAL_9]], %[[VAL_7]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
+
+subroutine cmplx_ctor_2(z, x)
+  complex(8) :: z
+  real(8) :: x
+  z = cmplx(x, 1._8, kind=8)
+end subroutine
+! CHECK-LABEL: func.func @_QPcmplx_ctor_2(
+! CHECK:  %[[VAL_2:.*]]:2 = hlfir.declare %{{.*}}x"} : (!fir.ref<f64>) -> (!fir.ref<f64>, !fir.ref<f64>)
+! CHECK:  %[[VAL_4:.*]] = fir.load %[[VAL_2]]#0 : !fir.ref<f64>
+! CHECK:  %[[VAL_5:.*]] = arith.constant 1.000000e+00 : f64
+! CHECK:  %[[VAL_6:.*]] = fir.undefined !fir.complex<8>
+! CHECK:  %[[VAL_7:.*]] = fir.insert_value %[[VAL_6]], %[[VAL_4]], [0 : index] : (!fir.complex<8>, f64) -> !fir.complex<8>
+! CHECK:  %[[VAL_8:.*]] = fir.insert_value %[[VAL_7]], %[[VAL_5]], [1 : index] : (!fir.complex<8>, f64) -> !fir.complex<8>
Index: flang/lib/Lower/ConvertExprToHLFIR.cpp
===================================================================
--- flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -20,6 +20,7 @@
 #include "flang/Lower/IntrinsicCall.h"
 #include "flang/Lower/StatementContext.h"
 #include "flang/Lower/SymbolMap.h"
+#include "flang/Optimizer/Builder/Complex.h"
 #include "flang/Optimizer/Builder/Runtime/Character.h"
 #include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/HLFIR/HLFIROps.h"
@@ -487,6 +488,19 @@
   }
 };
 
+template <int KIND>
+struct BinaryOp<Fortran::evaluate::ComplexConstructor<KIND>> {
+  using Op = Fortran::evaluate::ComplexConstructor<KIND>;
+  static hlfir::EntityWithAttributes gen(mlir::Location loc,
+                                         fir::FirOpBuilder &builder,
+                                         const Op &op, hlfir::Entity lhs,
+                                         hlfir::Entity rhs) {
+    mlir::Value res =
+        fir::factory::Complex{builder, loc}.createComplex(KIND, lhs, rhs);
+    return hlfir::EntityWithAttributes{res};
+  }
+};
+
 /// Lower Expr to HLFIR.
 class HlfirBuilder {
 public:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139180.479606.patch
Type: text/x-patch
Size: 2992 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221202/33915eab/attachment.bin>


More information about the flang-commits mailing list