Skip to content

Commit fbd9ab0

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 Emit a proper error message for CFG in workshare Cleanup tests Fix todo tests Fix dst src in copy function Use omp.single to handle CFG cases Fix lower workshare tests Different warning Fix bug and add better clarification comments Fix message Fix tests Do not emit empty omp.single's LowerWorkshare tests pipelines fix
1 parent 382728a commit fbd9ab0

20 files changed

+908
-5
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
@@ -50,4 +50,9 @@ def FunctionFilteringPass : Pass<"omp-function-filtering"> {
5050
];
5151
}
5252

53+
// Needs to be scheduled on Module as we create functions in it
54+
def LowerWorkshare : Pass<"lower-workshare", "::mlir::ModuleOp"> {
55+
let summary = "Lower workshare construct";
56+
}
57+
5358
#endif //FORTRAN_OPTIMIZER_OPENMP_PASSES

flang/include/flang/Optimizer/Passes/Pipelines.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ void createDefaultFIROptimizerPassPipeline(mlir::PassManager &pm,
123123
/// \param optLevel - optimization level used for creating FIR optimization
124124
/// passes pipeline
125125
void createHLFIRToFIRPassPipeline(
126-
mlir::PassManager &pm, llvm::OptimizationLevel optLevel = defaultOptLevel);
126+
mlir::PassManager &pm, bool enableOpenMP,
127+
llvm::OptimizationLevel optLevel = defaultOptLevel);
127128

128129
/// Create a pass pipeline for handling certain OpenMP transformations needed
129130
/// prior to FIR lowering.

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
@@ -5,6 +5,7 @@ add_flang_library(FlangOpenMPTransforms
55
MapsForPrivatizedSymbols.cpp
66
MapInfoFinalization.cpp
77
MarkDeclareTarget.cpp
8+
LowerWorkshare.cpp
89

910
DEPENDS
1011
FIRDialect

0 commit comments

Comments
 (0)