Skip to content

Commit 568abc2

Browse files
committed
[flang] Lower omp.workshare to other omp constructs
Change to workshare loop wrapper op Move single op declaration Schedule pass properly Correctly handle nested nested loop nests to be parallelized by workshare Leave comments for shouldUseWorkshareLowering Use copyprivate to scatter val from omp.single TODO still need to implement copy function TODO transitive check for usage outside of omp.single not imiplemented yet Transitively check for users outisde of single op TODO need to implement copy func TODO need to hoist allocas outside of single regions Add tests Hoist allocas More tests Emit body for copy func Test the tmp storing logic Clean up trivially dead ops Only handle single-block regions for now Fix tests for custom assembly for loop wrapper Only run the lower workshare pass if openmp is enabled Implement some missing functionality Fix tests Fix test Iterate backwards to find all trivially dead ops Add expalanation comment for createCopyFun Update test
1 parent d8cfd38 commit 568abc2

File tree

16 files changed

+915
-4
lines changed

16 files changed

+915
-4
lines changed

flang/include/flang/Optimizer/OpenMP/Passes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ namespace flangomp {
2525
#define GEN_PASS_REGISTRATION
2626
#include "flang/Optimizer/OpenMP/Passes.h.inc"
2727

28+
/// Impelements the logic specified in the 2.8.3 workshare Construct section of
29+
/// the OpenMP standard which specifies what statements or constructs shall be
30+
/// divided into units of work.
31+
bool shouldUseWorkshareLowering(mlir::Operation *op);
32+
2833
} // namespace flangomp
2934

3035
#endif // FORTRAN_OPTIMIZER_OPENMP_PASSES_H

flang/include/flang/Optimizer/OpenMP/Passes.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,9 @@ def FunctionFilteringPass : Pass<"omp-function-filtering"> {
3737
];
3838
}
3939

40+
// Needs to be scheduled on Module as we create functions in it
41+
def LowerWorkshare : Pass<"lower-workshare", "::mlir::ModuleOp"> {
42+
let summary = "Lower workshare construct";
43+
}
44+
4045
#endif //FORTRAN_OPTIMIZER_OPENMP_PASSES

flang/include/flang/Tools/CrossToolHelpers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct MLIRToLLVMPassPipelineConfig : public FlangEPCallBacks {
123123
false; ///< Set no-signed-zeros-fp-math attribute for functions.
124124
bool UnsafeFPMath = false; ///< Set unsafe-fp-math attribute for functions.
125125
bool NSWOnLoopVarInc = false; ///< Add nsw flag to loop variable increments.
126+
bool EnableOpenMP = false; ///< Enable OpenMP lowering.
126127
};
127128

128129
struct OffloadModuleOpts {

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,11 @@ void CodeGenAction::lowerHLFIRToFIR() {
715715
pm.enableVerifier(/*verifyPasses=*/true);
716716

717717
// Create the pass pipeline
718-
fir::createHLFIRToFIRPassPipeline(pm, level);
718+
fir::createHLFIRToFIRPassPipeline(
719+
pm,
720+
ci.getInvocation().getFrontendOpts().features.IsEnabled(
721+
Fortran::common::LanguageFeature::OpenMP),
722+
level);
719723
(void)mlir::applyPassManagerCLOptions(pm);
720724

721725
if (!mlir::succeeded(pm.run(*mlirModule))) {
@@ -828,6 +832,10 @@ void CodeGenAction::generateLLVMIR() {
828832
config.VScaleMax = vsr->second;
829833
}
830834

835+
if (ci.getInvocation().getFrontendOpts().features.IsEnabled(
836+
Fortran::common::LanguageFeature::OpenMP))
837+
config.EnableOpenMP = true;
838+
831839
if (ci.getInvocation().getLoweringOpts().getNSWOnLoopVarInc())
832840
config.NSWOnLoopVarInc = true;
833841

flang/lib/Optimizer/OpenMP/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_flang_library(FlangOpenMPTransforms
44
FunctionFiltering.cpp
55
MapInfoFinalization.cpp
66
MarkDeclareTarget.cpp
7+
LowerWorkshare.cpp
78

89
DEPENDS
910
FIRDialect

0 commit comments

Comments
 (0)