[flang-commits] [flang] 944dca7 - [flang][NFC] Remove obsolete ComplexExpr helper

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Fri Jan 28 12:02:19 PST 2022


Author: Valentin Clement
Date: 2022-01-28T21:02:14+01:00
New Revision: 944dca758f1c25706b0150ea238f46c8707b95af

URL: https://github.com/llvm/llvm-project/commit/944dca758f1c25706b0150ea238f46c8707b95af
DIFF: https://github.com/llvm/llvm-project/commit/944dca758f1c25706b0150ea238f46c8707b95af.diff

LOG: [flang][NFC] Remove obsolete ComplexExpr helper

Functionality present in `flang/include/flang/Lower/ComplexExpr.h` are
available in `flang/include/flang/Optimizer/Builder/Complex.h`. This patch removes
the obsolete files.

Reviewed By: kiranchandramohan, schweitz

Differential Revision: https://reviews.llvm.org/D118462

Added: 
    

Modified: 
    flang/lib/Lower/CMakeLists.txt
    flang/lib/Lower/IO.cpp
    flang/lib/Lower/IntrinsicCall.cpp

Removed: 
    flang/include/flang/Lower/ComplexExpr.h
    flang/lib/Lower/ComplexExpr.cpp


################################################################################
diff  --git a/flang/include/flang/Lower/ComplexExpr.h b/flang/include/flang/Lower/ComplexExpr.h
deleted file mode 100644
index 914d84f5adcfe..0000000000000
--- a/flang/include/flang/Lower/ComplexExpr.h
+++ /dev/null
@@ -1,87 +0,0 @@
-//===-- Lower/ComplexExpr.h -- lowering of complex values -------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef FORTRAN_LOWER_COMPLEXEXPR_H
-#define FORTRAN_LOWER_COMPLEXEXPR_H
-
-#include "flang/Optimizer/Builder/FIRBuilder.h"
-
-namespace Fortran::lower {
-
-/// Helper to facilitate lowering of COMPLEX manipulations in FIR.
-class ComplexExprHelper {
-public:
-  explicit ComplexExprHelper(fir::FirOpBuilder &builder, mlir::Location loc)
-      : builder(builder), loc(loc) {}
-  ComplexExprHelper(const ComplexExprHelper &) = delete;
-
-  // The values of part enum members are meaningful for
-  // InsertValueOp and ExtractValueOp so they are explicit.
-  enum class Part { Real = 0, Imag = 1 };
-
-  /// Type helper. Determine the type. Do not create MLIR operations.
-  mlir::Type getComplexPartType(mlir::Value cplx);
-  mlir::Type getComplexPartType(mlir::Type complexType);
-
-  /// Complex operation creation helper. They create MLIR operations.
-  mlir::Value createComplex(fir::KindTy kind, mlir::Value real,
-                            mlir::Value imag);
-
-  /// Create a complex value.
-  mlir::Value createComplex(mlir::Type complexType, mlir::Value real,
-                            mlir::Value imag);
-
-  mlir::Value extractComplexPart(mlir::Value cplx, bool isImagPart) {
-    return isImagPart ? extract<Part::Imag>(cplx) : extract<Part::Real>(cplx);
-  }
-
-  /// Returns (Real, Imag) pair of \p cplx
-  std::pair<mlir::Value, mlir::Value> extractParts(mlir::Value cplx) {
-    return {extract<Part::Real>(cplx), extract<Part::Imag>(cplx)};
-  }
-
-  mlir::Value insertComplexPart(mlir::Value cplx, mlir::Value part,
-                                bool isImagPart) {
-    return isImagPart ? insert<Part::Imag>(cplx, part)
-                      : insert<Part::Real>(cplx, part);
-  }
-
-  mlir::Value createComplexCompare(mlir::Value cplx1, mlir::Value cplx2,
-                                   bool eq);
-
-protected:
-  template <Part partId>
-  mlir::Value extract(mlir::Value cplx) {
-    return builder.create<fir::ExtractValueOp>(
-        loc, getComplexPartType(cplx), cplx,
-        builder.getArrayAttr({builder.getIntegerAttr(
-            builder.getIndexType(), static_cast<int>(partId))}));
-  }
-
-  template <Part partId>
-  mlir::Value insert(mlir::Value cplx, mlir::Value part) {
-    return builder.create<fir::InsertValueOp>(
-        loc, cplx.getType(), cplx, part,
-        builder.getArrayAttr({builder.getIntegerAttr(
-            builder.getIndexType(), static_cast<int>(partId))}));
-  }
-
-  template <Part partId>
-  mlir::Value createPartId() {
-    return builder.createIntegerConstant(loc, builder.getIndexType(),
-                                         static_cast<int>(partId));
-  }
-
-private:
-  fir::FirOpBuilder &builder;
-  mlir::Location loc;
-};
-
-} // namespace Fortran::lower
-
-#endif // FORTRAN_LOWER_COMPLEXEXPR_H

diff  --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt
index 99ff1d324ed0a..805fc4103b1cf 100644
--- a/flang/lib/Lower/CMakeLists.txt
+++ b/flang/lib/Lower/CMakeLists.txt
@@ -4,7 +4,6 @@ add_flang_library(FortranLower
   CharacterExpr.cpp
   CharacterRuntime.cpp
   Coarray.cpp
-  ComplexExpr.cpp
   ConvertType.cpp
   IntrinsicCall.cpp
   IO.cpp

diff  --git a/flang/lib/Lower/ComplexExpr.cpp b/flang/lib/Lower/ComplexExpr.cpp
deleted file mode 100644
index 67c01ce0d5bdb..0000000000000
--- a/flang/lib/Lower/ComplexExpr.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-//===-- ComplexExpr.cpp ---------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "flang/Lower/ComplexExpr.h"
-#include "flang/Lower/ConvertType.h"
-
-//===----------------------------------------------------------------------===//
-// ComplexExprHelper implementation
-//===----------------------------------------------------------------------===//
-
-mlir::Type
-Fortran::lower::ComplexExprHelper::getComplexPartType(mlir::Type complexType) {
-  return Fortran::lower::convertReal(
-      builder.getContext(), complexType.cast<fir::ComplexType>().getFKind());
-}
-
-mlir::Type
-Fortran::lower::ComplexExprHelper::getComplexPartType(mlir::Value cplx) {
-  return getComplexPartType(cplx.getType());
-}
-
-mlir::Value Fortran::lower::ComplexExprHelper::createComplex(fir::KindTy kind,
-                                                             mlir::Value real,
-                                                             mlir::Value imag) {
-  auto complexTy = fir::ComplexType::get(builder.getContext(), kind);
-  mlir::Value und = builder.create<fir::UndefOp>(loc, complexTy);
-  return insert<Part::Imag>(insert<Part::Real>(und, real), imag);
-}
-
-mlir::Value Fortran::lower::ComplexExprHelper::createComplex(mlir::Type cplxTy,
-                                                             mlir::Value real,
-                                                             mlir::Value imag) {
-  mlir::Value und = builder.create<fir::UndefOp>(loc, cplxTy);
-  return insert<Part::Imag>(insert<Part::Real>(und, real), imag);
-}
-
-mlir::Value Fortran::lower::ComplexExprHelper::createComplexCompare(
-    mlir::Value cplx1, mlir::Value cplx2, bool eq) {
-  auto real1 = extract<Part::Real>(cplx1);
-  auto real2 = extract<Part::Real>(cplx2);
-  auto imag1 = extract<Part::Imag>(cplx1);
-  auto imag2 = extract<Part::Imag>(cplx2);
-
-  mlir::arith::CmpFPredicate predicate =
-      eq ? mlir::arith::CmpFPredicate::UEQ : mlir::arith::CmpFPredicate::UNE;
-  mlir::Value realCmp =
-      builder.create<mlir::arith::CmpFOp>(loc, predicate, real1, real2);
-  mlir::Value imagCmp =
-      builder.create<mlir::arith::CmpFOp>(loc, predicate, imag1, imag2);
-
-  return eq ? builder.create<mlir::arith::AndIOp>(loc, realCmp, imagCmp)
-                  .getResult()
-            : builder.create<mlir::arith::OrIOp>(loc, realCmp, imagCmp)
-                  .getResult();
-}

diff  --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 18c5ff7a73d17..a3cf38f4b19c7 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -10,10 +10,10 @@
 #include "RTBuilder.h"
 #include "flang/Lower/Bridge.h"
 #include "flang/Lower/CharacterExpr.h"
-#include "flang/Lower/ComplexExpr.h"
 #include "flang/Lower/PFTBuilder.h"
 #include "flang/Lower/Runtime.h"
 #include "flang/Lower/Utils.h"
+#include "flang/Optimizer/Builder/Complex.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "flang/Parser/parse-tree.h"
 #include "flang/Runtime/io-api.h"
@@ -246,8 +246,7 @@ genOutputItemList(Fortran::lower::AbstractConverter &converter,
       outputFuncArgs.push_back(builder.createConvert(
           loc, outputFunc.getType().getInput(2), dataLen.second));
     } else if (fir::isa_complex(itemType)) {
-      auto parts = Fortran::lower::ComplexExprHelper{builder, loc}.extractParts(
-          itemValue);
+      auto parts = fir::factory::Complex{builder, loc}.extractParts(itemValue);
       outputFuncArgs.push_back(parts.first);
       outputFuncArgs.push_back(parts.second);
     } else {
@@ -312,8 +311,7 @@ static void genInputItemList(Fortran::lower::AbstractConverter &converter,
     mlir::Type complexPartType;
     if (itemType.isa<fir::ComplexType>())
       complexPartType = builder.getRefType(
-          Fortran::lower::ComplexExprHelper{builder, loc}.getComplexPartType(
-              itemType));
+          fir::factory::Complex{builder, loc}.getComplexPartType(itemType));
     auto complexPartAddr = [&](int index) {
       return builder.create<fir::CoordinateOp>(
           loc, complexPartType, originalItemAddr,

diff  --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp
index 1048ec119aaef..5ff8a63498a8d 100644
--- a/flang/lib/Lower/IntrinsicCall.cpp
+++ b/flang/lib/Lower/IntrinsicCall.cpp
@@ -17,10 +17,10 @@
 #include "RTBuilder.h"
 #include "flang/Common/static-multimap-view.h"
 #include "flang/Lower/CharacterExpr.h"
-#include "flang/Lower/ComplexExpr.h"
 #include "flang/Lower/ConvertType.h"
 #include "flang/Lower/Mangler.h"
 #include "flang/Lower/Runtime.h"
+#include "flang/Optimizer/Builder/Complex.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -959,8 +959,7 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType,
   }
   if (fir::isa_complex(type)) {
     // Use HYPOT to fulfill the no underflow/overflow requirement.
-    auto parts =
-        Fortran::lower::ComplexExprHelper{builder, loc}.extractParts(arg);
+    auto parts = fir::factory::Complex{builder, loc}.extractParts(arg);
     llvm::SmallVector<mlir::Value, 2> args = {parts.first, parts.second};
     return genRuntimeCall("hypot", resultType, args);
   }
@@ -971,7 +970,7 @@ mlir::Value IntrinsicLibrary::genAbs(mlir::Type resultType,
 mlir::Value IntrinsicLibrary::genAimag(mlir::Type resultType,
                                        llvm::ArrayRef<mlir::Value> args) {
   assert(args.size() == 1);
-  return Fortran::lower::ComplexExprHelper{builder, loc}.extractComplexPart(
+  return fir::factory::Complex{builder, loc}.extractComplexPart(
       args[0], true /* isImagPart */);
 }
 
@@ -1014,11 +1013,10 @@ mlir::Value IntrinsicLibrary::genConjg(mlir::Type resultType,
     llvm_unreachable("argument type mismatch");
 
   mlir::Value cplx = args[0];
-  auto imag =
-      Fortran::lower::ComplexExprHelper{builder, loc}.extractComplexPart(
-          cplx, /*isImagPart=*/true);
+  auto imag = fir::factory::Complex{builder, loc}.extractComplexPart(
+      cplx, /*isImagPart=*/true);
   auto negImag = builder.create<mlir::arith::NegFOp>(loc, imag);
-  return Fortran::lower::ComplexExprHelper{builder, loc}.insertComplexPart(
+  return fir::factory::Complex{builder, loc}.insertComplexPart(
       cplx, negImag, /*isImagPart=*/true);
 }
 


        


More information about the flang-commits mailing list