[flang-commits] [flang] [flang][NFC] Refactor to remove .inc file containing shared code (PR #109874)

Tarun Prabhu via flang-commits flang-commits at lists.llvm.org
Wed Sep 25 10:22:58 PDT 2024


================
@@ -0,0 +1,330 @@
+//===-- Pipelines.cpp -- FIR pass pipelines ---------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+/// This file defines some utilties to setup FIR pass pipelines. These are
+/// common to flang and the test tools.
+
+#include "flang/Optimizer/Passes/Pipelines.h"
+
+namespace {
+
+static void addNestedPassToAllTopLevelOperations(mlir::PassManager &pm,
+                                                 PassConstructor ctor) {
+  addNestedPassToOps<mlir::func::FuncOp, mlir::omp::DeclareReductionOp,
+                     mlir::omp::PrivateClauseOp, fir::GlobalOp>(pm, ctor);
+}
+
+static void
+addNestedPassToAllTopLevelOperationsConditionally(mlir::PassManager &pm,
+                                                  llvm::cl::opt<bool> &disabled,
+                                                  PassConstructor ctor) {
+  if (!disabled)
+    addNestedPassToAllTopLevelOperations(pm, ctor);
+}
+
+} // namespace
+
+namespace fir {
+
+// Add MLIR Canonicalizer pass with region simplification disabled.
+// FIR does not support the promotion of some SSA value to block arguments (or
+// into arith.select operands) that may be done by mlir block merging in the
+// region simplification (e.g., !fir.shape<> SSA values are not supported as
+// block arguments).
+// Aside from the fir.shape issue, moving some abstract SSA value into block
+// arguments may have a heavy cost since it forces their code generation that
+// may be expensive (array temporary). The MLIR pass does not take these
+// extra costs into account when doing block merging.
+static void
+addCanonicalizerPassWithoutRegionSimplification(mlir::OpPassManager &pm) {
+  mlir::GreedyRewriteConfig config;
+  config.enableRegionSimplification = mlir::GreedySimplifyRegionLevel::Disabled;
+  pm.addPass(mlir::createCanonicalizerPass(config));
+}
+
+static void addCfgConversionPass(mlir::PassManager &pm,
----------------
tarunprabhu wrote:

Done. I moved everything from the anonymous namespace to the FIR namespace. For the non-templated functions, I leaving them in an anonymous namespace resulted in "unused function" warnings. My understand is that the use of functions in that way could result in ODR violations, so I moved everything, including the templated functions, into the FIR namespace.

https://github.com/llvm/llvm-project/pull/109874


More information about the flang-commits mailing list