[flang][OpenMP] Add parsing support for nontemporal clause.
authorArnamoy Bhattacharyya <arnamoy.bhattacharyya@huawei.com>
Mon, 13 Sep 2021 16:29:22 +0000 (12:29 -0400)
committerArnamoy Bhattacharyya <arnamoy.bhattacharyya@huawei.com>
Mon, 13 Sep 2021 19:25:47 +0000 (15:25 -0400)
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
flang/lib/Parser/openmp-parsers.cpp
flang/lib/Semantics/resolve-directives.cpp
flang/test/Parser/omp-nontemporal-unparse.f90 [new file with mode: 0644]
flang/test/Semantics/omp-nontemporal.f90 [new file with mode: 0644]
llvm/include/llvm/Frontend/OpenMP/OMP.td

index 8810c57..b287b91 100644 (file)
@@ -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);
index 93f70e1..5585630 100644 (file)
@@ -203,6 +203,8 @@ TYPE_PARSER(
                  parenthesized(Parser<OmpMapClause>{}))) ||
     "MERGEABLE" >> construct<OmpClause>(construct<OmpClause::Mergeable>()) ||
     "NOGROUP" >> construct<OmpClause>(construct<OmpClause::Nogroup>()) ||
+    "NONTEMPORAL" >> construct<OmpClause>(construct<OmpClause::Nontemporal>(
+                         parenthesized(nonemptyList(name)))) ||
     "NOTINBRANCH" >>
         construct<OmpClause>(construct<OmpClause::Notinbranch>()) ||
     "NOWAIT" >> construct<OmpClause>(construct<OmpClause::Nowait>()) ||
index e1fc1ec..120f4db 100644 (file)
@@ -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 (file)
index 0000000..236c924
--- /dev/null
@@ -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 (file)
index 0000000..ea910be
--- /dev/null
@@ -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
index d5a6210..5ed279c 100644 (file)
@@ -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; }