-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Flang][OpenMP] Push genEval calls to individual operations, NFC #77758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
62f3165
[Flang][OpenMP] Separate creation of work-sharing and SIMD loops, NFC
kparzysz 841ae5f
[Flang][OpenMP] Push genEval calls to individual operations, NFC
kparzysz 8733efc
Rename `getEvalPastCollapse` to `getCollapsedEval`
kparzysz ffda6b2
Add symbol table parameter to remaining `genOMP` functions
kparzysz 28d4f7d
Merge branch 'main' into users/kparzysz/spr/a02-geneval-individual
kparzysz 0d9755d
Make all `genOMP` functions have the same interface
kparzysz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,6 +110,34 @@ static void gatherFuncAndVarSyms( | |
} | ||
} | ||
|
||
static Fortran::lower::pft::Evaluation * | ||
getCollapsedEval(Fortran::lower::pft::Evaluation &eval, int collapseValue) { | ||
// Return the Evaluation of the innermost collapsed loop, or the current | ||
// evaluation, if there is nothing to collapse. | ||
if (collapseValue == 0) | ||
return &eval; | ||
Comment on lines
+115
to
+118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Is it better to convert this to an assert (for > 0) and move this code to the parent function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll make this change in another commit. |
||
|
||
Fortran::lower::pft::Evaluation *curEval = &eval.getFirstNestedEvaluation(); | ||
for (int i = 1; i < collapseValue; i++) { | ||
// The nested evaluations should be DoConstructs (i.e. they should form | ||
// a loop nest). Each DoConstruct is a tuple <NonLabelDoStmt, Block, | ||
// EndDoStmt>. | ||
assert(curEval->isA<Fortran::parser::DoConstruct>()); | ||
curEval = &*std::next(curEval->getNestedEvaluations().begin()); | ||
} | ||
return curEval; | ||
} | ||
|
||
static void genNestedEvaluations(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::pft::Evaluation &eval, | ||
int collapseValue = 0) { | ||
Fortran::lower::pft::Evaluation *curEval = | ||
getCollapsedEval(eval, collapseValue); | ||
|
||
for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations()) | ||
converter.genEval(e); | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// DataSharingProcessor | ||
//===----------------------------------------------------------------------===// | ||
|
@@ -2944,8 +2972,9 @@ genOmpFlush(Fortran::lower::AbstractConverter &converter, | |
|
||
static void | ||
genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::pft::Evaluation &eval, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPStandaloneConstruct &standaloneConstruct) { | ||
std::visit( | ||
Fortran::common::visitors{ | ||
|
@@ -3034,6 +3063,9 @@ createSimdLoop(Fortran::lower::AbstractConverter &converter, | |
createBodyOfOp<mlir::omp::SimdLoopOp>(simdLoopOp, converter, loc, eval, | ||
&loopOpClauseList, iv, | ||
/*outer=*/false, &dsp); | ||
|
||
genNestedEvaluations(converter, eval, | ||
Fortran::lower::getCollapseValue(loopOpClauseList)); | ||
} | ||
|
||
static void createWsLoop(Fortran::lower::AbstractConverter &converter, | ||
|
@@ -3107,11 +3139,15 @@ static void createWsLoop(Fortran::lower::AbstractConverter &converter, | |
createBodyOfOp<mlir::omp::WsLoopOp>(wsLoopOp, converter, loc, eval, | ||
&beginClauseList, iv, | ||
/*outer=*/false, &dsp); | ||
|
||
genNestedEvaluations(converter, eval, | ||
Fortran::lower::getCollapseValue(beginClauseList)); | ||
} | ||
|
||
static void genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::pft::Evaluation &eval, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPLoopConstruct &loopConstruct) { | ||
const auto &beginLoopDirective = | ||
std::get<Fortran::parser::OmpBeginLoopDirective>(loopConstruct.t); | ||
|
@@ -3179,12 +3215,15 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, | |
createWsLoop(converter, eval, ompDirective, loopOpClauseList, endClauseList, | ||
currentLocation); | ||
} | ||
|
||
genOpenMPReduction(converter, loopOpClauseList); | ||
} | ||
|
||
static void | ||
genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::pft::Evaluation &eval, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPBlockConstruct &blockConstruct) { | ||
const auto &beginBlockDirective = | ||
std::get<Fortran::parser::OmpBeginBlockDirective>(blockConstruct.t); | ||
|
@@ -3298,10 +3337,15 @@ genOMP(Fortran::lower::AbstractConverter &converter, | |
break; | ||
} | ||
} | ||
|
||
genNestedEvaluations(converter, eval); | ||
genOpenMPReduction(converter, beginClauseList); | ||
} | ||
|
||
static void | ||
genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPCriticalConstruct &criticalConstruct) { | ||
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); | ||
|
@@ -3336,10 +3380,13 @@ genOMP(Fortran::lower::AbstractConverter &converter, | |
}(); | ||
createBodyOfOp<mlir::omp::CriticalOp>(criticalOp, converter, currentLocation, | ||
eval); | ||
genNestedEvaluations(converter, eval); | ||
} | ||
|
||
static void | ||
genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPSectionConstruct §ionConstruct) { | ||
mlir::Location currentLocation = converter.getCurrentLocation(); | ||
|
@@ -3359,13 +3406,18 @@ genOMP(Fortran::lower::AbstractConverter &converter, | |
.t); | ||
// Currently only private/firstprivate clause is handled, and | ||
// all privatization is done within `omp.section` operations. | ||
symTable.pushScope(); | ||
skatrak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
genOpWithBody<mlir::omp::SectionOp>(converter, eval, currentLocation, | ||
/*outerCombined=*/false, | ||
§ionsClauseList); | ||
genNestedEvaluations(converter, eval); | ||
symTable.popScope(); | ||
} | ||
|
||
static void | ||
genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPSectionsConstruct §ionsConstruct) { | ||
mlir::Location currentLocation = converter.getCurrentLocation(); | ||
|
@@ -3406,10 +3458,14 @@ genOMP(Fortran::lower::AbstractConverter &converter, | |
/*reduction_vars=*/mlir::ValueRange(), | ||
/*reductions=*/nullptr, allocateOperands, | ||
allocatorOperands, nowaitClauseOperand); | ||
|
||
genNestedEvaluations(converter, eval); | ||
} | ||
|
||
static void | ||
genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPAtomicConstruct &atomicConstruct) { | ||
std::visit( | ||
|
@@ -3453,6 +3509,8 @@ genOMP(Fortran::lower::AbstractConverter &converter, | |
} | ||
|
||
static void genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPDeclareTargetConstruct | ||
&declareTargetConstruct) { | ||
|
@@ -3504,24 +3562,28 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, | |
} | ||
|
||
static void genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPConstruct &ompConstruct) { | ||
std::visit( | ||
Fortran::common::visitors{ | ||
[&](const Fortran::parser::OpenMPStandaloneConstruct | ||
&standaloneConstruct) { | ||
genOMP(converter, eval, semanticsContext, standaloneConstruct); | ||
genOMP(converter, symTable, semanticsContext, eval, | ||
standaloneConstruct); | ||
}, | ||
[&](const Fortran::parser::OpenMPSectionsConstruct | ||
§ionsConstruct) { | ||
genOMP(converter, eval, sectionsConstruct); | ||
genOMP(converter, symTable, semanticsContext, eval, | ||
sectionsConstruct); | ||
}, | ||
[&](const Fortran::parser::OpenMPSectionConstruct §ionConstruct) { | ||
genOMP(converter, eval, sectionConstruct); | ||
genOMP(converter, symTable, semanticsContext, eval, | ||
sectionConstruct); | ||
}, | ||
[&](const Fortran::parser::OpenMPLoopConstruct &loopConstruct) { | ||
genOMP(converter, eval, semanticsContext, loopConstruct); | ||
genOMP(converter, symTable, semanticsContext, eval, loopConstruct); | ||
}, | ||
[&](const Fortran::parser::OpenMPDeclarativeAllocate | ||
&execAllocConstruct) { | ||
|
@@ -3536,21 +3598,25 @@ static void genOMP(Fortran::lower::AbstractConverter &converter, | |
TODO(converter.getCurrentLocation(), "OpenMPAllocatorsConstruct"); | ||
}, | ||
[&](const Fortran::parser::OpenMPBlockConstruct &blockConstruct) { | ||
genOMP(converter, eval, semanticsContext, blockConstruct); | ||
genOMP(converter, symTable, semanticsContext, eval, blockConstruct); | ||
}, | ||
[&](const Fortran::parser::OpenMPAtomicConstruct &atomicConstruct) { | ||
genOMP(converter, eval, atomicConstruct); | ||
genOMP(converter, symTable, semanticsContext, eval, | ||
atomicConstruct); | ||
}, | ||
[&](const Fortran::parser::OpenMPCriticalConstruct | ||
&criticalConstruct) { | ||
genOMP(converter, eval, criticalConstruct); | ||
genOMP(converter, symTable, semanticsContext, eval, | ||
criticalConstruct); | ||
}, | ||
}, | ||
ompConstruct.u); | ||
} | ||
|
||
static void | ||
genOMP(Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPDeclarativeConstruct &ompDeclConstruct) { | ||
std::visit( | ||
|
@@ -3570,7 +3636,8 @@ genOMP(Fortran::lower::AbstractConverter &converter, | |
}, | ||
[&](const Fortran::parser::OpenMPDeclareTargetConstruct | ||
&declareTargetConstruct) { | ||
genOMP(converter, eval, declareTargetConstruct); | ||
genOMP(converter, symTable, semanticsContext, eval, | ||
declareTargetConstruct); | ||
}, | ||
[&](const Fortran::parser::OpenMPRequiresConstruct | ||
&requiresConstruct) { | ||
|
@@ -3607,57 +3674,19 @@ void Fortran::lower::genOpenMPConstruct( | |
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPConstruct &omp) { | ||
|
||
symTable.pushScope(); | ||
genOMP(converter, semanticsContext, eval, omp); | ||
|
||
const Fortran::parser::OpenMPLoopConstruct *ompLoop = | ||
std::get_if<Fortran::parser::OpenMPLoopConstruct>(&omp.u); | ||
const Fortran::parser::OpenMPBlockConstruct *ompBlock = | ||
std::get_if<Fortran::parser::OpenMPBlockConstruct>(&omp.u); | ||
|
||
// If loop is part of an OpenMP Construct then the OpenMP dialect | ||
// workshare loop operation has already been created. Only the | ||
// body needs to be created here and the do_loop can be skipped. | ||
// Skip the number of collapsed loops, which is 1 when there is a | ||
// no collapse requested. | ||
|
||
Fortran::lower::pft::Evaluation *curEval = &eval; | ||
const Fortran::parser::OmpClauseList *loopOpClauseList = nullptr; | ||
if (ompLoop) { | ||
loopOpClauseList = &std::get<Fortran::parser::OmpClauseList>( | ||
std::get<Fortran::parser::OmpBeginLoopDirective>(ompLoop->t).t); | ||
int64_t collapseValue = Fortran::lower::getCollapseValue(*loopOpClauseList); | ||
|
||
curEval = &curEval->getFirstNestedEvaluation(); | ||
for (int64_t i = 1; i < collapseValue; i++) { | ||
curEval = &*std::next(curEval->getNestedEvaluations().begin()); | ||
} | ||
} | ||
|
||
for (Fortran::lower::pft::Evaluation &e : curEval->getNestedEvaluations()) | ||
converter.genEval(e); | ||
|
||
if (ompLoop) { | ||
genOpenMPReduction(converter, *loopOpClauseList); | ||
} else if (ompBlock) { | ||
const auto &blockStart = | ||
std::get<Fortran::parser::OmpBeginBlockDirective>(ompBlock->t); | ||
const auto &blockClauses = | ||
std::get<Fortran::parser::OmpClauseList>(blockStart.t); | ||
genOpenMPReduction(converter, blockClauses); | ||
} | ||
|
||
genOMP(converter, symTable, semanticsContext, eval, omp); | ||
symTable.popScope(); | ||
} | ||
|
||
void Fortran::lower::genOpenMPDeclarativeConstruct( | ||
Fortran::lower::AbstractConverter &converter, | ||
Fortran::lower::SymMap &symTable, | ||
Fortran::semantics::SemanticsContext &semanticsContext, | ||
Fortran::lower::pft::Evaluation &eval, | ||
const Fortran::parser::OpenMPDeclarativeConstruct &omp) { | ||
genOMP(converter, eval, omp); | ||
for (Fortran::lower::pft::Evaluation &e : eval.getNestedEvaluations()) | ||
converter.genEval(e); | ||
genOMP(converter, symTable, semanticsContext, eval, omp); | ||
genNestedEvaluations(converter, eval); | ||
} | ||
|
||
void Fortran::lower::genOpenMPSymbolProperties( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Maybe
getCollapsedLoopEval
would be slightly more self-explanatory?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make this change in another commit.