-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Flang][OMP]Add support for DECLARE MAPPER parsing and semantics #115160
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
Changes from 6 commits
8bc59ff
66b0170
3d810ef
98aca98
a5c72cc
085454a
3e563fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1468,6 +1468,10 @@ class OmpVisitor : public virtual DeclarationVisitor { | |
AddOmpSourceRange(x.source); | ||
return true; | ||
} | ||
|
||
bool Pre(const parser::OpenMPDeclareMapperConstruct &); | ||
void Post(const parser::OpenMPDeclareMapperConstruct &) { PopScope(); }; | ||
|
||
void Post(const parser::OmpBeginLoopDirective &) { | ||
messageHandler().set_currStmtSource(std::nullopt); | ||
} | ||
|
@@ -1605,6 +1609,35 @@ void OmpVisitor::Post(const parser::OpenMPBlockConstruct &x) { | |
} | ||
} | ||
|
||
// This "manually" walks the tree of the cosntruct, because the order | ||
kiranchandramohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// elements are resolved by the normal visitor will try to resolve | ||
// the map clauses attached to the directive without having resolved | ||
// the type, so the type is figured out using the implicit rules. | ||
kiranchandramohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool OmpVisitor::Pre(const parser::OpenMPDeclareMapperConstruct &x) { | ||
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. Please add a few comments saying what this function is doing and why everything is done in Pre? 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. Done! 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 don't see a debug-dump-symbols test ( |
||
AddOmpSourceRange(x.source); | ||
BeginDeclTypeSpec(); | ||
const auto &spec{std::get<parser::OmpDeclareMapperSpecifier>(x.t)}; | ||
Symbol *mapperSym{nullptr}; | ||
if (const auto &mapperName{std::get<std::optional<parser::Name>>(spec.t)}) { | ||
mapperSym = | ||
&MakeSymbol(*mapperName, MiscDetails{MiscDetails::Kind::ConstructName}); | ||
mapperName->symbol = mapperSym; | ||
} else { | ||
mapperSym = &MakeSymbol( | ||
"default", Attrs{}, MiscDetails{MiscDetails::Kind::ConstructName}); | ||
kiranchandramohan marked this conversation as resolved.
Show resolved
Hide resolved
TIFitis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
PushScope(Scope::Kind::OtherConstruct, nullptr); | ||
Walk(std::get<parser::TypeSpec>(spec.t)); | ||
const auto &varName{std::get<parser::ObjectName>(spec.t)}; | ||
DeclareObjectEntity(varName); | ||
|
||
Walk(std::get<parser::OmpClauseList>(x.t)); | ||
|
||
EndDeclTypeSpec(); | ||
return false; | ||
} | ||
|
||
// Walk the parse tree and resolve names to symbols. | ||
class ResolveNamesVisitor : public virtual ScopeHandler, | ||
public ModuleVisitor, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
! This test checks lowering of OpenMP declare mapper Directive. | ||
|
||
! RUN: split-file %s %t | ||
! RUN: not %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 %t/omp-declare-mapper-1.f90 2>&1 | FileCheck %t/omp-declare-mapper-1.f90 | ||
! RUN not %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 %t/omp-declare-mapper-2.f90 2>&1 | FileCheck %t/omp-declare-mapper-2.f90 | ||
|
||
!--- omp-declare-mapper-1.f90 | ||
subroutine declare_mapper_1 | ||
integer,parameter :: nvals = 250 | ||
type my_type | ||
integer :: num_vals | ||
integer, allocatable :: values(:) | ||
end type | ||
|
||
type my_type2 | ||
type (my_type) :: my_type_var | ||
type (my_type) :: temp | ||
real,dimension(nvals) :: unmapped | ||
real,dimension(nvals) :: arr | ||
end type | ||
type (my_type2) :: t | ||
real :: x, y(nvals) | ||
!$omp declare mapper (my_type :: var) map (var, var%values (1:var%num_vals)) | ||
!CHECK: not yet implemented: OpenMPDeclareMapperConstruct | ||
end subroutine declare_mapper_1 | ||
|
||
|
||
!--- omp-declare-mapper-2.f90 | ||
subroutine declare_mapper_2 | ||
integer,parameter :: nvals = 250 | ||
type my_type | ||
integer :: num_vals | ||
integer, allocatable :: values(:) | ||
end type | ||
|
||
type my_type2 | ||
type (my_type) :: my_type_var | ||
type (my_type) :: temp | ||
real,dimension(nvals) :: unmapped | ||
real,dimension(nvals) :: arr | ||
end type | ||
type (my_type2) :: t | ||
real :: x, y(nvals) | ||
!$omp declare mapper (my_mapper : my_type2 :: v) map (v%arr, x, y(:)) & | ||
!$omp& map (alloc : v%temp) | ||
!CHECK: not yet implemented: OpenMPDeclareMapperConstruct | ||
end subroutine declare_mapper_2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
! RUN: %flang_fc1 -fdebug-unparse-no-sema -fopenmp %s | FileCheck --ignore-case %s | ||
kiranchandramohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
! RUN: %flang_fc1 -fdebug-dump-parse-tree-no-sema -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s | ||
program main | ||
!CHECK-LABEL: program main | ||
implicit none | ||
|
||
type ty | ||
integer :: x | ||
end type ty | ||
|
||
|
||
!CHECK: !$OMP DECLARE MAPPER (mymapper:ty::mapped) MAP(mapped,mapped%x) | ||
!$omp declare mapper(mymapper : ty :: mapped) map(mapped, mapped%x) | ||
|
||
!PARSE-TREE: OpenMPDeclareMapperConstruct | ||
!PARSE-TREE: OmpDeclareMapperSpecifier | ||
!PARSE-TREE: Name = 'mymapper' | ||
!PARSE-TREE: TypeSpec -> DerivedTypeSpec | ||
!PARSE-TREE: Name = 'ty' | ||
!PARSE-TREE: Name = 'mapped' | ||
!PARSE-TREE: OmpMapClause | ||
!PARSE-TREE: OmpObjectList -> OmpObject -> Designator -> DataRef -> Name = 'mapped' | ||
!PARSE-TREE: OmpObject -> Designator -> DataRef -> StructureComponent | ||
!PARSE-TREE: DataRef -> Name = 'mapped' | ||
!PARSE-TREE: Name = 'x' | ||
|
||
end program main | ||
!CHECK-LABEL: end program main |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=50 | ||
! Test the source code starting with omp syntax | ||
kiranchandramohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
integer :: y | ||
|
||
!ERROR: Type is not a derived type | ||
!$omp declare mapper(mm : integer::x) map(x, y) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
! RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=50 | ||
! Test the source code starting with omp syntax | ||
|
||
type, abstract :: t1 | ||
integer :: y | ||
end type t1 | ||
|
||
!ERROR: ABSTRACT derived type may not be used here | ||
kiranchandramohan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
!$omp declare mapper(mm : t1::x) map(x, x%y) | ||
end |
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.
ultra nit: some of the declarations in this file have a comment giving the OpenMP 5.2 section number and what the parsing looks like (e.g. see DECLARE REDUCTION below). It would be nice to see one here.
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.
Now fixed.