diff --git a/flang/docs/OpenMP-declare-target.md b/flang/docs/OpenMP-declare-target.md index 45062469007b65..d29a46807e1eaf 100644 --- a/flang/docs/OpenMP-declare-target.md +++ b/flang/docs/OpenMP-declare-target.md @@ -149,7 +149,7 @@ flang/lib/Lower/OpenMP.cpp function `genDeclareTargetIntGlobal`. There are currently two passes within Flang that are related to the processing of `declare target`: -* `MarkDeclareTarget` - This pass is in charge of marking functions captured +* `OMPMarkDeclareTarget` - This pass is in charge of marking functions captured (called from) in `target` regions or other `declare target` marked functions as `declare target`. It does so recursively, i.e. nested calls will also be implicitly marked. It currently will try to mark things as conservatively as @@ -157,7 +157,7 @@ possible, e.g. if captured in a `target` region it will apply `nohost`, unless it encounters a `host` `declare target` in which case it will apply the `any` device type. Functions are handled similarly, except we utilise the parent's device type where possible. -* `FunctionFiltering` - This is executed after the `MarkDeclareTarget` +* `OMPFunctionFiltering` - This is executed after the `OMPMarkDeclareTarget` pass, and its job is to conservatively remove host functions from the module where possible when compiling for the device. This helps make sure that most incompatible code for the host is not lowered for the diff --git a/flang/docs/OpenMP-descriptor-management.md b/flang/docs/OpenMP-descriptor-management.md index 66c153914f70da..d0eb01b00f9bb9 100644 --- a/flang/docs/OpenMP-descriptor-management.md +++ b/flang/docs/OpenMP-descriptor-management.md @@ -44,7 +44,7 @@ Currently, Flang will lower these descriptor types in the OpenMP lowering (lower to all other map types, generating an omp.MapInfoOp containing relevant information required for lowering the OpenMP dialect to LLVM-IR during the final stages of the MLIR lowering. However, after the lowering to FIR/HLFIR has been performed an OpenMP dialect specific pass for Fortran, -`MapInfoFinalizationPass` (Optimizer/OpenMP/MapInfoFinalization.cpp) will expand the +`OMPMapInfoFinalizationPass` (Optimizer/OMPMapInfoFinalization.cpp) will expand the `omp.MapInfoOp`'s containing descriptors (which currently will be a `BoxType` or `BoxAddrOp`) into multiple mappings, with one extra per pointer member in the descriptor that is supported on top of the original descriptor map operation. These pointers members are linked to the parent descriptor by adding them to @@ -53,7 +53,7 @@ owning operation's (`omp.TargetOp`, `omp.TargetDataOp` etc.) map operand list an operation is `IsolatedFromAbove`, it also inserts them as `BlockArgs` to canonicalize the mappings and simplify lowering. -An example transformation by the `MapInfoFinalizationPass`: +An example transformation by the `OMPMapInfoFinalizationPass`: ``` diff --git a/flang/include/flang/Optimizer/CMakeLists.txt b/flang/include/flang/Optimizer/CMakeLists.txt index 3336ac935e1012..89e43a9ee8d621 100644 --- a/flang/include/flang/Optimizer/CMakeLists.txt +++ b/flang/include/flang/Optimizer/CMakeLists.txt @@ -2,4 +2,3 @@ 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 deleted file mode 100644 index d59573f0f7fd91..00000000000000 --- a/flang/include/flang/Optimizer/OpenMP/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -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 deleted file mode 100644 index 403d79667bf448..00000000000000 --- a/flang/include/flang/Optimizer/OpenMP/Passes.h +++ /dev/null @@ -1,30 +0,0 @@ -//===- 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 - -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 deleted file mode 100644 index 395178e26a5762..00000000000000 --- a/flang/include/flang/Optimizer/OpenMP/Passes.td +++ /dev/null @@ -1,40 +0,0 @@ -//===-- Passes.td - flang OpenMP pass definition -----------*- 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 MapInfoFinalizationPass - : 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 MarkDeclareTargetPass - : 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 FunctionFiltering : 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 53a1b55450972e..c703a62c03b7d9 100644 --- a/flang/include/flang/Optimizer/Transforms/Passes.td +++ b/flang/include/flang/Optimizer/Transforms/Passes.td @@ -340,6 +340,32 @@ 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 05b2f31711add2..7df50449494631 100644 --- a/flang/include/flang/Tools/CLOptions.inc +++ b/flang/include/flang/Tools/CLOptions.inc @@ -17,7 +17,6 @@ #include "mlir/Transforms/Passes.h" #include "flang/Optimizer/CodeGen/CodeGen.h" #include "flang/Optimizer/HLFIR/Passes.h" -#include "flang/Optimizer/OpenMP/Passes.h" #include "flang/Optimizer/Transforms/Passes.h" #include "llvm/Passes/OptimizationLevel.h" #include "llvm/Support/CommandLine.h" @@ -359,10 +358,10 @@ inline void createHLFIRToFIRPassPipeline( inline void createOpenMPFIRPassPipeline( mlir::PassManager &pm, bool isTargetDevice) { addNestedPassToAllTopLevelOperations( - pm, flangomp::createMapInfoFinalizationPass); - pm.addPass(flangomp::createMarkDeclareTargetPass()); + pm, fir::createOMPMapInfoFinalizationPass); + pm.addPass(fir::createOMPMarkDeclareTargetPass()); if (isTargetDevice) - pm.addPass(flangomp::createFunctionFiltering()); + pm.addPass(fir::createOMPFunctionFiltering()); } #if !defined(FLANG_EXCLUDE_CODEGEN) diff --git a/flang/lib/Frontend/CMakeLists.txt b/flang/lib/Frontend/CMakeLists.txt index ecdcc73d61ec1f..c20b9096aff496 100644 --- a/flang/lib/Frontend/CMakeLists.txt +++ b/flang/lib/Frontend/CMakeLists.txt @@ -38,7 +38,6 @@ 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 dd153ac33c0fbb..4a602162ed2b77 100644 --- a/flang/lib/Optimizer/CMakeLists.txt +++ b/flang/lib/Optimizer/CMakeLists.txt @@ -5,4 +5,3 @@ 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 deleted file mode 100644 index a8984d256b8f6a..00000000000000 --- a/flang/lib/Optimizer/OpenMP/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) - -add_flang_library(FlangOpenMPTransforms - FunctionFiltering.cpp - MapInfoFinalization.cpp - MarkDeclareTarget.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/CMakeLists.txt b/flang/lib/Optimizer/Transforms/CMakeLists.txt index a6fc8e999d44da..3869633bd98e02 100644 --- a/flang/lib/Optimizer/Transforms/CMakeLists.txt +++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt @@ -21,6 +21,9 @@ 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/lib/Optimizer/OpenMP/FunctionFiltering.cpp b/flang/lib/Optimizer/Transforms/OMPFunctionFiltering.cpp similarity index 90% rename from flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp rename to flang/lib/Optimizer/Transforms/OMPFunctionFiltering.cpp index bd9005d3e2df6f..0c472246c2a44c 100644 --- a/flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp +++ b/flang/lib/Optimizer/Transforms/OMPFunctionFiltering.cpp @@ -1,4 +1,4 @@ -//===- FunctionFiltering.cpp -------------------------------------------===// +//===- OMPFunctionFiltering.cpp -------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -13,7 +13,7 @@ #include "flang/Optimizer/Dialect/FIRDialect.h" #include "flang/Optimizer/Dialect/FIROpsSupport.h" -#include "flang/Optimizer/OpenMP/Passes.h" +#include "flang/Optimizer/Transforms/Passes.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" @@ -21,18 +21,18 @@ #include "mlir/IR/BuiltinOps.h" #include "llvm/ADT/SmallVector.h" -namespace flangomp { -#define GEN_PASS_DEF_FUNCTIONFILTERING -#include "flang/Optimizer/OpenMP/Passes.h.inc" -} // namespace flangomp +namespace fir { +#define GEN_PASS_DEF_OMPFUNCTIONFILTERING +#include "flang/Optimizer/Transforms/Passes.h.inc" +} // namespace fir using namespace mlir; namespace { -class FunctionFilteringPass - : public flangomp::impl::FunctionFilteringBase { +class OMPFunctionFilteringPass + : public fir::impl::OMPFunctionFilteringBase { public: - FunctionFilteringPass() = default; + OMPFunctionFilteringPass() = default; void runOnOperation() override { MLIRContext *context = &getContext(); diff --git a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp b/flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp similarity index 96% rename from flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp rename to flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp index 6e9cd03dca8f3f..ddaa3c5f404f0b 100644 --- a/flang/lib/Optimizer/OpenMP/MapInfoFinalization.cpp +++ b/flang/lib/Optimizer/Transforms/OMPMapInfoFinalization.cpp @@ -1,4 +1,5 @@ -//===- MapInfoFinalization.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. @@ -27,7 +28,7 @@ #include "flang/Optimizer/Builder/FIRBuilder.h" #include "flang/Optimizer/Dialect/FIRType.h" #include "flang/Optimizer/Dialect/Support/KindMapping.h" -#include "flang/Optimizer/OpenMP/Passes.h" +#include "flang/Optimizer/Transforms/Passes.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" #include "mlir/IR/BuiltinDialect.h" @@ -40,15 +41,15 @@ #include "llvm/Frontend/OpenMP/OMPConstants.h" #include -namespace flangomp { -#define GEN_PASS_DEF_MAPINFOFINALIZATIONPASS -#include "flang/Optimizer/OpenMP/Passes.h.inc" -} // namespace flangomp +namespace fir { +#define GEN_PASS_DEF_OMPMAPINFOFINALIZATIONPASS +#include "flang/Optimizer/Transforms/Passes.h.inc" +} // namespace fir namespace { -class MapInfoFinalizationPass - : public flangomp::impl::MapInfoFinalizationPassBase< - MapInfoFinalizationPass> { +class OMPMapInfoFinalizationPass + : public fir::impl::OMPMapInfoFinalizationPassBase< + OMPMapInfoFinalizationPass> { void genDescriptorMemberMaps(mlir::omp::MapInfoOp op, fir::FirOpBuilder &builder, @@ -244,7 +245,7 @@ class MapInfoFinalizationPass // all users appropriately, making sure to only add a single member link // per new generation for the original originating descriptor MapInfoOp. assert(llvm::hasSingleElement(op->getUsers()) && - "MapInfoFinalization currently only supports single users " + "OMPMapInfoFinalization currently only supports single users " "of a MapInfoOp"); if (!op.getMembers().empty()) { diff --git a/flang/lib/Optimizer/OpenMP/MarkDeclareTarget.cpp b/flang/lib/Optimizer/Transforms/OMPMarkDeclareTarget.cpp similarity index 80% rename from flang/lib/Optimizer/OpenMP/MarkDeclareTarget.cpp rename to flang/lib/Optimizer/Transforms/OMPMarkDeclareTarget.cpp index a7ffd5fda82b7f..4946e13b22865d 100644 --- a/flang/lib/Optimizer/OpenMP/MarkDeclareTarget.cpp +++ b/flang/lib/Optimizer/Transforms/OMPMarkDeclareTarget.cpp @@ -1,16 +1,4 @@ -//===- MarkDeclareTarget.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 "flang/Optimizer/Transforms/Passes.h" #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/OpenMP/OpenMPDialect.h" @@ -22,14 +10,14 @@ #include "mlir/Support/LLVM.h" #include "llvm/ADT/SmallPtrSet.h" -namespace flangomp { -#define GEN_PASS_DEF_MARKDECLARETARGETPASS -#include "flang/Optimizer/OpenMP/Passes.h.inc" -} // namespace flangomp +namespace fir { +#define GEN_PASS_DEF_OMPMARKDECLARETARGETPASS +#include "flang/Optimizer/Transforms/Passes.h.inc" +} // namespace fir namespace { -class MarkDeclareTargetPass - : public flangomp::impl::MarkDeclareTargetPassBase { +class OMPMarkDeclareTargetPass + : public fir::impl::OMPMarkDeclareTargetPassBase { void markNestedFuncs(mlir::omp::DeclareTargetDeviceType parentDevTy, mlir::omp::DeclareTargetCaptureClause parentCapClause, diff --git a/flang/tools/bbc/CMakeLists.txt b/flang/tools/bbc/CMakeLists.txt index 69316d4dc61de3..9410fd00566006 100644 --- a/flang/tools/bbc/CMakeLists.txt +++ b/flang/tools/bbc/CMakeLists.txt @@ -25,7 +25,6 @@ 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 4c6dbf7d9c8c37..43679a9d535782 100644 --- a/flang/tools/fir-opt/CMakeLists.txt +++ b/flang/tools/fir-opt/CMakeLists.txt @@ -19,7 +19,6 @@ 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 f75fba27c68f08..1846c1b317848f 100644 --- a/flang/tools/fir-opt/fir-opt.cpp +++ b/flang/tools/fir-opt/fir-opt.cpp @@ -14,7 +14,6 @@ #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" @@ -35,7 +34,6 @@ 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 698a398547c773..808219ac361f2a 100644 --- a/flang/tools/tco/CMakeLists.txt +++ b/flang/tools/tco/CMakeLists.txt @@ -17,7 +17,6 @@ target_link_libraries(tco PRIVATE FIRBuilder HLFIRDialect HLFIRTransforms - FlangOpenMPTransforms ${dialect_libs} ${extension_libs} MLIRIR