Skip to content

Commit 26d0051

Browse files
committed
[flang] Lower omp.workshare to other omp constructs
1 parent 4da93bb commit 26d0051

File tree

16 files changed

+490
-2
lines changed

16 files changed

+490
-2
lines changed

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 OpenMP pass entry points.
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/Pass/Pass.h"
18+
#include "mlir/Pass/PassRegistry.h"
19+
#include <memory>
20+
21+
namespace flangomp {
22+
#define GEN_PASS_DECL
23+
#define GEN_PASS_REGISTRATION
24+
#include "flang/Optimizer/OpenMP/Passes.h.inc"
25+
26+
bool shouldUseWorkshareLowering(mlir::Operation *op);
27+
28+
} // namespace flangomp
29+
30+
#endif // FORTRAN_OPTIMIZER_OPENMP_PASSES_H
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- Passes.td - HLFIR pass definition file -------------*- 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_DIALECT_OPENMP_PASSES
10+
#define FORTRAN_DIALECT_OPENMP_PASSES
11+
12+
include "mlir/Pass/PassBase.td"
13+
14+
def LowerWorkshare : Pass<"lower-workshare"> {
15+
let summary = "Lower workshare construct";
16+
}
17+
18+
#endif //FORTRAN_DIALECT_OPENMP_PASSES

flang/include/flang/Tools/CLOptions.inc

Lines changed: 2 additions & 0 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"
@@ -344,6 +345,7 @@ inline void createHLFIRToFIRPassPipeline(
344345
pm.addPass(hlfir::createLowerHLFIRIntrinsics());
345346
pm.addPass(hlfir::createBufferizeHLFIR());
346347
pm.addPass(hlfir::createConvertHLFIRtoFIR());
348+
pm.addPass(flangomp::createLowerWorkshare());
347349
}
348350

349351
/// Create a pass pipeline for handling certain OpenMP transformations needed

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)

flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
#include "flang/Optimizer/HLFIR/HLFIRDialect.h"
2727
#include "flang/Optimizer/HLFIR/HLFIROps.h"
2828
#include "flang/Optimizer/HLFIR/Passes.h"
29+
#include "flang/Optimizer/OpenMP/Passes.h"
30+
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
2931
#include "mlir/IR/Dominance.h"
3032
#include "mlir/IR/PatternMatch.h"
3133
#include "mlir/Pass/Pass.h"
3234
#include "mlir/Pass/PassManager.h"
3335
#include "mlir/Transforms/DialectConversion.h"
34-
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
3536
#include "llvm/ADT/TypeSwitch.h"
3637

3738
namespace hlfir {
@@ -792,7 +793,8 @@ struct ElementalOpConversion
792793
// Generate a loop nest looping around the fir.elemental shape and clone
793794
// fir.elemental region inside the inner loop.
794795
hlfir::LoopNest loopNest =
795-
hlfir::genLoopNest(loc, builder, extents, !elemental.isOrdered());
796+
hlfir::genLoopNest(loc, builder, extents, !elemental.isOrdered(),
797+
flangomp::shouldUseWorkshareLowering(elemental));
796798
auto insPt = builder.saveInsertionPoint();
797799
builder.setInsertionPointToStart(loopNest.body);
798800
auto yield = hlfir::inlineElementalOp(loc, builder, elemental,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
2+
3+
add_flang_library(FlangOpenMPTransforms
4+
LowerWorkshare.cpp
5+
6+
DEPENDS
7+
FIRDialect
8+
FlangOpenMPPassesIncGen
9+
${dialect_libs}
10+
11+
LINK_LIBS
12+
FIRAnalysis
13+
FIRDialect
14+
FIRBuilder
15+
FIRDialectSupport
16+
FIRSupport
17+
FIRTransforms
18+
HLFIRDialect
19+
MLIRIR
20+
${dialect_libs}
21+
22+
LINK_COMPONENTS
23+
AsmParser
24+
AsmPrinter
25+
Remarks
26+
)

0 commit comments

Comments
 (0)