Skip to content

Commit

Permalink
[flang][openacc] Resolve symbol in device, host and self clause
Browse files Browse the repository at this point in the history
Some symbols were not resolved in the device, host and self clause
resulting in an `Internal: no symbol found` error.

This patch adds symbol resolution for these clauses.

Reviewed By: razvanlupusoru

Differential Revision: https://reviews.llvm.org/D153919
  • Loading branch information
clementval committed Jun 28, 2023
1 parent 9ed76f3 commit eeba037
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions flang/include/flang/Semantics/symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@ class Symbol {
AccPrivate, AccFirstPrivate, AccShared,
// OpenACC data-mapping attribute
AccCopyIn, AccCopyOut, AccCreate, AccDelete, AccPresent,
// OpenACC data-movement attribute
AccDevice, AccHost, AccSelf,
// OpenACC miscellaneous flags
AccCommonBlock, AccThreadPrivate, AccReduction, AccNone, AccPreDetermined,
// OpenMP data-sharing attribute
Expand Down
24 changes: 24 additions & 0 deletions flang/lib/Semantics/resolve-directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,27 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
return false;
}

bool Pre(const parser::AccClause::Device &x) {
ResolveAccObjectList(x.v, Symbol::Flag::AccDevice);
return false;
}

bool Pre(const parser::AccClause::Host &x) {
ResolveAccObjectList(x.v, Symbol::Flag::AccHost);
return false;
}

bool Pre(const parser::AccClause::Self &x) {
const std::optional<parser::AccSelfClause> &accSelfClause = x.v;
if (accSelfClause &&
std::holds_alternative<parser::AccObjectList>((*accSelfClause).u)) {
const auto &accObjectList =
std::get<parser::AccObjectList>((*accSelfClause).u);
ResolveAccObjectList(accObjectList, Symbol::Flag::AccSelf);
}
return false;
}

void Post(const parser::Name &);

private:
Expand All @@ -210,6 +231,9 @@ class AccAttributeVisitor : DirectiveAttributeVisitor<llvm::acc::Directive> {
Symbol::Flag::AccPrivate, Symbol::Flag::AccFirstPrivate,
Symbol::Flag::AccReduction};

static constexpr Symbol::Flags accDataMvtFlags{
Symbol::Flag::AccDevice, Symbol::Flag::AccHost, Symbol::Flag::AccSelf};

static constexpr Symbol::Flags accFlagsRequireMark{};

void PrivatizeAssociatedLoopIndex(const parser::OpenACCLoopConstruct &);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ program openacc_parallel_loop_validity
end do

!ERROR: SELF clause on the PARALLEL LOOP directive only accepts optional scalar logical expression
!$acc parallel loop self(bb, cc(:))
!$acc parallel loop self(bb, cc(:,:))
do i = 1, N
a(i) = 3.14
end do
Expand Down
16 changes: 16 additions & 0 deletions flang/test/Semantics/OpenACC/acc-resolve04.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! RUN: %flang_fc1 -fopenacc %s

! Check that symbol are correctly resolved in device, host and self clause.

program test_resolve04
real :: a(10), b(10)
common /foo/ b, c

!$acc data create(/foo/)
!$acc update device(/foo/)
!$acc update host(/foo/)
!$acc update self(/foo/)
!$acc end data

end

2 changes: 1 addition & 1 deletion flang/test/Semantics/OpenACC/acc-update-validity.f90
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ program openacc_update_validity
!ERROR: At most one ASYNC clause can appear on the UPDATE directive
!$acc update host(aa, bb) async(1) async(2)

!$acc update self(bb, cc(:)) wait(1)
!$acc update self(bb, cc(:,:)) wait(1)

!ERROR: SELF clause on the UPDATE directive must have a var-list
!$acc update self
Expand Down

0 comments on commit eeba037

Please sign in to comment.