Skip to content

Commit d6ef90f

Browse files
committed
[OpenMP][Flang][Semantics] Add semantics support for USE_DEVICE_PTR clause on OMP TARGET DATA directive.
Initial support for USE_DEVICE_PTR clause on OMP TARGET DATA directive. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D148254
1 parent b1465cd commit d6ef90f

File tree

8 files changed

+53
-10
lines changed

8 files changed

+53
-10
lines changed

flang/docs/OpenMP-semantics.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ w/
318318
For the following OpenMP regions:
319319

320320
* `target` regions
321+
* `target data` regions
321322
* `teams` regions
322323
* `parallel` regions
323324
* `simd` regions
@@ -407,6 +408,16 @@ More details are listed in the following table:
407408
<td>OmpLastPrivate
408409
</td>
409410
</tr>
411+
<tr>
412+
<td>use_device_ptr
413+
</td>
414+
<td>Yes
415+
</td>
416+
<td>New Symbol
417+
</td>
418+
<td>OmpUseDevicePtr
419+
</td>
420+
</tr>
410421
</table>
411422

412423
To determine the right data-sharing attribute,
@@ -519,6 +530,12 @@ will be determined and represented as `Flag` in the `Symbol` object
519530
of the variable.
520531
No `Symbol` or `Scope` will be created.
521532

533+
However, there are some exceptions for this, Pointers that appear in a
534+
use_device_ptr clause are privatized and the device pointers to the
535+
corresponding list items in the device data environment are assigned into the
536+
private versions so it is best to follow the representation for privatised
537+
variables i.e represent them with a new Symbol and `OmpUseDevicePtr` flag.
538+
522539
The basic steps to determine the data-mapping attribute are:
523540

524541
1. If _map_ clause is present,

flang/include/flang/Semantics/symbol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ class Symbol {
560560
OmpShared, OmpPrivate, OmpLinear, OmpFirstPrivate, OmpLastPrivate,
561561
// OpenMP data-mapping attribute
562562
OmpMapTo, OmpMapFrom, OmpMapAlloc, OmpMapRelease, OmpMapDelete,
563+
OmpUseDevicePtr,
563564
// OpenMP data-copying attribute
564565
OmpCopyIn, OmpCopyPrivate,
565566
// OpenMP miscellaneous flags

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ TYPE_PARSER(
309309
"TO" >> construct<OmpClause>(construct<OmpClause::To>(
310310
parenthesized(Parser<OmpObjectList>{}))) ||
311311
"USE_DEVICE_PTR" >> construct<OmpClause>(construct<OmpClause::UseDevicePtr>(
312-
parenthesized(nonemptyList(name)))) ||
312+
parenthesized(Parser<OmpObjectList>{}))) ||
313313
"UNIFIED_ADDRESS" >>
314314
construct<OmpClause>(construct<OmpClause::UnifiedAddress>()) ||
315315
"UNIFIED_SHARED_MEMORY" >>

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,11 +2766,12 @@ const parser::OmpObjectList *OmpStructureChecker::GetOmpObjectList(
27662766
const parser::OmpClause &clause) {
27672767

27682768
// Clauses with OmpObjectList as its data member
2769-
using MemberObjectListClauses = std::tuple<parser::OmpClause::Copyprivate,
2770-
parser::OmpClause::Copyin, parser::OmpClause::Firstprivate,
2771-
parser::OmpClause::From, parser::OmpClause::Lastprivate,
2772-
parser::OmpClause::Link, parser::OmpClause::Private,
2773-
parser::OmpClause::Shared, parser::OmpClause::To>;
2769+
using MemberObjectListClauses =
2770+
std::tuple<parser::OmpClause::Copyprivate, parser::OmpClause::Copyin,
2771+
parser::OmpClause::Firstprivate, parser::OmpClause::From,
2772+
parser::OmpClause::Lastprivate, parser::OmpClause::Link,
2773+
parser::OmpClause::Private, parser::OmpClause::Shared,
2774+
parser::OmpClause::To, parser::OmpClause::UseDevicePtr>;
27742775

27752776
// Clauses with OmpObjectList in the tuple
27762777
using TupleObjectListClauses = std::tuple<parser::OmpClause::Allocate,

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,11 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
436436
return false;
437437
}
438438

439+
bool Pre(const parser::OmpClause::UseDevicePtr &x) {
440+
ResolveOmpObjectList(x.v, Symbol::Flag::OmpUseDevicePtr);
441+
return false;
442+
}
443+
439444
void Post(const parser::Name &);
440445

441446
// Keep track of labels in the statements that causes jumps to target labels
@@ -506,7 +511,7 @@ class OmpAttributeVisitor : DirectiveAttributeVisitor<llvm::omp::Directive> {
506511
Symbol::Flag::OmpPrivate, Symbol::Flag::OmpLinear,
507512
Symbol::Flag::OmpFirstPrivate, Symbol::Flag::OmpLastPrivate,
508513
Symbol::Flag::OmpReduction, Symbol::Flag::OmpCriticalLock,
509-
Symbol::Flag::OmpCopyIn};
514+
Symbol::Flag::OmpCopyIn, Symbol::Flag::OmpUseDevicePtr};
510515

511516
static constexpr Symbol::Flags ompFlagsRequireMark{
512517
Symbol::Flag::OmpThreadprivate};

flang/lib/Semantics/resolve-names.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,6 @@ bool OmpVisitor::NeedsScope(const parser::OpenMPBlockConstruct &x) {
14141414
const auto &beginBlockDir{std::get<parser::OmpBeginBlockDirective>(x.t)};
14151415
const auto &beginDir{std::get<parser::OmpBlockDirective>(beginBlockDir.t)};
14161416
switch (beginDir.v) {
1417-
case llvm::omp::Directive::OMPD_target_data:
14181417
case llvm::omp::Directive::OMPD_master:
14191418
case llvm::omp::Directive::OMPD_ordered:
14201419
case llvm::omp::Directive::OMPD_taskgroup:
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! RUN: %flang -fc1 -fopenmp -fdebug-dump-symbols %s | FileCheck %s
2+
! OpenMP Version 5.0
3+
! 2.10.1 use_device_ptr clause
4+
! List items that appear in a use_device_ptr clause are converted into device
5+
! pointers to the corresponding list item in the device data environment.
6+
7+
subroutine omp_target_data
8+
use iso_c_binding
9+
integer :: a(1024)
10+
!CHECK: b size=8 offset=4096: ObjectEntity type: TYPE(c_ptr)
11+
type(C_PTR) :: b
12+
integer, pointer :: arrayB
13+
a = 1
14+
!$omp target data map(tofrom: a, arrayB) use_device_ptr(b)
15+
!CHECK: b (OmpUseDevicePtr)
16+
allocate(arrayB)
17+
call c_f_pointer(b, arrayB)
18+
a = arrayB
19+
!$omp end target data
20+
end subroutine omp_target_data
21+

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ def OMPC_From : Clause<"from"> {
295295
}
296296
def OMPC_UseDevicePtr : Clause<"use_device_ptr"> {
297297
let clangClass = "OMPUseDevicePtrClause";
298-
let flangClass = "Name";
299-
let isValueList = true;
298+
let flangClass = "OmpObjectList";
300299
}
301300
def OMPC_IsDevicePtr : Clause<"is_device_ptr"> {
302301
let clangClass = "OMPIsDevicePtrClause";

0 commit comments

Comments
 (0)