-
Notifications
You must be signed in to change notification settings - Fork 16
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
[flang][OpenMP] Lower private, firstprivate, shared, copyin clauses for Parallel construct #456
Conversation
flang/lib/Lower/OpenMP.cpp
Outdated
@@ -21,6 +23,32 @@ | |||
|
|||
#define TODO() llvm_unreachable("not yet implemented") | |||
|
|||
static const Fortran::parser::Name * | |||
getDesignatorNameIfDataRef(const Fortran::parser::Designator &designator) { | |||
const auto *dataRef{std::get_if<Fortran::parser::DataRef>(&designator.u)}; |
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.
LLVM/MLIR prefer type var = expression;
style. For consistency with MLIR, we follow that style in lowering.
flang/lib/Lower/OpenMP.cpp
Outdated
} else if (const auto &defaultClause = | ||
std::get_if<Fortran::parser::OmpDefaultClause>( | ||
&clause.u)) { | ||
TODO(); |
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.
We're moving to TODO("string")
in lowering. The string can be anything, including "", of course. See Todo.h for more.
flang/lib/Lower/OpenMP.cpp
Outdated
@@ -11,6 +11,8 @@ | |||
//===----------------------------------------------------------------------===// | |||
|
|||
#include "flang/Lower/OpenMP.h" | |||
#include "SymbolMap.h" |
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.
Is this include required? (I probably just missed it while skimming...)
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.
Thanks! Yea, not needed. Must be residual of my other work.
defaultClauseOperand.dyn_cast_or_null<StringAttr>(), | ||
privateClauseOperands, firstprivateClauseOperands, sharedClauseOperands, | ||
copyinClauseOperands, | ||
procBindClauseOperand.dyn_cast_or_null<StringAttr>()); |
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.
You can move the handling of proc_bind and default clause after the op create so you can directly set attribute on it. The code below should get you there. Didn't build it so might need some changes. Also I guess there should be helper functions generated by MLIR TableGen to get the name of the Attr and not hardcoding it
procBindClauseOperand.dyn_cast_or_null<StringAttr>()); | |
procBindClauseOperand.dyn_cast_or_null<StringAttr>()); | |
// Clauses mapped to attributes. | |
for (const auto &clause : parallelOpClauseList.v) { | |
if (const auto &procBindClause = | |
std::get_if<Fortran::parser::OmpProcBindClause>( | |
&clause.u)) { | |
switch (procBindClause.v) { | |
case OmpProcBindClause::Type::Close: | |
parallelOp.setAttr("proc_bind_val", llvm::omp::OMP_PROC_BIND_close); | |
break; | |
case OmpProcBindClause::Type::Master: | |
parallelOp.setAttr("proc_bind_val", llvm::omp::OMP_PROC_BIND_master); | |
break; | |
case OmpProcBindClause::Type::Spread: | |
parallelOp.setAttr("proc_bind_val", llvm::omp::OMP_PROC_BIND_spread); | |
break; | |
} else if (const auto &defaultClause = | |
std::get_if<Fortran::parser::OmpDefaultClause>( | |
&clause.u)) { | |
switch (defaultClause.v) { | |
case OmpDefaultClause::Type::Private: | |
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultPrivate); | |
break; | |
case OmpDefaultClause::Type::Firstprivate: | |
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultFirstprivate); | |
break; | |
case OmpDefaultClause::Type::Shared: | |
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultShared); | |
break; | |
case OmpDefaultClause::Type::None: | |
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultNone); | |
break; | |
} | |
} | |
} | |
} |
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.
Thanks for the suggestion!, I also looked for other solutions.
This one doesn't work since mlir::omp::ClauseDefault::ClauseDefaultNone
doesn't implicitly converts to Attribute
.
parallelOp.setAttr("default_val", mlir::omp::ClauseDefault::ClauseDefaultNone);
Maybe these 2 attributes based clauses deserves a fresh look separately.
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.
As I mentioned, there is probably helper functions to translate enum to string for that purpose. This should be in the tablegen generated file for the OpenMP dialect.
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.
+1 for the progress here. See a few comments inline.
@@ -21,6 +23,32 @@ | |||
|
|||
#define TODO() llvm_unreachable("not yet implemented") | |||
|
|||
static const Fortran::parser::Name * | |||
getDesignatorNameIfDataRef(const Fortran::parser::Designator &designator) { |
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.
Can this function be shared (with OpenACC, possibly elsewhere too) by putting it in a commonplace?
return dataRef ? std::get_if<Fortran::parser::Name>(&dataRef->u) : nullptr; | ||
} | ||
|
||
static void genObjectList(const Fortran::parser::OmpObjectList &objectList, |
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.
Can this be shared too?
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.
Yes, I'm observing and marking these. Some of the Directive handling code can be shared(Maybe LowerDirectives.cpp
in lib/Lower
dir ? or so..). But these are not on top of my priority list as of now.
Since they may break things(for short term) in Lowering of OpenACC
or OpenMP
of which both are developing rapidly and to some sort orthogonal to each other.
!LLVMIR: call void @_QQmain..omp_par | ||
!LLVMIR: call void @__kmpc_end_serialized_parallel | ||
|
||
program ifclause |
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.
Add a few more variants with true, false, constant eval logical expression, logical variable on the if clause.
!LLVMIRDialect: omp.terminator | ||
!LLVMIRDialect: } | ||
|
||
program private_clause |
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.
A few more variants,
-> subroutine arguments.
-> Array
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.
Done thanks!
Just wanted clarify that array
print inside a omp
region doesn't work(crashes). So test cases captures array, however do not attempt to print
them.
This may be related to:
#454
I think once we have the minimal set of operations lowered to fir
dialect, we can start to focus on phase ordering/lower level issues. This will again help us to re-establish end-to-end functional test cases.
flang/lib/Lower/OpenMP.cpp
Outdated
} else if (const auto &procBindClause = | ||
std::get_if<Fortran::parser::OmpProcBindClause>( | ||
&clause.u)) { | ||
TODO("default clause for omp parallel"); |
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.
Ah, I'll take care of this in subsequent revision.
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.
If you don't handle these in this PR, can you adapt the name of the PR and description to reflect it.
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.
Sure, makes sense! Actually just now I noticed there's one more clause allocate
defined in 5.0 standard, currently in review stage.
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.
Rin is handling the allocate clause. You can leave that for now.
flang/lib/Lower/OpenMP.cpp
Outdated
} else if (const auto &procBindClause = | ||
std::get_if<Fortran::parser::OmpProcBindClause>( | ||
&clause.u)) { | ||
TODO("default clause for omp parallel"); |
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.
If you don't handle these in this PR, can you adapt the name of the PR and description to reflect it.
@schweitzpgi plan is to merge this PR post this week scheduled merge. Some changes are still in |
…or Parallel construct TODO: Handle Attribute based clauses: 1. Default clause 2. ProcBind clause
Squashed and prepared for merging. |
Note: This patch reflects the work that can be upstreamed from PR's(merged): 1. flang-compiler#456 2. flang-compiler#485 Also replaced TODO with new TODO. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D89769
Note: This patch reflects the work that can be upstreamed from PR's(merged): 1. flang-compiler/f18-llvm-project#456 2. flang-compiler/f18-llvm-project#485 Also replaced TODO with new TODO. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D89769
Note: This patch reflects the work that can be upstreamed from PR's(merged): 1. flang-compiler/f18-llvm-project#456 2. flang-compiler/f18-llvm-project#485 Also replaced TODO with new TODO. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D89769
TODO:
Handle Attribute based clauses: