[clang] ad49765 - [OpenMP] Allow const parameters in declare simd linear clause

Graham Hunter via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 2 06:54:54 PST 2020


Author: Graham Hunter
Date: 2020-03-02T14:54:14Z
New Revision: ad497658d25a3616e4c57cf7d12e3497a1c66f35

URL: https://github.com/llvm/llvm-project/commit/ad497658d25a3616e4c57cf7d12e3497a1c66f35
DIFF: https://github.com/llvm/llvm-project/commit/ad497658d25a3616e4c57cf7d12e3497a1c66f35.diff

LOG: [OpenMP] Allow const parameters in declare simd linear clause

Reviewers: ABataev, kkwli0, jdoerfert, fpetrogalli

Reviewed By: ABataev, fpetrogalli

Differential Revision: https://reviews.llvm.org/D75350

Added: 
    

Modified: 
    clang/include/clang/Sema/Sema.h
    clang/lib/Sema/SemaOpenMP.cpp
    clang/test/OpenMP/declare_simd_aarch64.c
    clang/test/OpenMP/declare_simd_codegen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 2d7676e23cfc..f1dfe411983a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -10173,7 +10173,8 @@ class Sema final {
   /// Checks that the specified declaration matches requirements for the linear
   /// decls.
   bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
-                             OpenMPLinearClauseKind LinKind, QualType Type);
+                             OpenMPLinearClauseKind LinKind, QualType Type,
+                             bool IsDeclareSimd = false);
 
   /// Called on well-formed '\#pragma omp declare simd' after parsing of
   /// the associated method/function.

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6aaf70918d02..de732577c81b 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5269,7 +5269,8 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective(
               E->containsUnexpandedParameterPack())
             continue;
           (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind,
-                                      PVD->getOriginalType());
+                                      PVD->getOriginalType(),
+                                      /*IsDeclareSimd=*/true);
           continue;
         }
       }
@@ -5289,7 +5290,7 @@ Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective(
           E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
         continue;
       (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind,
-                                  E->getType());
+                                  E->getType(), /*IsDeclareSimd=*/true);
       continue;
     }
     Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause)
@@ -14547,8 +14548,8 @@ bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind,
 }
 
 bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
-                                 OpenMPLinearClauseKind LinKind,
-                                 QualType Type) {
+                                 OpenMPLinearClauseKind LinKind, QualType Type,
+                                 bool IsDeclareSimd) {
   const auto *VD = dyn_cast_or_null<VarDecl>(D);
   // A variable must not have an incomplete type or a reference type.
   if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type))
@@ -14564,8 +14565,10 @@ bool Sema::CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc,
   // OpenMP 5.0 [2.19.3, List Item Privatization, Restrictions]
   // A variable that is privatized must not have a const-qualified type
   // unless it is of class type with a mutable member. This restriction does
-  // not apply to the firstprivate clause.
-  if (rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
+  // not apply to the firstprivate clause, nor to the linear clause on
+  // declarative directives (like declare simd).
+  if (!IsDeclareSimd &&
+      rejectConstNotMutableType(*this, D, Type, OMPC_linear, ELoc))
     return true;
 
   // A list item must be of integral or pointer type.

diff  --git a/clang/test/OpenMP/declare_simd_aarch64.c b/clang/test/OpenMP/declare_simd_aarch64.c
index eff0eed07dfe..4af2ad9bb603 100644
--- a/clang/test/OpenMP/declare_simd_aarch64.c
+++ b/clang/test/OpenMP/declare_simd_aarch64.c
@@ -116,6 +116,15 @@ double c02(double *x, char y);
 // AARCH64: "_ZGVnM16uv_c02" "_ZGVnM8uv_c02"
 // AARCH64-NOT: c02
 
+/************************************/
+/* Linear with a constant parameter */
+/************************************/
+
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i);
+// AARCH64: "_ZGVnN2l_constlinear" "_ZGVnN4l_constlinear"
+// AARCH64-NOT: constlinear
+
 /*************************/
 /* sincos-like signature */
 /*************************/
@@ -170,6 +179,7 @@ void do_something() {
   D = b03(D);
   *I = c01(D, *S);
   *D = c02(D, *S);
+  constlinear(*I);
   sincos(*D, D, D);
   SinCos(*D, D, D);
   foo2(I, *I);

diff  --git a/clang/test/OpenMP/declare_simd_codegen.cpp b/clang/test/OpenMP/declare_simd_codegen.cpp
index 4ac0b7f03a0e..ef7ad8772e51 100644
--- a/clang/test/OpenMP/declare_simd_codegen.cpp
+++ b/clang/test/OpenMP/declare_simd_codegen.cpp
@@ -114,6 +114,9 @@ float foo(float *q, float x, int k) { return 0; }
 #pragma omp declare simd notinbranch
 double foo(double x) { return 0; }
 
+#pragma omp declare simd notinbranch linear(i)
+double constlinear(const int i) { return 0.0; }
+
 // CHECK-DAG: define {{.+}}@_Z5add_1Pf(
 // CHECK-DAG: define {{.+}}@_Z1hIiEvPT_S1_S1_S1_(
 // CHECK-DAG: define {{.+}}@_Z1hIfEvPT_S1_S1_S1_(
@@ -131,6 +134,7 @@ double foo(double x) { return 0; }
 // CHECK-DAG: define {{.+}}@_Z3fooPffi(
 // CHECK-DAG: define {{.+}}@_Z3food(
 // CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
+// CHECK-DAG: define {{.+}}@_Z11constlineari(
 
 // CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf"
@@ -320,6 +324,11 @@ double foo(double x) { return 0; }
 // CHECK-DAG: "_ZGVdN4v__Z3food"
 // CHECK-DAG: "_ZGVeN8v__Z3food"
 
+// CHECK-DAG: "_ZGVbN2l__Z11constlineari"
+// CHECK-DAG: "_ZGVcN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVdN4l__Z11constlineari"
+// CHECK-DAG: "_ZGVeN8l__Z11constlineari"
+
 // CHECK-NOT: "_ZGV{{.+}}__Z1fRA_i
 
 #endif


        


More information about the cfe-commits mailing list