Skip to content

Commit 21cfe72

Browse files
committed
Fortran: Add support for OpenMP's nontemporal clause
gcc/fortran/ChangeLog: * gfortran.h: Add OMP_LIST_NONTEMPORAL. * dump-parse-tree.c (show_omp_clauses): Dump it * openmp.c (enum omp_mask1): Add OMP_CLAUSE_NOTEMPORAL. (OMP_SIMD_CLAUSES): Add it. (gfc_match_omp_clauses): Match nontemporal clause. * trans-openmp.c (gfc_trans_omp_clauses): Process nontemporal clause. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/nontemporal-1.f90: New test. * gfortran.dg/gomp/nontemporal-2.f90: New test.
1 parent fe9458c commit 21cfe72

File tree

6 files changed

+63
-1
lines changed

6 files changed

+63
-1
lines changed

gcc/fortran/dump-parse-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ show_omp_clauses (gfc_omp_clauses *omp_clauses)
15951595
case OMP_LIST_IS_DEVICE_PTR: type = "IS_DEVICE_PTR"; break;
15961596
case OMP_LIST_USE_DEVICE_PTR: type = "USE_DEVICE_PTR"; break;
15971597
case OMP_LIST_USE_DEVICE_ADDR: type = "USE_DEVICE_ADDR"; break;
1598+
case OMP_LIST_NONTEMPORAL: type = "NONTEMPORAL"; break;
15981599
default:
15991600
gcc_unreachable ();
16001601
}

gcc/fortran/gfortran.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,7 @@ enum
12761276
OMP_LIST_IS_DEVICE_PTR,
12771277
OMP_LIST_USE_DEVICE_PTR,
12781278
OMP_LIST_USE_DEVICE_ADDR,
1279+
OMP_LIST_NONTEMPORAL,
12791280
OMP_LIST_NUM
12801281
};
12811282

gcc/fortran/openmp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ enum omp_mask1
794794
OMP_CLAUSE_IS_DEVICE_PTR,
795795
OMP_CLAUSE_LINK,
796796
OMP_CLAUSE_NOGROUP,
797+
OMP_CLAUSE_NOTEMPORAL,
797798
OMP_CLAUSE_NUM_TASKS,
798799
OMP_CLAUSE_PRIORITY,
799800
OMP_CLAUSE_SIMD,
@@ -1510,6 +1511,11 @@ gfc_match_omp_clauses (gfc_omp_clauses **cp, const omp_mask mask,
15101511
c->nogroup = needs_space = true;
15111512
continue;
15121513
}
1514+
if ((mask & OMP_CLAUSE_NOTEMPORAL)
1515+
&& gfc_match_omp_variable_list ("nontemporal (",
1516+
&c->lists[OMP_LIST_NONTEMPORAL],
1517+
true) == MATCH_YES)
1518+
continue;
15131519
if ((mask & OMP_CLAUSE_NOTINBRANCH)
15141520
&& !c->notinbranch
15151521
&& !c->inbranch
@@ -2591,7 +2597,7 @@ gfc_match_oacc_routine (void)
25912597
(omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_LASTPRIVATE \
25922598
| OMP_CLAUSE_REDUCTION | OMP_CLAUSE_COLLAPSE | OMP_CLAUSE_SAFELEN \
25932599
| OMP_CLAUSE_LINEAR | OMP_CLAUSE_ALIGNED | OMP_CLAUSE_SIMDLEN \
2594-
| OMP_CLAUSE_IF | OMP_CLAUSE_ORDER)
2600+
| OMP_CLAUSE_IF | OMP_CLAUSE_ORDER | OMP_CLAUSE_NOTEMPORAL)
25952601
#define OMP_TASK_CLAUSES \
25962602
(omp_mask (OMP_CLAUSE_PRIVATE) | OMP_CLAUSE_FIRSTPRIVATE \
25972603
| OMP_CLAUSE_SHARED | OMP_CLAUSE_IF | OMP_CLAUSE_DEFAULT \

gcc/fortran/trans-openmp.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,9 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses,
22902290
case OMP_LIST_IS_DEVICE_PTR:
22912291
clause_code = OMP_CLAUSE_IS_DEVICE_PTR;
22922292
goto add_clause;
2293+
case OMP_LIST_NONTEMPORAL:
2294+
clause_code = OMP_CLAUSE_NONTEMPORAL;
2295+
goto add_clause;
22932296

22942297
add_clause:
22952298
omp_clauses
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
! { dg-do compile }
2+
! { dg-additional-options "-O2 -fdump-tree-original" }
3+
4+
module m
5+
integer :: a(:), b(1024), c(1024), d(1024)
6+
allocatable :: a
7+
end module m
8+
9+
subroutine foo
10+
use m
11+
implicit none
12+
integer :: i
13+
!$omp simd nontemporal (a, b)
14+
do i = 1, 1024
15+
a(i) = b(i) + c(i)
16+
end do
17+
18+
!$omp simd nontemporal (d)
19+
do i = 1, 1024
20+
d(i) = 2 * c(i)
21+
end do
22+
end subroutine foo
23+
24+
! { dg-final { scan-tree-dump-times "#pragma omp simd linear\\(i:1\\) nontemporal\\(a\\) nontemporal\\(b\\)" 1 "original" } }
25+
! { dg-final { scan-tree-dump-times "#pragma omp simd linear\\(i:1\\) nontemporal\\(d\\)" 1 "original" } }
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
! { dg-do compile }
2+
3+
module m
4+
integer, allocatable :: a(:), b(:), c(:), d(:)
5+
end module m
6+
7+
subroutine foo
8+
use m
9+
implicit none
10+
integer :: i
11+
12+
!$omp simd nontemporal (a, b) aligned (a, b, c)
13+
do i = 1, ubound(a, dim=1)
14+
a(i) = b(i) + c(i)
15+
end do
16+
17+
!$omp simd nontemporal (d) nontemporal (d) ! { dg-error "'d' present on multiple clauses" }
18+
do i = 1, ubound(d, dim=1)
19+
d(i) = 2 * c(i)
20+
end do
21+
22+
!$omp simd nontemporal (a, b, b) ! { dg-error "'b' present on multiple clauses" }
23+
do i = 1, ubound(a, dim=1)
24+
a(i) = a(i) + b(i) + c(i)
25+
end do
26+
end subroutine foo

0 commit comments

Comments
 (0)