[clang] 7585ba2 - [clang][OpenMP] Fix mangling of linear parameters.

Francesco Petrogalli via cfe-commits cfe-commits at lists.llvm.org
Fri May 1 14:20:03 PDT 2020


Author: Francesco Petrogalli
Date: 2020-05-01T21:19:00Z
New Revision: 7585ba208e67443d0fbc883db320934c65312b02

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

LOG: [clang][OpenMP] Fix mangling of linear parameters.

Summary:
The linear parameter token in the mangling function must be multiplied
by the pointee size in bytes when the parameter is a pointer.

Reviewers: ABataev, andwar, jdoerfert

Subscribers: yaxunl, guansong, cfe-commits

Tags: #clang

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

Added: 
    

Modified: 
    clang/lib/CodeGen/CGOpenMPRuntime.cpp
    clang/test/OpenMP/declare_simd_aarch64.c
    clang/test/OpenMP/declare_simd_codegen.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 307750ccfec9..6a69d02fa817 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -11073,7 +11073,7 @@ emitX86DeclareSimdFunction(const FunctionDecl *FD, llvm::Function *Fn,
           break;
         case Linear:
           Out << 'l';
-          if (!!ParamAttr.StrideOrArg)
+          if (ParamAttr.StrideOrArg != 1)
             Out << ParamAttr.StrideOrArg;
           break;
         case Uniform:
@@ -11213,7 +11213,7 @@ static std::string mangleVectorParameters(ArrayRef<ParamAttrTy> ParamAttrs) {
       Out << 'l';
       // Don't print the step value if it is not present or if it is
       // equal to 1.
-      if (!!ParamAttr.StrideOrArg && ParamAttr.StrideOrArg != 1)
+      if (ParamAttr.StrideOrArg != 1)
         Out << ParamAttr.StrideOrArg;
       break;
     case Uniform:
@@ -11451,15 +11451,24 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
       for (const Expr *E : Attr->linears()) {
         E = E->IgnoreParenImpCasts();
         unsigned Pos;
+        // Rescaling factor needed to compute the linear parameter
+        // value in the mangled name.
+        unsigned PtrRescalingFactor = 1;
         if (isa<CXXThisExpr>(E)) {
           Pos = ParamPositions[FD];
         } else {
           const auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl())
                                 ->getCanonicalDecl();
           Pos = ParamPositions[PVD];
+          if (auto *P = dyn_cast<PointerType>(PVD->getType()))
+            PtrRescalingFactor = CGM.getContext()
+                                     .getTypeSizeInChars(P->getPointeeType())
+                                     .getQuantity();
         }
         ParamAttrTy &ParamAttr = ParamAttrs[Pos];
         ParamAttr.Kind = Linear;
+        // Assuming a stride of 1, for `linear` without modifiers.
+        ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned(1);
         if (*SI) {
           Expr::EvalResult Result;
           if (!(*SI)->EvaluateAsInt(Result, C, Expr::SE_AllowSideEffects)) {
@@ -11475,6 +11484,11 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD,
             ParamAttr.StrideOrArg = Result.Val.getInt();
           }
         }
+        // If we are using a linear clause on a pointer, we need to
+        // rescale the value of linear_step with the byte size of the
+        // pointee type.
+        if (Linear == ParamAttr.Kind)
+          ParamAttr.StrideOrArg = ParamAttr.StrideOrArg * PtrRescalingFactor;
         ++SI;
         ++MI;
       }

diff  --git a/clang/test/OpenMP/declare_simd_aarch64.c b/clang/test/OpenMP/declare_simd_aarch64.c
index 4af2ad9bb603..21c83c225963 100644
--- a/clang/test/OpenMP/declare_simd_aarch64.c
+++ b/clang/test/OpenMP/declare_simd_aarch64.c
@@ -130,12 +130,12 @@ double constlinear(const int i);
 /*************************/
 #pragma omp declare simd linear(sin) linear(cos)
 void sincos(double in, double *sin, double *cos);
-// AARCH64: "_ZGVnN2vll_sincos"
+// AARCH64: "_ZGVnN2vl8l8_sincos"
 // AARCH64-NOT: sincos
 
 #pragma omp declare simd linear(sin : 1) linear(cos : 2)
 void SinCos(double in, double *sin, double *cos);
-// AARCH64: "_ZGVnN2vll2_SinCos"
+// AARCH64: "_ZGVnN2vl8l16_SinCos"
 // AARCH64-NOT: SinCos
 
 // Selection of tests based on the examples provided in chapter 5 of
@@ -158,7 +158,7 @@ int foo3(int *x, int i, unsigned char c);
 // Listing 6, p. 19
 #pragma omp declare simd linear(x) aligned(x : 16) simdlen(4)
 int foo4(int *x, float y);
-// AARCH64: "_ZGVnM4la16v_foo4" "_ZGVnN4la16v_foo4"
+// AARCH64: "_ZGVnM4l4a16v_foo4" "_ZGVnN4l4a16v_foo4"
 // AARCH64-NOT: foo4
 
 static int *I;

diff  --git a/clang/test/OpenMP/declare_simd_codegen.cpp b/clang/test/OpenMP/declare_simd_codegen.cpp
index ef7ad8772e51..1967f3b248dc 100644
--- a/clang/test/OpenMP/declare_simd_codegen.cpp
+++ b/clang/test/OpenMP/declare_simd_codegen.cpp
@@ -136,14 +136,14 @@ double constlinear(const int i) { return 0.0; }
 // CHECK-DAG: declare {{.+}}@_Z5add_2Pf(
 // CHECK-DAG: define {{.+}}@_Z11constlineari(
 
-// CHECK-DAG: "_ZGVbM4l8__Z5add_1Pf"
-// CHECK-DAG: "_ZGVbN4l8__Z5add_1Pf"
-// CHECK-DAG: "_ZGVcM8l8__Z5add_1Pf"
-// CHECK-DAG: "_ZGVcN8l8__Z5add_1Pf"
-// CHECK-DAG: "_ZGVdM8l8__Z5add_1Pf"
-// CHECK-DAG: "_ZGVdN8l8__Z5add_1Pf"
-// CHECK-DAG: "_ZGVeM16l8__Z5add_1Pf"
-// CHECK-DAG: "_ZGVeN16l8__Z5add_1Pf"
+// CHECK-DAG: "_ZGVbM4l32__Z5add_1Pf"
+// CHECK-DAG: "_ZGVbN4l32__Z5add_1Pf"
+// CHECK-DAG: "_ZGVcM8l32__Z5add_1Pf"
+// CHECK-DAG: "_ZGVcN8l32__Z5add_1Pf"
+// CHECK-DAG: "_ZGVdM8l32__Z5add_1Pf"
+// CHECK-DAG: "_ZGVdN8l32__Z5add_1Pf"
+// CHECK-DAG: "_ZGVeM16l32__Z5add_1Pf"
+// CHECK-DAG: "_ZGVeN16l32__Z5add_1Pf"
 // CHECK-DAG: "_ZGVbM32v__Z5add_1Pf"
 // CHECK-DAG: "_ZGVcM32v__Z5add_1Pf"
 // CHECK-DAG: "_ZGVdM32v__Z5add_1Pf"
@@ -180,14 +180,14 @@ double constlinear(const int i) { return 0.0; }
 // CHECK-DAG: "_ZGVeM16uus1__ZN2VV3addEii"
 // CHECK-DAG: "_ZGVeN16uus1__ZN2VV3addEii"
 
-// CHECK-DAG: "_ZGVbM4lla16l4a4__ZN2VV6taddpfEPfRS0_"
-// CHECK-DAG: "_ZGVbN4lla16l4a4__ZN2VV6taddpfEPfRS0_"
-// CHECK-DAG: "_ZGVcM8lla16l4a4__ZN2VV6taddpfEPfRS0_"
-// CHECK-DAG: "_ZGVcN8lla16l4a4__ZN2VV6taddpfEPfRS0_"
-// CHECK-DAG: "_ZGVdM8lla16l4a4__ZN2VV6taddpfEPfRS0_"
-// CHECK-DAG: "_ZGVdN8lla16l4a4__ZN2VV6taddpfEPfRS0_"
-// CHECK-DAG: "_ZGVeM16lla16l4a4__ZN2VV6taddpfEPfRS0_"
-// CHECK-DAG: "_ZGVeN16lla16l4a4__ZN2VV6taddpfEPfRS0_"
+// CHECK-DAG: "_ZGVbM4ll4a16l4a4__ZN2VV6taddpfEPfRS0_"
+// CHECK-DAG: "_ZGVbN4ll4a16l4a4__ZN2VV6taddpfEPfRS0_"
+// CHECK-DAG: "_ZGVcM8ll4a16l4a4__ZN2VV6taddpfEPfRS0_"
+// CHECK-DAG: "_ZGVcN8ll4a16l4a4__ZN2VV6taddpfEPfRS0_"
+// CHECK-DAG: "_ZGVdM8ll4a16l4a4__ZN2VV6taddpfEPfRS0_"
+// CHECK-DAG: "_ZGVdN8ll4a16l4a4__ZN2VV6taddpfEPfRS0_"
+// CHECK-DAG: "_ZGVeM16ll4a16l4a4__ZN2VV6taddpfEPfRS0_"
+// CHECK-DAG: "_ZGVeN16ll4a16l4a4__ZN2VV6taddpfEPfRS0_"
 
 // CHECK-DAG: "_ZGVbM4vvl8__ZN2VV4taddERA_iRi"
 // CHECK-DAG: "_ZGVbN4vvl8__ZN2VV4taddERA_iRi"
@@ -293,23 +293,23 @@ double constlinear(const int i) { return 0.0; }
 // CHECK-DAG: "_ZGVeM16vvv__Z3bax2VVPdi"
 // CHECK-DAG: "_ZGVeN16vvv__Z3bax2VVPdi"
 
-// CHECK-DAG: "_ZGVbM4ua16vl1__Z3fooPffi"
-// CHECK-DAG: "_ZGVbN4ua16vl1__Z3fooPffi"
-// CHECK-DAG: "_ZGVcM8ua16vl1__Z3fooPffi"
-// CHECK-DAG: "_ZGVcN8ua16vl1__Z3fooPffi"
-// CHECK-DAG: "_ZGVdM8ua16vl1__Z3fooPffi"
-// CHECK-DAG: "_ZGVdN8ua16vl1__Z3fooPffi"
-// CHECK-DAG: "_ZGVeM16ua16vl1__Z3fooPffi"
-// CHECK-DAG: "_ZGVeN16ua16vl1__Z3fooPffi"
-
-// CHECK-DAG: "_ZGVbM4l8__Z5add_2Pf"
-// CHECK-DAG: "_ZGVbN4l8__Z5add_2Pf"
-// CHECK-DAG: "_ZGVcM8l8__Z5add_2Pf"
-// CHECK-DAG: "_ZGVcN8l8__Z5add_2Pf"
-// CHECK-DAG: "_ZGVdM8l8__Z5add_2Pf"
-// CHECK-DAG: "_ZGVdN8l8__Z5add_2Pf"
-// CHECK-DAG: "_ZGVeM16l8__Z5add_2Pf"
-// CHECK-DAG: "_ZGVeN16l8__Z5add_2Pf"
+// CHECK-DAG: "_ZGVbM4ua16vl__Z3fooPffi"
+// CHECK-DAG: "_ZGVbN4ua16vl__Z3fooPffi"
+// CHECK-DAG: "_ZGVcM8ua16vl__Z3fooPffi"
+// CHECK-DAG: "_ZGVcN8ua16vl__Z3fooPffi"
+// CHECK-DAG: "_ZGVdM8ua16vl__Z3fooPffi"
+// CHECK-DAG: "_ZGVdN8ua16vl__Z3fooPffi"
+// CHECK-DAG: "_ZGVeM16ua16vl__Z3fooPffi"
+// CHECK-DAG: "_ZGVeN16ua16vl__Z3fooPffi"
+
+// CHECK-DAG: "_ZGVbM4l32__Z5add_2Pf"
+// CHECK-DAG: "_ZGVbN4l32__Z5add_2Pf"
+// CHECK-DAG: "_ZGVcM8l32__Z5add_2Pf"
+// CHECK-DAG: "_ZGVcN8l32__Z5add_2Pf"
+// CHECK-DAG: "_ZGVdM8l32__Z5add_2Pf"
+// CHECK-DAG: "_ZGVdN8l32__Z5add_2Pf"
+// CHECK-DAG: "_ZGVeM16l32__Z5add_2Pf"
+// CHECK-DAG: "_ZGVeN16l32__Z5add_2Pf"
 // CHECK-DAG: "_ZGVbM32v__Z5add_2Pf"
 // CHECK-DAG: "_ZGVcM32v__Z5add_2Pf"
 // CHECK-DAG: "_ZGVdM32v__Z5add_2Pf"


        


More information about the cfe-commits mailing list