]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fixed codegen for parameters privatization.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 21 May 2015 09:47:46 +0000 (09:47 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 21 May 2015 09:47:46 +0000 (09:47 +0000)
For parameters we shall take a derived type of parameters, not the original one.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@237882 91177308-0d34-0410-b5e6-96231b3b80d8

13 files changed:
lib/CodeGen/CGOpenMPRuntime.cpp
lib/CodeGen/CGStmtOpenMP.cpp
lib/Sema/SemaOpenMP.cpp
test/OpenMP/for_firstprivate_messages.cpp
test/OpenMP/for_lastprivate_messages.cpp
test/OpenMP/for_private_messages.cpp
test/OpenMP/parallel_firstprivate_codegen.cpp
test/OpenMP/single_codegen.cpp
test/OpenMP/single_copyprivate_messages.cpp
test/OpenMP/task_firstprivate_codegen.cpp
test/OpenMP/task_firstprivate_messages.cpp
test/OpenMP/task_private_codegen.cpp
test/OpenMP/task_private_messages.cpp

index a8665254545fdf428e420f74cbe343f6027e8e75..789302c88555fbcdf5f0cf4a8e50617cb0981e97 100644 (file)
@@ -1289,9 +1289,6 @@ static llvm::Value *emitCopyprivateCopyFunction(
         CGF.ConvertTypeForMem(C.getPointerType(SrcExprs[I]->getType())));
     auto *VD = cast<DeclRefExpr>(CopyprivateVars[I])->getDecl();
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     CGF.EmitOMPCopy(CGF, Type, DestAddr, SrcAddr,
                     cast<VarDecl>(cast<DeclRefExpr>(DestExprs[I])->getDecl()),
                     cast<VarDecl>(cast<DeclRefExpr>(SrcExprs[I])->getDecl()),
@@ -1671,9 +1668,6 @@ createPrivatesRecordDecl(CodeGenModule &CGM,
     RD->startDefinition();
     for (auto &&Pair : Privates) {
       auto Type = Pair.second.Original->getType();
-      if (auto *PVD = dyn_cast<ParmVarDecl>(Pair.second.Original)) {
-        Type = PVD->getOriginalType();
-      }
       Type = Type.getNonReferenceType();
       addFieldToRecordDecl(C, RD, Type);
     }
@@ -1960,9 +1954,6 @@ void CGOpenMPRuntime::emitTaskCall(
           auto SharedRefLValue =
               CGF.EmitLValueForField(SharedsBase, SharedField);
           QualType Type = OriginalVD->getType();
-          if (auto *PVD = dyn_cast<ParmVarDecl>(OriginalVD)) {
-            Type = PVD->getOriginalType();
-          }
           if (Type->isArrayType()) {
             // Initialize firstprivate array.
             if (!isa<CXXConstructExpr>(Init) ||
index 4a4c06f7e1c1c7db74e495a9e5958f3b5ac45569..78412e47345624951ad56b6ce63c1bdbbf23fed6 100644 (file)
@@ -133,9 +133,6 @@ bool CodeGenFunction::EmitOMPFirstprivateClause(const OMPExecutableDirective &D,
             (*IRef)->getType(), VK_LValue, (*IRef)->getExprLoc());
         auto *OriginalAddr = EmitLValue(&DRE).getAddress();
         QualType Type = OrigVD->getType();
-        if (auto *PVD = dyn_cast<ParmVarDecl>(OrigVD)) {
-          Type = PVD->getOriginalType();
-        }
         if (Type->isArrayType()) {
           // Emit VarDecl with copy init for arrays.
           // Get the address of the original variable captured in current
@@ -229,9 +226,6 @@ bool CodeGenFunction::EmitOMPCopyinClause(const OMPExecutableDirective &D) {
     for (auto *AssignOp : C->assignment_ops()) {
       auto *VD = cast<VarDecl>(cast<DeclRefExpr>(*IRef)->getDecl());
       QualType Type = VD->getType();
-      if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-        Type = PVD->getOriginalType();
-      }
       if (CopiedVars.insert(VD->getCanonicalDecl()).second) {
         // Get the address of the master variable.
         auto *MasterAddr = VD->isStaticLocal()
@@ -355,9 +349,6 @@ void CodeGenFunction::EmitOMPLastprivateClauseFinal(
       for (auto *AssignOp : C->assignment_ops()) {
         auto *PrivateVD = cast<VarDecl>(cast<DeclRefExpr>(*IRef)->getDecl());
         QualType Type = PrivateVD->getType();
-        if (auto *PVD = dyn_cast<ParmVarDecl>(PrivateVD)) {
-          Type = PVD->getOriginalType();
-        }
         auto *CanonicalVD = PrivateVD->getCanonicalDecl();
         if (AlreadyEmittedVars.insert(CanonicalVD).second) {
           // If lastprivate variable is a loop control variable for loop-based
index c7d0c148ba0e48384df500e6d333201926bf76fa..ee6bdb21e55270cb0ce19a71f607dde7d3ef6426 100644 (file)
@@ -505,9 +505,6 @@ DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) {
   }
 
   QualType Type = D->getType().getNonReferenceType().getCanonicalType();
-  if (auto *PVD = dyn_cast<ParmVarDecl>(D)) {
-    Type = PVD->getOriginalType().getNonReferenceType().getCanonicalType();
-  }
   bool IsConstant = Type.isConstant(SemaRef.getASTContext());
   Type = SemaRef.getASTContext().getBaseElementType(Type);
   // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
@@ -664,9 +661,6 @@ void Sema::EndOpenMPDSABlock(Stmt *CurDirective) {
           }
           auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl());
           QualType Type = VD->getType();
-          if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-            Type = PVD->getOriginalType();
-          }
           auto DVar = DSAStack->getTopDSA(VD, false);
           if (DVar.CKind == OMPC_lastprivate) {
             // Generate helper private variable and initialize it with the
@@ -4761,9 +4755,6 @@ OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -4805,7 +4796,7 @@ OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
     }
 
     // Variably modified types are not supported for tasks.
-    if (Type->isVariablyModifiedType() &&
+    if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() &&
         DSAStack->getCurrentDirective() == OMPD_task) {
       Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
           << getOpenMPClauseName(OMPC_private) << Type
@@ -4907,9 +4898,6 @@ OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -5036,7 +5024,7 @@ OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
     }
 
     // Variably modified types are not supported for tasks.
-    if (Type->isVariablyModifiedType() &&
+    if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() &&
         DSAStack->getCurrentDirective() == OMPD_task) {
       Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
           << getOpenMPClauseName(OMPC_firstprivate) << Type
@@ -5143,9 +5131,6 @@ OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList,
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -5280,9 +5265,6 @@ OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -5492,9 +5474,6 @@ OMPClause *Sema::ActOnOpenMPReductionClause(
     auto D = DE->getDecl();
     auto VD = cast<VarDecl>(D);
     auto Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     // OpenMP [2.9.3.3, Restrictions, C/C++, p.3]
     //  A variable that appears in a private clause must not have an incomplete
     //  type or a reference type.
@@ -5825,9 +5804,6 @@ OMPClause *Sema::ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
     }
 
     QualType QType = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      QType = PVD->getOriginalType();
-    }
     if (QType->isDependentType() || QType->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -6008,9 +5984,6 @@ OMPClause *Sema::ActOnOpenMPAlignedClause(
     // The type of list items appearing in the aligned clause must be
     // array, pointer, reference to array, or reference to pointer.
     QualType QType = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      QType = PVD->getOriginalType();
-    }
     QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType();
     const Type *Ty = QType.getTypePtrOrNull();
     if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() &&
@@ -6090,9 +6063,6 @@ OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList,
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -6183,9 +6153,6 @@ OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList,
     VarDecl *VD = cast<VarDecl>(D);
 
     QualType Type = VD->getType();
-    if (auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
-      Type = PVD->getOriginalType();
-    }
     if (Type->isDependentType() || Type->isInstantiationDependentType()) {
       // It will be analyzed later.
       Vars.push_back(DE);
@@ -6225,7 +6192,7 @@ OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList,
     }
 
     // Variably modified types are not supported.
-    if (Type->isVariablyModifiedType()) {
+    if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) {
       Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
           << getOpenMPClauseName(OMPC_copyprivate) << Type
           << getOpenMPDirectiveName(DSAStack->getCurrentDirective());
index f22a33eee9b7cd0ace4043a6615998cd07aed2a7..2ec81104e77164439d687c2aad1d2dc648847c18 100644 (file)
@@ -35,7 +35,7 @@ extern const int f;
 class S4 {
   int a;
   S4();
-  S4(const S4 &s4); // expected-note 3 {{implicitly declared private here}}
+  S4(const S4 &s4); // expected-note 2 {{implicitly declared private here}}
 
 public:
   S4(int v) : a(v) {}
@@ -154,7 +154,7 @@ int foomain(int argc, char **argv) {
 
 void bar(S4 a[2]) {
 #pragma omp parallel
-#pragma omp for firstprivate(a) // expected-error {{calling a private constructor of class 'S4'}}
+#pragma omp for firstprivate(a)
   for (int i = 0; i < 2; ++i)
     foo();
 }
index c3551e2fbab23747f735100ab3214f53b759774c..2fa14b63bd115b8d866d0f4e8b77100b161b6d36 100644 (file)
@@ -36,7 +36,7 @@ const S3 ca[5];     // expected-note {{global variable is predetermined as share
 extern const int f; // expected-note {{global variable is predetermined as shared}}
 class S4 {
   int a;
-  S4();             // expected-note 4 {{implicitly declared private here}}
+  S4();             // expected-note 3 {{implicitly declared private here}}
   S4(const S4 &s4);
 
 public:
@@ -144,7 +144,7 @@ int foomain(int argc, char **argv) {
 
 void bar(S4 a[2]) {
 #pragma omp parallel
-#pragma omp for lastprivate(a) // expected-error {{calling a private constructor of class 'S4'}}
+#pragma omp for lastprivate(a)
   for (int i = 0; i < 2; ++i)
     foo();
 }
index 3ea0e5460f24b37ca43c6ad8f439be2fd5ba0e7f..225a1beb99ea4c38ceeeb4ef2039feccf89596f5 100644 (file)
@@ -26,7 +26,7 @@ public:
 const S3 ca[5];
 class S4 {
   int a;
-  S4(); // expected-note {{implicitly declared private here}}
+  S4(); // expected-note {{implicitly declared private here}}
 
 public:
   S4(int v) : a(v) {}
@@ -110,7 +110,7 @@ int foomain(I argc, C **argv) {
 
 void bar(S4 a[2]) {
 #pragma omp parallel
-#pragma omp for private(a) // expected-error {{calling a private constructor of class 'S4'}}
+#pragma omp for private(a)
   for (int i = 0; i < 2; ++i)
     foo();
 }
index 00918f67ef65f665a61969e0712d57ef2d2f2cf7..3f61362a3d976e4c2215b2c40be2b0863c8d3259 100644 (file)
@@ -250,19 +250,19 @@ struct St {
   ~St() {}
 };
 
-void array_func(int a[3], St s[2], int n, long double vla1[n]) {
+void array_func(float a[3], St s[2], int n, long double vla1[n]) {
   double vla2[n];
 // ARRAY: @__kmpc_fork_call(
-// ARRAY: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.+}}, i8* %{{.+}}, i64 12, i32 4, i1 false)
-// ARRAY: call void @_ZN2StC1ERKS_(%struct.St* %{{.+}}, %struct.St* dereferenceable(8) %{{.+}}
+// ARRAY: [[PRIV_A:%.+]] = alloca float*
+// ARRAY: [[PRIV_S:%.+]] = alloca %struct.St*
+// ARRAY: [[PRIV_VLA1:%.+]] = alloca x86_fp80*
+// ARRAY: store float* %{{.+}}, float** [[PRIV_A]],
+// ARRAY: store %struct.St* %{{.+}}, %struct.St** [[PRIV_S]],
+// ARRAY: store x86_fp80* %{{.+}}, x86_fp80** [[PRIV_VLA1]],
 // ARRAY: call i8* @llvm.stacksave()
-// ARRAY: [[SIZE:%.+]] = mul nuw i64 %{{.+}}, 16
-// ARRAY: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.+}}, i8* %{{.+}}, i64 [[SIZE]], i32 16, i1 false)
 // ARRAY: [[SIZE:%.+]] = mul nuw i64 %{{.+}}, 8
 // ARRAY: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.+}}, i8* %{{.+}}, i64 [[SIZE]], i32 8, i1 false)
 // ARRAY: call void @llvm.stackrestore(i8*
-// ARRAY: call void @_ZN2StD1Ev(%struct.St* %{{.+}})
-// ARRAY: br i1
 #pragma omp parallel firstprivate(a, s, vla1, vla2)
   ;
 }
index d3ad969b37ffa435209d2974a78cdb52e719bbbf..0593b2aa75135b0abd1663d92f206f4f1f7dfdf2 100644 (file)
@@ -178,12 +178,12 @@ struct St {
   ~St() {}
 };
 
-void array_func(int a[3], St s[2]) {
+void array_func(int n, int a[n], St s[2]) {
 // ARRAY: call void @__kmpc_copyprivate(%ident_t* @{{.+}}, i32 %{{.+}}, i64 16, i8* %{{.+}}, void (i8*, i8*)* [[CPY:@.+]], i32 %{{.+}})
 #pragma omp single copyprivate(a, s)
   ;
 }
 // ARRAY: define internal void [[CPY]]
-// ARRAY: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.+}}, i8* %{{.+}}, i64 12, i32 4, i1 false)
-// ARRAY: call dereferenceable(8) %struct.St* @_ZN2StaSERKS_(%struct.St* %{{.+}}, %struct.St* dereferenceable(8) %{{.+}})
+// ARRAY: store i32* %{{.+}}, i32** %{{.+}},
+// ARRAY: store %struct.St* %{{.+}}, %struct.St** %{{.+}},
 #endif
index 0995eb07b9983c9d0660c16b454ee61781c52842..4714753f494e07a4ecbad03caa58e8acd0e0f890 100644 (file)
@@ -21,7 +21,7 @@ public:
 class S4 {
   int a;
   S4();
-  S4 &operator=(const S4 &s4); // expected-note 4 {{implicitly declared private here}}
+  S4 &operator=(const S4 &s4); // expected-note 3 {{implicitly declared private here}}
 
 public:
   S4(int v) : a(v) {}
@@ -105,8 +105,8 @@ T tmain(T argc, C **argv) {
   return T();
 }
 
-void bar(S4 a[2], int n, int b[n]) { // expected-note {{'b' defined here}}
-#pragma omp single copyprivate(a, b) // expected-error {{'operator=' is a private member of 'S4'}} expected-error {{arguments of OpenMP clause 'copyprivate' in '#pragma omp single' directive cannot be of variably-modified type 'int [n]'}}
+void bar(S4 a[2], int n, int b[n]) {
+#pragma omp single copyprivate(a, b)
     foo();
 }
 
index a5eb20cf4603875f9c9bf72ca092db04d6d5a2a5..449be6815af2296387fc3ffe0145bf36b78a0ab2 100644 (file)
@@ -408,15 +408,11 @@ struct St {
   ~St() {}
 };
 
-void array_func(int a[3], St s[2]) {
+void array_func(int n, float a[n], St s[2]) {
 // ARRAY: call i8* @__kmpc_omp_task_alloc(
-// ARRAY: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.+}}, i8* %{{.+}}, i64 12, i32 4, i1 false)
-// ARRAY: call void @_ZN2StC1ERKS_(%struct.St* %{{.+}}, %struct.St* dereferenceable(8) %{{.+}})
-// ARRAY: store i32 (i32, i8*)* bitcast (i32 (i32, %{{[^*]+}}*)* [[DESTRUCTORS:@.+]] to i32 (i32, i8*)*), i32 (i32, i8*)** %{{.+}},
+// ARRAY: store float** %{{.+}}, float*** %{{.+}},
+// ARRAY: store %struct.St** %{{.+}}, %struct.St*** %{{.+}},
 // ARRAY: call i32 @__kmpc_omp_task(
-// ARRAY: define internal i32 [[DESTRUCTORS]](i32,
-// ARRAY: call void @_ZN2StD1Ev(%struct.St* %{{.+}})
-// ARRAY: br i1
 #pragma omp task firstprivate(a, s)
   ;
 }
index 6052ac588b92c6b101444654fdcd24aff5cf8f30..0126d47c50f97fee9b79ebcce5ab663d69642772 100644 (file)
@@ -51,8 +51,8 @@ public:
 S3 h;
 #pragma omp threadprivate(h) // expected-note {{defined as threadprivate or thread local}}
 
-void bar(int n, int b[n]) { // expected-note {{'b' defined here}}
-#pragma omp task firstprivate(b) // expected-error {{arguments of OpenMP clause 'firstprivate' in '#pragma omp task' directive cannot be of variably-modified type 'int [n]'}}
+void bar(int n, int b[n]) {
+#pragma omp task firstprivate(b)
     foo();
 }
 
index b97b2f7d9063a2007fde33716f1d88209427681c..e6f11d3e85abaea29c787aab919d9b11b04574c6 100644 (file)
@@ -371,15 +371,11 @@ struct St {
   ~St() {}
 };
 
-void array_func(int a[2], St s[2]) {
+void array_func(int n, float a[n], St s[2]) {
 // ARRAY: call i8* @__kmpc_omp_task_alloc(
-// ARRAY-NOT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.+}}, i8* %{{.+}}, i64 12, i32 4, i1 false)
-// ARRAY: call void @_ZN2StC1Ev(%struct.St* %{{.+}})
-// ARRAY: store i32 (i32, i8*)* bitcast (i32 (i32, %{{[^*]+}}*)* [[DESTRUCTORS:@.+]] to i32 (i32, i8*)*), i32 (i32, i8*)** %{{.+}},
+// ARRAY: store float** %{{.+}}, float*** %{{.+}},
+// ARRAY: store %struct.St** %{{.+}}, %struct.St*** %{{.+}},
 // ARRAY: call i32 @__kmpc_omp_task(
-// ARRAY: define internal i32 [[DESTRUCTORS]](i32,
-// ARRAY: call void @_ZN2StD1Ev(%struct.St* %{{.+}})
-// ARRAY: br i1
 #pragma omp task private(a, s)
   ;
 }
index 34f647b0c5328f41f157716fd6d73ef80e67576d..c2c1f519d0c15af89da2ccd10cb1ffd316c64156 100644 (file)
@@ -45,8 +45,8 @@ public:
 int threadvar;
 #pragma omp threadprivate(threadvar) // expected-note {{defined as threadprivate or thread local}}
 
-void bar(int n, int b[n]) { // expected-note {{'b' defined here}}
-#pragma omp task private(b) // expected-error {{arguments of OpenMP clause 'private' in '#pragma omp task' directive cannot be of variably-modified type 'int [n]'}}
+void bar(int n, int b[n]) {
+#pragma omp task private(b)
     foo();
 }