[flang-commits] [flang] [flang][NFC] Move OpenMP related passes into a separate directory (PR #104732)
via flang-commits
flang-commits at lists.llvm.org
Sun Aug 18 20:22:52 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
@llvm/pr-subscribers-flang-driver
Author: Ivan R. Ivanov (ivanradanov)
<details>
<summary>Changes</summary>
Refactoring before introducing a new OpenMP pass in flang: https://github.com/llvm/llvm-project/pull/101446
---
Full diff: https://github.com/llvm/llvm-project/pull/104732.diff
17 Files Affected:
- (modified) flang/include/flang/Optimizer/CMakeLists.txt (+1)
- (added) flang/include/flang/Optimizer/OpenMP/CMakeLists.txt (+4)
- (added) flang/include/flang/Optimizer/OpenMP/Passes.h (+30)
- (added) flang/include/flang/Optimizer/OpenMP/Passes.td (+40)
- (modified) flang/include/flang/Optimizer/Transforms/Passes.td (-26)
- (modified) flang/include/flang/Tools/CLOptions.inc (+4-3)
- (modified) flang/lib/Frontend/CMakeLists.txt (+1)
- (modified) flang/lib/Optimizer/CMakeLists.txt (+1)
- (added) flang/lib/Optimizer/OpenMP/CMakeLists.txt (+25)
- (renamed) flang/lib/Optimizer/OpenMP/OMPFunctionFiltering.cpp (+6-5)
- (renamed) flang/lib/Optimizer/OpenMP/OMPMapInfoFinalization.cpp (+6-7)
- (renamed) flang/lib/Optimizer/OpenMP/OMPMarkDeclareTarget.cpp (+18-5)
- (modified) flang/lib/Optimizer/Transforms/CMakeLists.txt (-3)
- (modified) flang/tools/bbc/CMakeLists.txt (+1)
- (modified) flang/tools/fir-opt/CMakeLists.txt (+1)
- (modified) flang/tools/fir-opt/fir-opt.cpp (+2)
- (modified) flang/tools/tco/CMakeLists.txt (+1)
``````````diff
diff --git a/flang/include/flang/Optimizer/CMakeLists.txt b/flang/include/flang/Optimizer/CMakeLists.txt
index 89e43a9ee8d621..3336ac935e1012 100644
--- a/flang/include/flang/Optimizer/CMakeLists.txt
+++ b/flang/include/flang/Optimizer/CMakeLists.txt
@@ -2,3 +2,4 @@ add_subdirectory(CodeGen)
add_subdirectory(Dialect)
add_subdirectory(HLFIR)
add_subdirectory(Transforms)
+add_subdirectory(OpenMP)
diff --git a/flang/include/flang/Optimizer/OpenMP/CMakeLists.txt b/flang/include/flang/Optimizer/OpenMP/CMakeLists.txt
new file mode 100644
index 00000000000000..d59573f0f7fd91
--- /dev/null
+++ b/flang/include/flang/Optimizer/OpenMP/CMakeLists.txt
@@ -0,0 +1,4 @@
+set(LLVM_TARGET_DEFINITIONS Passes.td)
+mlir_tablegen(Passes.h.inc -gen-pass-decls -name FlangOpenMP)
+
+add_public_tablegen_target(FlangOpenMPPassesIncGen)
diff --git a/flang/include/flang/Optimizer/OpenMP/Passes.h b/flang/include/flang/Optimizer/OpenMP/Passes.h
new file mode 100644
index 00000000000000..403d79667bf448
--- /dev/null
+++ b/flang/include/flang/Optimizer/OpenMP/Passes.h
@@ -0,0 +1,30 @@
+//===- Passes.h - OpenMP pass entry points ----------------------*- 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 header declares the flang OpenMP passes.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef FORTRAN_OPTIMIZER_OPENMP_PASSES_H
+#define FORTRAN_OPTIMIZER_OPENMP_PASSES_H
+
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Pass/PassRegistry.h"
+
+#include <memory>
+
+namespace flangomp {
+#define GEN_PASS_DECL
+#define GEN_PASS_REGISTRATION
+#include "flang/Optimizer/OpenMP/Passes.h.inc"
+
+} // namespace flangomp
+
+#endif // FORTRAN_OPTIMIZER_OPENMP_PASSES_H
diff --git a/flang/include/flang/Optimizer/OpenMP/Passes.td b/flang/include/flang/Optimizer/OpenMP/Passes.td
new file mode 100644
index 00000000000000..7c203efbb5ee13
--- /dev/null
+++ b/flang/include/flang/Optimizer/OpenMP/Passes.td
@@ -0,0 +1,40 @@
+//===-- Passes.td - HLFIR pass definition file -------------*- tablegen -*-===//
+//
+// 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_OPTIMIZER_OPENMP_PASSES
+#define FORTRAN_OPTIMIZER_OPENMP_PASSES
+
+include "mlir/Pass/PassBase.td"
+
+def OMPMapInfoFinalizationPass
+ : Pass<"omp-map-info-finalization"> {
+ let summary = "expands OpenMP MapInfo operations containing descriptors";
+ let description = [{
+ Expands MapInfo operations containing descriptor types into multiple
+ MapInfo's for each pointer element in the descriptor that requires
+ explicit individual mapping by the OpenMP runtime.
+ }];
+ let dependentDialects = ["mlir::omp::OpenMPDialect"];
+}
+
+def OMPMarkDeclareTargetPass
+ : Pass<"omp-mark-declare-target", "mlir::ModuleOp"> {
+ let summary = "Marks all functions called by an OpenMP declare target function as declare target";
+ let dependentDialects = ["mlir::omp::OpenMPDialect"];
+}
+
+def OMPFunctionFiltering : Pass<"omp-function-filtering"> {
+ let summary = "Filters out functions intended for the host when compiling "
+ "for the target device.";
+ let dependentDialects = [
+ "mlir::func::FuncDialect",
+ "fir::FIROpsDialect"
+ ];
+}
+
+#endif //FORTRAN_OPTIMIZER_OPENMP_PASSES
diff --git a/flang/include/flang/Optimizer/Transforms/Passes.td b/flang/include/flang/Optimizer/Transforms/Passes.td
index 786083f95e15c0..3d7a8fc04bb72f 100644
--- a/flang/include/flang/Optimizer/Transforms/Passes.td
+++ b/flang/include/flang/Optimizer/Transforms/Passes.td
@@ -340,32 +340,6 @@ def LoopVersioning : Pass<"loop-versioning", "mlir::func::FuncOp"> {
let dependentDialects = [ "fir::FIROpsDialect" ];
}
-def OMPMapInfoFinalizationPass
- : Pass<"omp-map-info-finalization"> {
- let summary = "expands OpenMP MapInfo operations containing descriptors";
- let description = [{
- Expands MapInfo operations containing descriptor types into multiple
- MapInfo's for each pointer element in the descriptor that requires
- explicit individual mapping by the OpenMP runtime.
- }];
- let dependentDialects = ["mlir::omp::OpenMPDialect"];
-}
-
-def OMPMarkDeclareTargetPass
- : Pass<"omp-mark-declare-target", "mlir::ModuleOp"> {
- let summary = "Marks all functions called by an OpenMP declare target function as declare target";
- let dependentDialects = ["mlir::omp::OpenMPDialect"];
-}
-
-def OMPFunctionFiltering : Pass<"omp-function-filtering"> {
- let summary = "Filters out functions intended for the host when compiling "
- "for the target device.";
- let dependentDialects = [
- "mlir::func::FuncDialect",
- "fir::FIROpsDialect"
- ];
-}
-
def VScaleAttr : Pass<"vscale-attr", "mlir::func::FuncOp"> {
let summary = "Add vscale_range attribute to functions";
let description = [{
diff --git a/flang/include/flang/Tools/CLOptions.inc b/flang/include/flang/Tools/CLOptions.inc
index 7df50449494631..1ad74a98c8d956 100644
--- a/flang/include/flang/Tools/CLOptions.inc
+++ b/flang/include/flang/Tools/CLOptions.inc
@@ -18,6 +18,7 @@
#include "flang/Optimizer/CodeGen/CodeGen.h"
#include "flang/Optimizer/HLFIR/Passes.h"
#include "flang/Optimizer/Transforms/Passes.h"
+#include "flang/Optimizer/OpenMP/Passes.h"
#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Support/CommandLine.h"
#include <type_traits>
@@ -358,10 +359,10 @@ inline void createHLFIRToFIRPassPipeline(
inline void createOpenMPFIRPassPipeline(
mlir::PassManager &pm, bool isTargetDevice) {
addNestedPassToAllTopLevelOperations(
- pm, fir::createOMPMapInfoFinalizationPass);
- pm.addPass(fir::createOMPMarkDeclareTargetPass());
+ pm, flangomp::createOMPMapInfoFinalizationPass);
+ pm.addPass(flangomp::createOMPMarkDeclareTargetPass());
if (isTargetDevice)
- pm.addPass(fir::createOMPFunctionFiltering());
+ pm.addPass(flangomp::createOMPFunctionFiltering());
}
#if !defined(FLANG_EXCLUDE_CODEGEN)
diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt
index c20b9096aff496..ecdcc73d61ec1f 100644
--- a/flang/lib/Frontend/CMakeLists.txt
+++ b/flang/lib/Frontend/CMakeLists.txt
@@ -38,6 +38,7 @@ add_flang_library(flangFrontend
FIRTransforms
HLFIRDialect
HLFIRTransforms
+ FlangOpenMPTransforms
MLIRTransforms
MLIRBuiltinToLLVMIRTranslation
MLIRLLVMToLLVMIRTranslation
diff --git a/flang/lib/Optimizer/CMakeLists.txt b/flang/lib/Optimizer/CMakeLists.txt
index 4a602162ed2b77..dd153ac33c0fbb 100644
--- a/flang/lib/Optimizer/CMakeLists.txt
+++ b/flang/lib/Optimizer/CMakeLists.txt
@@ -5,3 +5,4 @@ add_subdirectory(HLFIR)
add_subdirectory(Support)
add_subdirectory(Transforms)
add_subdirectory(Analysis)
+add_subdirectory(OpenMP)
diff --git a/flang/lib/Optimizer/OpenMP/CMakeLists.txt b/flang/lib/Optimizer/OpenMP/CMakeLists.txt
new file mode 100644
index 00000000000000..c31b490c87f67f
--- /dev/null
+++ b/flang/lib/Optimizer/OpenMP/CMakeLists.txt
@@ -0,0 +1,25 @@
+get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
+
+add_flang_library(FlangOpenMPTransforms
+ OMPFunctionFiltering.cpp
+ OMPMapInfoFinalization.cpp
+ OMPMarkDeclareTarget.cpp
+
+ DEPENDS
+ FIRDialect
+ HLFIROpsIncGen
+ FlangOpenMPPassesIncGen
+
+ LINK_LIBS
+ FIRAnalysis
+ FIRBuilder
+ FIRCodeGen
+ FIRDialect
+ FIRDialectSupport
+ FIRSupport
+ FortranCommon
+ MLIRFuncDialect
+ MLIROpenMPDialect
+ HLFIRDialect
+ MLIRIR
+)
diff --git a/flang/lib/Optimizer/Transforms/OMPFunctionFiltering.cpp b/flang/lib/Optimizer/OpenMP/OMPFunctionFiltering.cpp
similarity index 94%
rename from flang/lib/Optimizer/Transforms/OMPFunctionFiltering.cpp
rename to flang/lib/Optimizer/OpenMP/OMPFunctionFiltering.cpp
index 0c472246c2a44c..2011bd56352ffa 100644
--- a/flang/lib/Optimizer/Transforms/OMPFunctionFiltering.cpp
+++ b/flang/lib/Optimizer/OpenMP/OMPFunctionFiltering.cpp
@@ -13,7 +13,7 @@
#include "flang/Optimizer/Dialect/FIRDialect.h"
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
-#include "flang/Optimizer/Transforms/Passes.h"
+#include "flang/Optimizer/OpenMP/Passes.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
@@ -21,16 +21,17 @@
#include "mlir/IR/BuiltinOps.h"
#include "llvm/ADT/SmallVector.h"
-namespace fir {
+namespace flangomp {
#define GEN_PASS_DEF_OMPFUNCTIONFILTERING
-#include "flang/Optimizer/Transforms/Passes.h.inc"
-} // namespace fir
+#include "flang/Optimizer/OpenMP/Passes.h.inc"
+} // namespace flangomp
using namespace mlir;
namespace {
class OMPFunctionFilteringPass
- : public fir::impl::OMPFunctionFilteringBase<OMPFunctionFilteringPass> {
+ : public flangomp::impl::OMPFunctionFilteringBase<
+ OMPFunctionFilteringPass> {
public:
OMPFunctionFilteringPass() = default;
diff --git a/flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp b/flang/lib/Optimizer/OpenMP/OMPMapInfoFinalization.cpp
similarity index 97%
rename from flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp
rename to flang/lib/Optimizer/OpenMP/OMPMapInfoFinalization.cpp
index ddaa3c5f404f0b..84fd8b28fb6a00 100644
--- a/flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp
+++ b/flang/lib/Optimizer/OpenMP/OMPMapInfoFinalization.cpp
@@ -1,5 +1,4 @@
-//===- OMPMapInfoFinalization.cpp
-//---------------------------------------------------===//
+//===- OMPMapInfoFinalization.cpp -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -28,7 +27,7 @@
#include "flang/Optimizer/Builder/FIRBuilder.h"
#include "flang/Optimizer/Dialect/FIRType.h"
#include "flang/Optimizer/Dialect/Support/KindMapping.h"
-#include "flang/Optimizer/Transforms/Passes.h"
+#include "flang/Optimizer/OpenMP/Passes.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
#include "mlir/IR/BuiltinDialect.h"
@@ -41,14 +40,14 @@
#include "llvm/Frontend/OpenMP/OMPConstants.h"
#include <iterator>
-namespace fir {
+namespace flangomp {
#define GEN_PASS_DEF_OMPMAPINFOFINALIZATIONPASS
-#include "flang/Optimizer/Transforms/Passes.h.inc"
-} // namespace fir
+#include "flang/Optimizer/OpenMP/Passes.h.inc"
+} // namespace flangomp
namespace {
class OMPMapInfoFinalizationPass
- : public fir::impl::OMPMapInfoFinalizationPassBase<
+ : public flangomp::impl::OMPMapInfoFinalizationPassBase<
OMPMapInfoFinalizationPass> {
void genDescriptorMemberMaps(mlir::omp::MapInfoOp op,
diff --git a/flang/lib/Optimizer/Transforms/OMPMarkDeclareTarget.cpp b/flang/lib/Optimizer/OpenMP/OMPMarkDeclareTarget.cpp
similarity index 81%
rename from flang/lib/Optimizer/Transforms/OMPMarkDeclareTarget.cpp
rename to flang/lib/Optimizer/OpenMP/OMPMarkDeclareTarget.cpp
index 4946e13b22865d..b36c2af91bfe33 100644
--- a/flang/lib/Optimizer/Transforms/OMPMarkDeclareTarget.cpp
+++ b/flang/lib/Optimizer/OpenMP/OMPMarkDeclareTarget.cpp
@@ -1,4 +1,16 @@
-#include "flang/Optimizer/Transforms/Passes.h"
+//===- OMPMarkDeclareTarget.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
+//
+//===----------------------------------------------------------------------===//
+//
+// Mark functions called from explicit target code as implicitly declare target.
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Optimizer/OpenMP/Passes.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
@@ -10,14 +22,15 @@
#include "mlir/Support/LLVM.h"
#include "llvm/ADT/SmallPtrSet.h"
-namespace fir {
+namespace flangomp {
#define GEN_PASS_DEF_OMPMARKDECLARETARGETPASS
-#include "flang/Optimizer/Transforms/Passes.h.inc"
-} // namespace fir
+#include "flang/Optimizer/OpenMP/Passes.h.inc"
+} // namespace flangomp
namespace {
class OMPMarkDeclareTargetPass
- : public fir::impl::OMPMarkDeclareTargetPassBase<OMPMarkDeclareTargetPass> {
+ : public flangomp::impl::OMPMarkDeclareTargetPassBase<
+ OMPMarkDeclareTargetPass> {
void markNestedFuncs(mlir::omp::DeclareTargetDeviceType parentDevTy,
mlir::omp::DeclareTargetCaptureClause parentCapClause,
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index 3108304240894c..8b8f174f59f4fd 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -20,9 +20,6 @@ add_flang_library(FIRTransforms
AddDebugInfo.cpp
PolymorphicOpConversion.cpp
LoopVersioning.cpp
- OMPFunctionFiltering.cpp
- OMPMapInfoFinalization.cpp
- OMPMarkDeclareTarget.cpp
StackReclaim.cpp
VScaleAttr.cpp
FunctionAttr.cpp
diff --git a/flang/tools/bbc/CMakeLists.txt b/flang/tools/bbc/CMakeLists.txt
index 9410fd00566006..69316d4dc61de3 100644
--- a/flang/tools/bbc/CMakeLists.txt
+++ b/flang/tools/bbc/CMakeLists.txt
@@ -25,6 +25,7 @@ FIRTransforms
FIRBuilder
HLFIRDialect
HLFIRTransforms
+FlangOpenMPTransforms
${dialect_libs}
${extension_libs}
MLIRAffineToStandard
diff --git a/flang/tools/fir-opt/CMakeLists.txt b/flang/tools/fir-opt/CMakeLists.txt
index 43679a9d535782..4c6dbf7d9c8c37 100644
--- a/flang/tools/fir-opt/CMakeLists.txt
+++ b/flang/tools/fir-opt/CMakeLists.txt
@@ -19,6 +19,7 @@ target_link_libraries(fir-opt PRIVATE
FIRCodeGen
HLFIRDialect
HLFIRTransforms
+ FlangOpenMPTransforms
FIRAnalysis
${test_libs}
${dialect_libs}
diff --git a/flang/tools/fir-opt/fir-opt.cpp b/flang/tools/fir-opt/fir-opt.cpp
index 1846c1b317848f..f75fba27c68f08 100644
--- a/flang/tools/fir-opt/fir-opt.cpp
+++ b/flang/tools/fir-opt/fir-opt.cpp
@@ -14,6 +14,7 @@
#include "mlir/Tools/mlir-opt/MlirOptMain.h"
#include "flang/Optimizer/CodeGen/CodeGen.h"
#include "flang/Optimizer/HLFIR/Passes.h"
+#include "flang/Optimizer/OpenMP/Passes.h"
#include "flang/Optimizer/Support/InitFIR.h"
#include "flang/Optimizer/Transforms/Passes.h"
@@ -34,6 +35,7 @@ int main(int argc, char **argv) {
fir::registerOptCodeGenPasses();
fir::registerOptTransformPasses();
hlfir::registerHLFIRPasses();
+ flangomp::registerFlangOpenMPPasses();
#ifdef FLANG_INCLUDE_TESTS
fir::test::registerTestFIRAliasAnalysisPass();
mlir::registerSideEffectTestPasses();
diff --git a/flang/tools/tco/CMakeLists.txt b/flang/tools/tco/CMakeLists.txt
index 808219ac361f2a..698a398547c773 100644
--- a/flang/tools/tco/CMakeLists.txt
+++ b/flang/tools/tco/CMakeLists.txt
@@ -17,6 +17,7 @@ target_link_libraries(tco PRIVATE
FIRBuilder
HLFIRDialect
HLFIRTransforms
+ FlangOpenMPTransforms
${dialect_libs}
${extension_libs}
MLIRIR
``````````
</details>
https://github.com/llvm/llvm-project/pull/104732
More information about the flang-commits
mailing list