-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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] Add semantic checks for detach clause in task #119172
base: main
Are you sure you want to change the base?
[Flang] [OpenMP] Add semantic checks for detach clause in task #119172
Conversation
|
@llvm/pr-subscribers-flang-openmp @llvm/pr-subscribers-flang-semantics Author: Thirumalai Shaktivel (Thirumalai-Shaktivel) ChangesFixes:
Restrictions:
OpenMP 5.2: Detach contruct
Full diff: https://github.com/llvm/llvm-project/pull/119172.diff 4 Files Affected:
|
You can test this locally with the following command:View the diff from clang-format here. |
|
There seems to be some problem with I get the following locally The failed line seems to be within the range (80 characters): |
Fixes: - Add semantic checks along with the tests - Move the detach clause to allowedOnceClauses list in Task construct Restrictions:\ OpenMP 5.0: Task construct - At most one detach clause can appear on the directive. - If a detach clause appears on the directive, then a mergeable clause cannot appear on the same directive. OpenMP 5.2: Detach contruct - If a detach clause appears on a directive, then the encountering task must not be a final task. - A variable that appears in a detach clause cannot appear as a list item on a data-environment attribute clause on the same construct. - A variable that is part of another variable (as an array element or a structure element) cannot appear in a detach clause. - event-handle must not have the POINTER attribute.
3da984c to
414ea0c
Compare
| } | ||
| auto type{name->symbol->GetType()}; | ||
| if (!name->symbol->GetType()->IsNumeric(TypeCategory::Integer) || | ||
| evaluate::ToInt64(type->numericTypeSpec().kind()) != 8) { |
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.
Please remove the check of the kind. We shouldn't be using hardcoded numbers.
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 felt the same. But, the only info I had was the kind => 8 to throw an error for the following:
!ERROR: The event-handle: `e` must be of type integer(kind=omp_event_handle_kind)
!$omp task detach(e)
x = x + 1
!$omp end task
Do you know any other way to add a check for this?
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 don't have a way of checking this, unfortunately. In other cases we limit it to checking that it has an INTEGER type, but without checking the kind.
| @@ -2739,6 +2739,59 @@ void OmpStructureChecker::Leave(const parser::OmpClauseList &) { | |||
| llvm::omp::Clause::OMPC_copyprivate, {llvm::omp::Clause::OMPC_nowait}); | |||
| } | |||
|
|
|||
| if (GetContext().directive == llvm::omp::Directive::OMPD_task) { | |||
| if (auto *d_clause{FindClause(llvm::omp::Clause::OMPC_detach)}) { | |||
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.
No snake_case please (d_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.
Good catch, I forgot to update this.
| // OpenMP 5.0: Task construct restrictions | ||
| CheckNotAllowedIfClause( | ||
| llvm::omp::Clause::OMPC_detach, {llvm::omp::Clause::OMPC_mergeable}); | ||
|
|
||
| // OpenMP 5.2: Task construct restrictions |
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're doing version-specific checks, please guard them with the actual version from -fopenmp-version. You can get it from the language options in context. This is done in a number of places in this file, you can check how to do it.
| std::string eventHandleSymName{name->ToString()}; | ||
| auto checkVarAppearsInDataEnvClause = [&](const parser::OmpObjectList | ||
| &objs, | ||
| std::string clause) { | ||
| for (const auto &obj : objs.v) { | ||
| if (const parser::Name *objName{ | ||
| parser::Unwrap<parser::Name>(obj)}) { | ||
| if (objName->ToString() == eventHandleSymName) { | ||
| context_.Say(GetContext().clauseSource, | ||
| "A variable: `%s` that appears in a DETACH clause cannot appear on %s clause on the same construct"_err_en_US, | ||
| eventHandleSymName, 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.
Please compare symbols, not names. You can compare the results of &symbol->GetUltimate() to be accurate.
| // OpenMP 5.0: Task construct restrictions | ||
| CheckAllowedClause(llvm::omp::Clause::OMPC_detach); | ||
|
|
||
| // OpenMP 5.2: Detach clause restrictions |
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.
Same here: please do version-specific checks based on the actual version.
|
Sure, thanks for the review. I will update it and report back soon. |
Fixes:
Restrictions:
OpenMP 5.0: Task construct
OpenMP 5.2: Detach contruct