From b9a8f34d476e03a22fb7e75aef265febc7fd21fd Mon Sep 17 00:00:00 2001 From: Arnamoy Bhattacharyya Date: Mon, 13 Sep 2021 12:29:22 -0400 Subject: [PATCH] [flang][OpenMP] Add parsing support for nontemporal clause. This patch adds parsing support for the nontemporal clause. Also adds a couple of test cases. Reviewed By: clementval Differential Revision: https://reviews.llvm.org/D106896 --- flang/include/flang/Semantics/symbol.h | 2 +- flang/lib/Parser/openmp-parsers.cpp | 2 + flang/lib/Semantics/resolve-directives.cpp | 7 ++ flang/test/Parser/omp-nontemporal-unparse.f90 | 19 ++++ flang/test/Semantics/omp-nontemporal.f90 | 95 +++++++++++++++++++ llvm/include/llvm/Frontend/OpenMP/OMP.td | 2 + 6 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 flang/test/Parser/omp-nontemporal-unparse.f90 create mode 100644 flang/test/Semantics/omp-nontemporal.f90 diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h index 8810c5785370..b287b91e14fb 100644 --- a/flang/include/flang/Semantics/symbol.h +++ b/flang/include/flang/Semantics/symbol.h @@ -511,7 +511,7 @@ public: // OpenMP data-copying attribute OmpCopyIn, OmpCopyPrivate, // OpenMP miscellaneous flags - OmpCommonBlock, OmpReduction, OmpAligned, OmpAllocate, + OmpCommonBlock, OmpReduction, OmpAligned, OmpNontemporal, OmpAllocate, OmpDeclarativeAllocateDirective, OmpExecutableAllocateDirective, OmpDeclareSimd, OmpDeclareTarget, OmpThreadprivate, OmpDeclareReduction, OmpFlushed, OmpCriticalLock, OmpIfSpecified, OmpNone, OmpPreDetermined); diff --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp index 93f70e165f6b..5585630b20e8 100644 --- a/flang/lib/Parser/openmp-parsers.cpp +++ b/flang/lib/Parser/openmp-parsers.cpp @@ -203,6 +203,8 @@ TYPE_PARSER( parenthesized(Parser{}))) || "MERGEABLE" >> construct(construct()) || "NOGROUP" >> construct(construct()) || + "NONTEMPORAL" >> construct(construct( + parenthesized(nonemptyList(name)))) || "NOTINBRANCH" >> construct(construct()) || "NOWAIT" >> construct(construct()) || diff --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp index e1fc1ec43e22..120f4db423e4 100644 --- a/flang/lib/Semantics/resolve-directives.cpp +++ b/flang/lib/Semantics/resolve-directives.cpp @@ -407,6 +407,13 @@ public: ResolveOmpNameList(alignedNameList, Symbol::Flag::OmpAligned); return false; } + + bool Pre(const parser::OmpClause::Nontemporal &x) { + const auto &nontemporalNameList{x.v}; + ResolveOmpNameList(nontemporalNameList, Symbol::Flag::OmpNontemporal); + return false; + } + void Post(const parser::Name &); // Keep track of labels in the statements that causes jumps to target labels diff --git a/flang/test/Parser/omp-nontemporal-unparse.f90 b/flang/test/Parser/omp-nontemporal-unparse.f90 new file mode 100644 index 000000000000..236c92416ea1 --- /dev/null +++ b/flang/test/Parser/omp-nontemporal-unparse.f90 @@ -0,0 +1,19 @@ +! RUN: %flang_fc1 -fdebug-unparse-no-sema -fopenmp %s | FileCheck %s + +program omp_simd + integer i + integer, allocatable :: a(:) + + allocate(a(10)) + + !NONTEMPORAL + !$omp simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end simd +end program omp_simd +!CHECK-LABEL: PROGRAM omp_simd + +!NONTEMPORAL +!CHECK: !$OMP SIMD NONTEMPORAL(a) diff --git a/flang/test/Semantics/omp-nontemporal.f90 b/flang/test/Semantics/omp-nontemporal.f90 new file mode 100644 index 000000000000..ea910bec048c --- /dev/null +++ b/flang/test/Semantics/omp-nontemporal.f90 @@ -0,0 +1,95 @@ +! RUN: %python %S/test_errors.py %s %flang -fopenmp +! REQUIRES: shell +! Check OpenMP clause validity for NONTEMPORAL clause + +program omp_simd + integer i + integer, allocatable :: a(:) + + allocate(a(10)) + + !$omp simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end simd + + !$omp parallel do simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end parallel do simd + + !$omp parallel do simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end parallel do simd + + !ERROR: NONTEMPORAL clause is not allowed on the DO SIMD directive + !$omp do simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end do simd + + !$omp taskloop simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end taskloop simd + + !$omp teams + !$omp distribute parallel do simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end distribute parallel do simd + !$omp end teams + + !$omp teams + !$omp distribute simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end distribute simd + !$omp end teams + + !$omp target parallel do simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end target parallel do simd + + !$omp target simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end target simd + + !$omp teams distribute simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end teams distribute simd + + !$omp teams distribute parallel do simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end teams distribute parallel do simd + + !$omp target teams distribute parallel do simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end target teams distribute parallel do simd + + !$omp target teams distribute simd nontemporal(a) + do i = 1, 10 + a(i) = i + end do + !$omp end target teams distribute simd + + +end program omp_simd diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td index d5a62107bbb8..5ed279c2d152 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMP.td +++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td @@ -261,6 +261,8 @@ def OMPC_Allocate : Clause<"allocate"> { } def OMPC_NonTemporal : Clause<"nontemporal"> { let clangClass = "OMPNontemporalClause"; + let flangClass = "Name"; + let isValueList = true; } def OMP_ORDER_concurrent : ClauseVal<"default",2,0> { let isDefault = 1; }