r359200 - [OPENMP] Improved check for the linear dependency in the non-rectangular

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 25 09:21:13 PDT 2019


Author: abataev
Date: Thu Apr 25 09:21:13 2019
New Revision: 359200

URL: http://llvm.org/viewvc/llvm-project?rev=359200&view=rev
Log:
[OPENMP] Improved check for the linear dependency in the non-rectangular
loop nests.

Added a checks that the initializer/condition expressions depend only
only of the single previous loop iteration variable.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaOpenMP.cpp
    cfe/trunk/test/OpenMP/for_loop_messages.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=359200&r1=359199&r2=359200&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 25 09:21:13 2019
@@ -9172,6 +9172,8 @@ def err_omp_expected_private_copy_for_al
   "the referenced item is not found in any private clause on the same directive">;
 def err_omp_stmt_depends_on_loop_counter : Error<
   "the loop %select{initializer|condition}0 expression depends on the current loop control variable">;
+def err_omp_invariant_or_linear_dependancy : Error<
+  "expected loop invariant expression or '<invariant1> * %0 + <invariant2>' kind of expression">;
 } // end of OpenMP category
 
 let CategoryName = "Related Result Type Issue" in {

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=359200&r1=359199&r2=359200&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Thu Apr 25 09:21:13 2019
@@ -4715,6 +4715,7 @@ class LoopCounterRefChecker final
   Sema &SemaRef;
   DSAStackTy &Stack;
   const ValueDecl *CurLCDecl = nullptr;
+  const ValueDecl *DepDecl = nullptr;
   bool IsInitializer = true;
 
 public:
@@ -4728,6 +4729,18 @@ public:
         return false;
       }
       const auto &&Data = Stack.isLoopControlVariable(VD);
+      if (DepDecl && Data.first) {
+        SmallString<128> Name;
+        llvm::raw_svector_ostream OS(Name);
+        DepDecl->getNameForDiagnostic(OS, SemaRef.getPrintingPolicy(),
+                                      /*Qualified=*/true);
+        SemaRef.Diag(E->getExprLoc(),
+                     diag::err_omp_invariant_or_linear_dependancy)
+            << OS.str();
+        return false;
+      }
+      if (Data.first)
+        DepDecl = VD;
       return Data.first;
     }
     return false;
@@ -4742,16 +4755,27 @@ public:
         return false;
       }
       const auto &&Data = Stack.isLoopControlVariable(VD);
+      if (DepDecl && Data.first) {
+        SmallString<128> Name;
+        llvm::raw_svector_ostream OS(Name);
+        DepDecl->getNameForDiagnostic(OS, SemaRef.getPrintingPolicy(),
+                                      /*Qualified=*/true);
+        SemaRef.Diag(E->getExprLoc(),
+                     diag::err_omp_invariant_or_linear_dependancy)
+            << OS.str();
+        return false;
+      }
+      if (Data.first)
+        DepDecl = VD;
       return Data.first;
     }
     return false;
   }
   bool VisitStmt(const Stmt *S) {
-    for (const Stmt *Child : S->children()) {
-      if (Child && Visit(Child))
-        return true;
-    }
-    return false;
+    bool Res = true;
+    for (const Stmt *Child : S->children())
+      Res = Child && Visit(Child) && Res;
+    return Res;
   }
   explicit LoopCounterRefChecker(Sema &SemaRef, DSAStackTy &Stack,
                                  const ValueDecl *CurLCDecl, bool IsInitializer)

Modified: cfe/trunk/test/OpenMP/for_loop_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_loop_messages.cpp?rev=359200&r1=359199&r2=359200&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/for_loop_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/for_loop_messages.cpp Thu Apr 25 09:21:13 2019
@@ -293,6 +293,12 @@ int test_iteration_spaces() {
   for (ii = ii * 10 + 25; ii < ii / ii - 23; ii += 1)
     c[ii] = a[ii];
 
+// expected-error at +3 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}}
+#pragma omp for collapse(2)
+    for (ii = 10 + 25; ii < 1000; ii += 1)
+      for (kk = ii * 10 + 25; kk < ii / ii - 23; kk += 1)
+        ;
+
 #pragma omp parallel
 // expected-note at +2  {{defined as firstprivate}}
 // expected-error at +2 {{loop iteration variable in the associated loop of 'omp for' directive may not be firstprivate, predetermined as private}}
@@ -603,7 +609,7 @@ int test_with_random_access_iterator() {
 
 template <typename IT, int ST>
 class TC {
-  int ii;
+  int ii, iii;
 public:
   int dotest_lt(IT begin, IT end) {
 #pragma omp parallel
@@ -614,6 +620,14 @@ public:
     ;
 
 #pragma omp parallel
+// expected-error at +4 2 {{expected loop invariant expression or '<invariant1> * ii + <invariant2>' kind of expression}}
+// expected-error at +3 {{expected loop invariant expression or '<invariant1> * TC::ii + <invariant2>' kind of expression}}
+#pragma omp for collapse(2)
+    for (ii = 10 + 25; ii < 1000; ii += 1)
+      for (iii = ii * 10 + 25; iii < ii / ii - 23; iii += 1)
+        ;
+
+#pragma omp parallel
 // expected-note at +3 {{loop step is expected to be positive due to this condition}}
 // expected-error at +2 {{increment expression must cause 'I' to increase on each iteration of OpenMP for loop}}
 #pragma omp for




More information about the cfe-commits mailing list