[PATCH] D120402: [flang] Lower complex constant
Valentin Clement via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 23 04:06:22 PST 2022
clementval created this revision.
clementval added reviewers: jeanPerier, PeteSteinfeld, schweitz, svedanayagam, klausler.
Herald added subscribers: mehdi_amini, kristof.beyls.
Herald added a reviewer: sscalpone.
Herald added a project: Flang.
clementval requested review of this revision.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
Add ability to lower complex constant.
This patch is part of the upstreaming effort from fir-dev branch.
Co-authored-by: Kiran Chandramohan <kiran.chandramohan at arm.com>
Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>
Co-authored-by: Jean Perier <jperier at nvidia.com>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D120402
Files:
flang/lib/Lower/ConvertExpr.cpp
flang/test/Lower/assignment.f90
Index: flang/test/Lower/assignment.f90
===================================================================
--- flang/test/Lower/assignment.f90
+++ flang/test/Lower/assignment.f90
@@ -284,3 +284,17 @@
! CHECK: fir.store %[[C10]] to %[[D]] : !fir.ref<f80>
! CHECK: %[[C16:.*]] = arith.constant 1.600000e+01 : f128
! CHECK: fir.store %[[C16]] to %[[E]] : !fir.ref<f128>
+
+subroutine complex_constant()
+ complex(4) :: a
+ a = (0, 1)
+end
+
+! CHECK-LABEL: func @_QPcomplex_constant()
+! CHECK: %[[A:.*]] = fir.alloca !fir.complex<4> {bindc_name = "a", uniq_name = "_QFcomplex_constantEa"}
+! CHECK: %[[C0:.*]] = arith.constant 0.000000e+00 : f32
+! CHECK: %[[C1:.*]] = arith.constant 1.000000e+00 : f32
+! CHECK: %[[UNDEF:.*]] = fir.undefined !fir.complex<4>
+! CHECK: %[[INS0:.*]] = fir.insert_value %[[UNDEF]], %[[C0]], [0 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
+! CHECK: %[[INS1:.*]] = fir.insert_value %[[INS0]], %[[C1]], [1 : index] : (!fir.complex<4>, f32) -> !fir.complex<4>
+! CHECK: fir.store %[[INS1]] to %[[A]] : !fir.ref<!fir.complex<4>>
Index: flang/lib/Lower/ConvertExpr.cpp
===================================================================
--- flang/lib/Lower/ConvertExpr.cpp
+++ flang/lib/Lower/ConvertExpr.cpp
@@ -19,6 +19,7 @@
#include "flang/Lower/IntrinsicCall.h"
#include "flang/Lower/SymbolMap.h"
#include "flang/Lower/Todo.h"
+#include "flang/Optimizer/Builder/Complex.h"
#include "flang/Semantics/expression.h"
#include "flang/Semantics/symbol.h"
#include "flang/Semantics/tools.h"
@@ -277,7 +278,9 @@
template <int KIND>
ExtValue genval(const Fortran::evaluate::ComplexConstructor<KIND> &op) {
- TODO(getLoc(), "genval ComplexConstructor");
+ mlir::Value realPartValue = genunbox(op.left());
+ return fir::factory::Complex{builder, getLoc()}.createComplex(
+ KIND, realPartValue, genunbox(op.right()));
}
template <int KIND>
@@ -381,7 +384,14 @@
return genRealConstant<KIND>(builder.getContext(), floatVal);
}
} else if constexpr (TC == Fortran::common::TypeCategory::Complex) {
- TODO(getLoc(), "genval complex constant");
+ using TR =
+ Fortran::evaluate::Type<Fortran::common::TypeCategory::Real, KIND>;
+ Fortran::evaluate::ComplexConstructor<KIND> ctor(
+ Fortran::evaluate::Expr<TR>{
+ Fortran::evaluate::Constant<TR>{value.REAL()}},
+ Fortran::evaluate::Expr<TR>{
+ Fortran::evaluate::Constant<TR>{value.AIMAG()}});
+ return genunbox(ctor);
} else /*constexpr*/ {
llvm_unreachable("unhandled constant");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120402.410770.patch
Type: text/x-patch
Size: 2662 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220223/661cdfb1/attachment.bin>
More information about the llvm-commits
mailing list