r264715 - [OPENMP 4.5] Allow data members in 'aligned' clause.
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 29 03:59:57 PDT 2016
Author: abataev
Date: Tue Mar 29 05:59:56 2016
New Revision: 264715
URL: http://llvm.org/viewvc/llvm-project?rev=264715&view=rev
Log:
[OPENMP 4.5] Allow data members in 'aligned' clause.
OpenMP 4.5 allows privatization of data members OpenMP clauses. Patch
adds support for data members in 'aligned' clause.
Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/simd_aligned_messages.cpp
cfe/trunk/test/OpenMP/simd_ast_print.cpp
cfe/trunk/test/OpenMP/simd_codegen.cpp
cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp
Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=264715&r1=264714&r2=264715&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Mar 29 05:59:56 2016
@@ -1745,7 +1745,7 @@ static DeclRefExpr *buildCapture(Sema &S
CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit,
/*AsExpression=*/false);
return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(),
- SourceLocation());
+ CaptureExpr->getExprLoc());
}
static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) {
@@ -7727,10 +7727,10 @@ OMPClause *Sema::ActOnOpenMPSharedClause
}
DeclRefExpr *Ref = nullptr;
- if (!VD)
+ if (!VD && IsOpenMPCapturedDecl(D))
Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true);
DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref);
- Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref);
+ Vars.push_back((VD || !Ref) ? RefExpr->IgnoreParens() : Ref);
}
if (Vars.empty())
@@ -8692,53 +8692,55 @@ OMPClause *Sema::ActOnOpenMPAlignedClaus
SmallVector<Expr *, 8> Vars;
for (auto &RefExpr : VarList) {
- assert(RefExpr && "NULL expr in OpenMP aligned clause.");
- if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
+ assert(RefExpr && "NULL expr in OpenMP linear clause.");
+ SourceLocation ELoc;
+ SourceRange ERange;
+ Expr *SimpleRefExpr = RefExpr;
+ auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange,
+ /*AllowArraySection=*/false);
+ if (Res.second) {
// It will be analyzed later.
Vars.push_back(RefExpr);
- continue;
}
-
- SourceLocation ELoc = RefExpr->getExprLoc();
- // OpenMP [2.1, C/C++]
- // A list item is a variable name.
- DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr);
- if (!DE || !isa<VarDecl>(DE->getDecl())) {
- Diag(ELoc, diag::err_omp_expected_var_name_member_expr)
- << 0 << RefExpr->getSourceRange();
+ ValueDecl *D = Res.first;
+ if (!D)
continue;
- }
- VarDecl *VD = cast<VarDecl>(DE->getDecl());
+ QualType QType = D->getType();
+ auto *VD = dyn_cast<VarDecl>(D);
// OpenMP [2.8.1, simd construct, Restrictions]
// 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();
QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType();
const Type *Ty = QType.getTypePtrOrNull();
- if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() &&
- !Ty->isPointerType())) {
+ if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) {
Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr)
- << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange();
+ << QType << getLangOpts().CPlusPlus << ERange;
bool IsDecl =
+ !VD ||
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
- Diag(VD->getLocation(),
+ Diag(D->getLocation(),
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
- << VD;
+ << D;
continue;
}
// OpenMP [2.8.1, simd construct, Restrictions]
// A list-item cannot appear in more than one aligned clause.
- if (Expr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) {
- Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange();
+ if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) {
+ Diag(ELoc, diag::err_omp_aligned_twice) << ERange;
Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa)
<< getOpenMPClauseName(OMPC_aligned);
continue;
}
- Vars.push_back(DE);
+ DeclRefExpr *Ref = nullptr;
+ if (!VD && IsOpenMPCapturedDecl(D))
+ Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true);
+ Vars.push_back(DefaultFunctionArrayConversion(
+ (VD || !Ref) ? RefExpr->IgnoreParens() : Ref)
+ .get());
}
// OpenMP [2.8.1, simd construct, Description]
Modified: cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp?rev=264715&r1=264714&r2=264715&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/for_simd_aligned_messages.cpp Tue Mar 29 05:59:56 2016
@@ -196,6 +196,7 @@ int main(int argc, char **argv) {
#pragma omp for simd aligned(h)
for (int k = 0; k < argc; ++k) ++k;
int *pargc = &argc;
+ // expected-note at +1 {{in instantiation of function template specialization 'foomain<int *, char>' requested here}}
foomain<int*,char>(pargc,argv);
return 0;
}
Modified: cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp?rev=264715&r1=264714&r2=264715&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/parallel_for_simd_aligned_messages.cpp Tue Mar 29 05:59:56 2016
@@ -196,6 +196,7 @@ int main(int argc, char **argv) {
#pragma omp parallel for simd aligned(h)
for (int k = 0; k < argc; ++k) ++k;
int *pargc = &argc;
+ // expected-note at +1 {{in instantiation of function template specialization 'foomain<int *, char>' requested here}}
foomain<int*,char>(pargc,argv);
return 0;
}
Modified: cfe/trunk/test/OpenMP/simd_aligned_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/simd_aligned_messages.cpp?rev=264715&r1=264714&r2=264715&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/simd_aligned_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/simd_aligned_messages.cpp Tue Mar 29 05:59:56 2016
@@ -196,6 +196,7 @@ int main(int argc, char **argv) {
#pragma omp simd aligned(h)
for (int k = 0; k < argc; ++k) ++k;
int *pargc = &argc;
+ // expected-note at +1 {{in instantiation of function template specialization 'foomain<int *, char>' requested here}}
foomain<int*,char>(pargc,argv);
return 0;
}
Modified: cfe/trunk/test/OpenMP/simd_ast_print.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/simd_ast_print.cpp?rev=264715&r1=264714&r2=264715&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/simd_ast_print.cpp (original)
+++ cfe/trunk/test/OpenMP/simd_ast_print.cpp Tue Mar 29 05:59:56 2016
@@ -6,6 +6,58 @@
#ifndef HEADER
#define HEADER
+struct SS {
+ SS(): a(0) {}
+ SS(int v) : a(v) {}
+ int a;
+ typedef int type;
+};
+
+template <typename T>
+class S7 : public T {
+protected:
+ T *a;
+ T b[2];
+ S7() : a(0) {}
+
+public:
+ S7(typename T::type &v) : a((T*)&v) {
+#pragma omp simd aligned(a)
+ for (int k = 0; k < a->a; ++k)
+ ++this->a->a;
+ }
+ S7 &operator=(S7 &s) {
+#pragma omp simd aligned(this->b : 8)
+ for (int k = 0; k < s.a->a; ++k)
+ ++s.a->a;
+ return *this;
+ }
+};
+
+// CHECK: #pragma omp simd aligned(this->a)
+// CHECK: #pragma omp simd aligned(this->a)
+// CHECK: #pragma omp simd aligned(this->b: 8)
+
+class S8 : public S7<SS> {
+ S8() {}
+
+public:
+ S8(int v) : S7<SS>(v){
+#pragma omp simd aligned(S7<SS>::a)
+ for (int k = 0; k < a->a; ++k)
+ ++this->a->a;
+ }
+ S8 &operator=(S8 &s) {
+#pragma omp simd aligned(this->b: 4)
+ for (int k = 0; k < s.a->a; ++k)
+ ++s.a->a;
+ return *this;
+ }
+};
+
+// CHECK: #pragma omp simd aligned(this->S7<SS>::a)
+// CHECK: #pragma omp simd aligned(this->b: 4)
+
void foo() {}
int g_ind = 1;
template<class T, class N> T reduct(T* arr, N num) {
Modified: cfe/trunk/test/OpenMP/simd_codegen.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/simd_codegen.cpp?rev=264715&r1=264714&r2=264715&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/simd_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/simd_codegen.cpp Tue Mar 29 05:59:56 2016
@@ -4,8 +4,10 @@
// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=TERM_DEBUG
// REQUIRES: x86-registered-target
// expected-no-diagnostics
-#ifndef HEADER
-#define HEADER
+ #ifndef HEADER
+ #define HEADER
+
+// CHECK: [[SS_TY:%.+]] = type { i32 }
long long get_val() { return 0; }
double *g_ptr;
@@ -632,5 +634,68 @@ void parallel_simd(float *a) {
a[i] += bar();
}
// TERM_DEBUG: !{{[0-9]+}} = !DILocation(line: [[@LINE-11]],
+
+// CHECK-LABEL: S8
+// CHECK: ptrtoint [[SS_TY]]* %{{.+}} to i64
+// CHECK-NEXT: and i64 %{{.+}}, 15
+// CHECK-NEXT: icmp eq i64 %{{.+}}, 0
+// CHECK-NEXT: call void @llvm.assume(i1
+
+// CHECK: ptrtoint [[SS_TY]]* %{{.+}} to i64
+// CHECK-NEXT: and i64 %{{.+}}, 7
+// CHECK-NEXT: icmp eq i64 %{{.+}}, 0
+// CHECK-NEXT: call void @llvm.assume(i1
+
+// CHECK: ptrtoint [[SS_TY]]* %{{.+}} to i64
+// CHECK-NEXT: and i64 %{{.+}}, 15
+// CHECK-NEXT: icmp eq i64 %{{.+}}, 0
+// CHECK-NEXT: call void @llvm.assume(i1
+
+// CHECK: ptrtoint [[SS_TY]]* %{{.+}} to i64
+// CHECK-NEXT: and i64 %{{.+}}, 3
+// CHECK-NEXT: icmp eq i64 %{{.+}}, 0
+// CHECK-NEXT: call void @llvm.assume(i1
+struct SS {
+ SS(): a(0) {}
+ SS(int v) : a(v) {}
+ int a;
+ typedef int type;
+};
+
+template <typename T>
+class S7 : public T {
+protected:
+ T *a;
+ T b[2];
+ S7() : a(0) {}
+
+public:
+ S7(typename T::type &v) : a((T*)&v) {
+#pragma omp simd aligned(a)
+ for (int k = 0; k < a->a; ++k)
+ ++this->a->a;
+#pragma omp simd aligned(this->b : 8)
+ for (int k = 0; k < a->a; ++k)
+ ++a->a;
+ }
+};
+
+class S8 : private IterDouble, public S7<SS> {
+ S8() {}
+
+public:
+ S8(int v) : S7<SS>(v){
+#pragma omp parallel private(a)
+#pragma omp simd aligned(S7<SS>::a)
+ for (int k = 0; k < a->a; ++k)
+ ++this->a->a;
+#pragma omp parallel shared(b)
+#pragma omp simd aligned(this->b: 4)
+ for (int k = 0; k < a->a; ++k)
+ ++a->a;
+ }
+};
+S8 s8(0);
+
#endif // HEADER
Modified: cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp?rev=264715&r1=264714&r2=264715&view=diff
==============================================================================
--- cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp (original)
+++ cfe/trunk/test/OpenMP/taskloop_simd_aligned_messages.cpp Tue Mar 29 05:59:56 2016
@@ -196,6 +196,7 @@ int main(int argc, char **argv) {
#pragma omp taskloop simd aligned(h)
for (int k = 0; k < argc; ++k) ++k;
int *pargc = &argc;
+ // expected-note at +1 {{in instantiation of function template specialization 'foomain<int *, char>' requested here}}
foomain<int*,char>(pargc,argv);
return 0;
}
More information about the cfe-commits
mailing list