[flang-commits] [flang] 47a66f1 - [flang][NFC] Remove obsolete DoLoopHelper

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


Author: Valentin Clement
Date: 2022-01-28T11:30:11+01:00
New Revision: 47a66f1c5ad5a27f38b667a7d9849eb11c07bbff

URL: https://github.com/llvm/llvm-project/commit/47a66f1c5ad5a27f38b667a7d9849eb11c07bbff
DIFF: https://github.com/llvm/llvm-project/commit/47a66f1c5ad5a27f38b667a7d9849eb11c07bbff.diff

LOG: [flang][NFC] Remove obsolete DoLoopHelper

During the upstreaming process from fir-dev some
new builder have been introduced in the `flang/Optimizer/Builder`
directory. This patch removes the obsolete DoLoopHelper still present
in the lowering directories and makes use of the new one where needed.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan

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

Added: 
    

Modified: 
    flang/lib/Lower/CMakeLists.txt
    flang/lib/Lower/CharacterExpr.cpp

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


################################################################################
diff  --git a/flang/include/flang/Lower/DoLoopHelper.h b/flang/include/flang/Lower/DoLoopHelper.h
deleted file mode 100644
index d62e7ae86d161..0000000000000
--- a/flang/include/flang/Lower/DoLoopHelper.h
+++ /dev/null
@@ -1,45 +0,0 @@
-//===-- Lower/DoLoopHelper.h -- gen fir.do_loop ops -------------*- 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_DOLOOPHELPER_H
-#define FORTRAN_LOWER_DOLOOPHELPER_H
-
-#include "flang/Optimizer/Builder/FIRBuilder.h"
-
-namespace Fortran::lower {
-
-/// Helper to build fir.do_loop Ops.
-class DoLoopHelper {
-public:
-  explicit DoLoopHelper(fir::FirOpBuilder &builder, mlir::Location loc)
-      : builder(builder), loc(loc) {}
-  DoLoopHelper(const DoLoopHelper &) = delete;
-
-  /// Type of a callback to generate the loop body.
-  using BodyGenerator = std::function<void(fir::FirOpBuilder &, mlir::Value)>;
-
-  /// Build loop [\p lb, \p ub] with step \p step.
-  /// If \p step is an empty value, 1 is used for the step.
-  void createLoop(mlir::Value lb, mlir::Value ub, mlir::Value step,
-                  const BodyGenerator &bodyGenerator);
-
-  /// Build loop [\p lb,  \p ub] with step 1.
-  void createLoop(mlir::Value lb, mlir::Value ub,
-                  const BodyGenerator &bodyGenerator);
-
-  /// Build loop [0, \p count) with step 1.
-  void createLoop(mlir::Value count, const BodyGenerator &bodyGenerator);
-
-private:
-  fir::FirOpBuilder &builder;
-  mlir::Location loc;
-};
-
-} // namespace Fortran::lower
-
-#endif // FORTRAN_LOWER_DOLOOPHELPER_H

diff  --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt
index 2e7c35481b542..3beafc8d34a42 100644
--- a/flang/lib/Lower/CMakeLists.txt
+++ b/flang/lib/Lower/CMakeLists.txt
@@ -6,7 +6,6 @@ add_flang_library(FortranLower
   Coarray.cpp
   ComplexExpr.cpp
   ConvertType.cpp
-  DoLoopHelper.cpp
   IntrinsicCall.cpp
   IO.cpp
   Mangler.cpp

diff  --git a/flang/lib/Lower/CharacterExpr.cpp b/flang/lib/Lower/CharacterExpr.cpp
index ce7c9342f08c2..e4cd9f0ced1ad 100644
--- a/flang/lib/Lower/CharacterExpr.cpp
+++ b/flang/lib/Lower/CharacterExpr.cpp
@@ -8,8 +8,8 @@
 
 #include "flang/Lower/CharacterExpr.h"
 #include "flang/Lower/ConvertType.h"
-#include "flang/Lower/DoLoopHelper.h"
 #include "flang/Lower/IntrinsicCall.h"
+#include "flang/Optimizer/Builder/DoLoopHelper.h"
 
 //===----------------------------------------------------------------------===//
 // CharacterExprHelper implementation
@@ -179,7 +179,7 @@ void Fortran::lower::CharacterExprHelper::createStoreCharAt(
 void Fortran::lower::CharacterExprHelper::createCopy(
     const fir::CharBoxValue &dest, const fir::CharBoxValue &src,
     mlir::Value count) {
-  Fortran::lower::DoLoopHelper{builder, loc}.createLoop(
+  fir::factory::DoLoopHelper{builder, loc}.createLoop(
       count, [&](fir::FirOpBuilder &, mlir::Value index) {
         auto charVal = createLoadCharAt(src, index);
         createStoreCharAt(dest, index, charVal);
@@ -191,7 +191,7 @@ void Fortran::lower::CharacterExprHelper::createPadding(
   auto blank = createBlankConstant(getCharacterType(str));
   // Always create the loop, if upper < lower, no iteration will be
   // executed.
-  Fortran::lower::DoLoopHelper{builder, loc}.createLoop(
+  fir::factory::DoLoopHelper{builder, loc}.createLoop(
       lower, upper, [&](fir::FirOpBuilder &, mlir::Value index) {
         createStoreCharAt(str, index, blank);
       });
@@ -286,7 +286,7 @@ fir::CharBoxValue Fortran::lower::CharacterExprHelper::createConcatenate(
   auto upperBound = builder.create<mlir::arith::SubIOp>(loc, len, one);
   auto lhsLen =
       builder.createConvert(loc, builder.getIndexType(), lhs.getLen());
-  Fortran::lower::DoLoopHelper{builder, loc}.createLoop(
+  fir::factory::DoLoopHelper{builder, loc}.createLoop(
       lhs.getLen(), upperBound, one,
       [&](fir::FirOpBuilder &bldr, mlir::Value index) {
         auto rhsIndex = bldr.create<mlir::arith::SubIOp>(loc, index, lhsLen);

diff  --git a/flang/lib/Lower/DoLoopHelper.cpp b/flang/lib/Lower/DoLoopHelper.cpp
deleted file mode 100644
index 7af3665fa1dc3..0000000000000
--- a/flang/lib/Lower/DoLoopHelper.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-//===-- DoLoopHelper.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/DoLoopHelper.h"
-
-//===----------------------------------------------------------------------===//
-// DoLoopHelper implementation
-//===----------------------------------------------------------------------===//
-
-void Fortran::lower::DoLoopHelper::createLoop(
-    mlir::Value lb, mlir::Value ub, mlir::Value step,
-    const BodyGenerator &bodyGenerator) {
-  auto lbi = builder.convertToIndexType(loc, lb);
-  auto ubi = builder.convertToIndexType(loc, ub);
-  assert(step && "step must be an actual Value");
-  auto inc = builder.convertToIndexType(loc, step);
-  auto loop = builder.create<fir::DoLoopOp>(loc, lbi, ubi, inc);
-  auto insertPt = builder.saveInsertionPoint();
-  builder.setInsertionPointToStart(loop.getBody());
-  auto index = loop.getInductionVar();
-  bodyGenerator(builder, index);
-  builder.restoreInsertionPoint(insertPt);
-}
-
-void Fortran::lower::DoLoopHelper::createLoop(
-    mlir::Value lb, mlir::Value ub, const BodyGenerator &bodyGenerator) {
-  createLoop(lb, ub,
-             builder.createIntegerConstant(loc, builder.getIndexType(), 1),
-             bodyGenerator);
-}
-
-void Fortran::lower::DoLoopHelper::createLoop(
-    mlir::Value count, const BodyGenerator &bodyGenerator) {
-  auto indexType = builder.getIndexType();
-  auto zero = builder.createIntegerConstant(loc, indexType, 0);
-  auto one = builder.createIntegerConstant(loc, count.getType(), 1);
-  auto up = builder.create<mlir::arith::SubIOp>(loc, count, one);
-  createLoop(zero, up, one, bodyGenerator);
-}


        


More information about the flang-commits mailing list