Skip to content

Commit 301e107

Browse files
ivanradanovcjdb
authored andcommitted
[flang][NFC] Move OpenMP related passes into a separate directory (llvm#104732)
Reapplied with fixed library dependencies for shared lib build
1 parent fe6c1c0 commit 301e107

File tree

19 files changed

+154
-63
lines changed

19 files changed

+154
-63
lines changed

flang/docs/OpenMP-declare-target.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ flang/lib/Lower/OpenMP.cpp function `genDeclareTargetIntGlobal`.
149149

150150
There are currently two passes within Flang that are related to the processing
151151
of `declare target`:
152-
* `OMPMarkDeclareTarget` - This pass is in charge of marking functions captured
152+
* `MarkDeclareTarget` - This pass is in charge of marking functions captured
153153
(called from) in `target` regions or other `declare target` marked functions as
154154
`declare target`. It does so recursively, i.e. nested calls will also be
155155
implicitly marked. It currently will try to mark things as conservatively as
156156
possible, e.g. if captured in a `target` region it will apply `nohost`, unless
157157
it encounters a `host` `declare target` in which case it will apply the `any`
158158
device type. Functions are handled similarly, except we utilise the parent's
159159
device type where possible.
160-
* `OMPFunctionFiltering` - This is executed after the `OMPMarkDeclareTarget`
160+
* `FunctionFiltering` - This is executed after the `MarkDeclareTarget`
161161
pass, and its job is to conservatively remove host functions from
162162
the module where possible when compiling for the device. This helps make
163163
sure that most incompatible code for the host is not lowered for the

flang/docs/OpenMP-descriptor-management.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Currently, Flang will lower these descriptor types in the OpenMP lowering (lower
4444
to all other map types, generating an omp.MapInfoOp containing relevant information required for lowering
4545
the OpenMP dialect to LLVM-IR during the final stages of the MLIR lowering. However, after
4646
the lowering to FIR/HLFIR has been performed an OpenMP dialect specific pass for Fortran,
47-
`OMPMapInfoFinalizationPass` (Optimizer/OMPMapInfoFinalization.cpp) will expand the
47+
`MapInfoFinalizationPass` (Optimizer/OpenMP/MapInfoFinalization.cpp) will expand the
4848
`omp.MapInfoOp`'s containing descriptors (which currently will be a `BoxType` or `BoxAddrOp`) into multiple
4949
mappings, with one extra per pointer member in the descriptor that is supported on top of the original
5050
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
5353
operation is `IsolatedFromAbove`, it also inserts them as `BlockArgs` to canonicalize the mappings and
5454
simplify lowering.
5555
56-
An example transformation by the `OMPMapInfoFinalizationPass`:
56+
An example transformation by the `MapInfoFinalizationPass`:
5757
5858
```
5959

flang/include/flang/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ add_subdirectory(CodeGen)
22
add_subdirectory(Dialect)
33
add_subdirectory(HLFIR)
44
add_subdirectory(Transforms)
5+
add_subdirectory(OpenMP)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(LLVM_TARGET_DEFINITIONS Passes.td)
2+
mlir_tablegen(Passes.h.inc -gen-pass-decls -name FlangOpenMP)
3+
4+
add_public_tablegen_target(FlangOpenMPPassesIncGen)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===- Passes.h - OpenMP pass entry points ----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This header declares the flang OpenMP passes.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef FORTRAN_OPTIMIZER_OPENMP_PASSES_H
14+
#define FORTRAN_OPTIMIZER_OPENMP_PASSES_H
15+
16+
#include "mlir/Dialect/Func/IR/FuncOps.h"
17+
#include "mlir/IR/BuiltinOps.h"
18+
#include "mlir/Pass/Pass.h"
19+
#include "mlir/Pass/PassRegistry.h"
20+
21+
#include <memory>
22+
23+
namespace flangomp {
24+
#define GEN_PASS_DECL
25+
#define GEN_PASS_REGISTRATION
26+
#include "flang/Optimizer/OpenMP/Passes.h.inc"
27+
28+
} // namespace flangomp
29+
30+
#endif // FORTRAN_OPTIMIZER_OPENMP_PASSES_H
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//===-- Passes.td - flang OpenMP pass definition -----------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_OPTIMIZER_OPENMP_PASSES
10+
#define FORTRAN_OPTIMIZER_OPENMP_PASSES
11+
12+
include "mlir/Pass/PassBase.td"
13+
14+
def MapInfoFinalizationPass
15+
: Pass<"omp-map-info-finalization"> {
16+
let summary = "expands OpenMP MapInfo operations containing descriptors";
17+
let description = [{
18+
Expands MapInfo operations containing descriptor types into multiple
19+
MapInfo's for each pointer element in the descriptor that requires
20+
explicit individual mapping by the OpenMP runtime.
21+
}];
22+
let dependentDialects = ["mlir::omp::OpenMPDialect"];
23+
}
24+
25+
def MarkDeclareTargetPass
26+
: Pass<"omp-mark-declare-target", "mlir::ModuleOp"> {
27+
let summary = "Marks all functions called by an OpenMP declare target function as declare target";
28+
let dependentDialects = ["mlir::omp::OpenMPDialect"];
29+
}
30+
31+
def FunctionFiltering : Pass<"omp-function-filtering"> {
32+
let summary = "Filters out functions intended for the host when compiling "
33+
"for the target device.";
34+
let dependentDialects = [
35+
"mlir::func::FuncDialect",
36+
"fir::FIROpsDialect"
37+
];
38+
}
39+
40+
#endif //FORTRAN_OPTIMIZER_OPENMP_PASSES

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -358,32 +358,6 @@ def LoopVersioning : Pass<"loop-versioning", "mlir::func::FuncOp"> {
358358
let dependentDialects = [ "fir::FIROpsDialect" ];
359359
}
360360

361-
def OMPMapInfoFinalizationPass
362-
: Pass<"omp-map-info-finalization"> {
363-
let summary = "expands OpenMP MapInfo operations containing descriptors";
364-
let description = [{
365-
Expands MapInfo operations containing descriptor types into multiple
366-
MapInfo's for each pointer element in the descriptor that requires
367-
explicit individual mapping by the OpenMP runtime.
368-
}];
369-
let dependentDialects = ["mlir::omp::OpenMPDialect"];
370-
}
371-
372-
def OMPMarkDeclareTargetPass
373-
: Pass<"omp-mark-declare-target", "mlir::ModuleOp"> {
374-
let summary = "Marks all functions called by an OpenMP declare target function as declare target";
375-
let dependentDialects = ["mlir::omp::OpenMPDialect"];
376-
}
377-
378-
def OMPFunctionFiltering : Pass<"omp-function-filtering"> {
379-
let summary = "Filters out functions intended for the host when compiling "
380-
"for the target device.";
381-
let dependentDialects = [
382-
"mlir::func::FuncDialect",
383-
"fir::FIROpsDialect"
384-
];
385-
}
386-
387361
def VScaleAttr : Pass<"vscale-attr", "mlir::func::FuncOp"> {
388362
let summary = "Add vscale_range attribute to functions";
389363
let description = [{

flang/include/flang/Tools/CLOptions.inc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "mlir/Transforms/Passes.h"
1818
#include "flang/Optimizer/CodeGen/CodeGen.h"
1919
#include "flang/Optimizer/HLFIR/Passes.h"
20+
#include "flang/Optimizer/OpenMP/Passes.h"
2021
#include "flang/Optimizer/Transforms/Passes.h"
2122
#include "llvm/Passes/OptimizationLevel.h"
2223
#include "llvm/Support/CommandLine.h"
@@ -367,10 +368,10 @@ inline void createHLFIRToFIRPassPipeline(
367368
inline void createOpenMPFIRPassPipeline(
368369
mlir::PassManager &pm, bool isTargetDevice) {
369370
addNestedPassToAllTopLevelOperations(
370-
pm, fir::createOMPMapInfoFinalizationPass);
371-
pm.addPass(fir::createOMPMarkDeclareTargetPass());
371+
pm, flangomp::createMapInfoFinalizationPass);
372+
pm.addPass(flangomp::createMarkDeclareTargetPass());
372373
if (isTargetDevice)
373-
pm.addPass(fir::createOMPFunctionFiltering());
374+
pm.addPass(flangomp::createFunctionFiltering());
374375
}
375376

376377
#if !defined(FLANG_EXCLUDE_CODEGEN)

flang/lib/Frontend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_flang_library(flangFrontend
3838
FIRTransforms
3939
HLFIRDialect
4040
HLFIRTransforms
41+
FlangOpenMPTransforms
4142
MLIRTransforms
4243
MLIRBuiltinToLLVMIRTranslation
4344
MLIRLLVMToLLVMIRTranslation

flang/lib/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ add_subdirectory(HLFIR)
55
add_subdirectory(Support)
66
add_subdirectory(Transforms)
77
add_subdirectory(Analysis)
8+
add_subdirectory(OpenMP)

0 commit comments

Comments
 (0)