2013-03-22 14:34:35 +08:00
|
|
|
//===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// \brief This file implements semantic analysis for OpenMP directives and
|
2013-05-13 12:18:18 +08:00
|
|
|
/// clauses.
|
2013-03-22 14:34:35 +08:00
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Basic/OpenMPKinds.h"
|
|
|
|
#include "clang/AST/Decl.h"
|
2013-07-19 11:13:43 +08:00
|
|
|
#include "clang/AST/DeclCXX.h"
|
2013-03-22 14:34:35 +08:00
|
|
|
#include "clang/AST/DeclOpenMP.h"
|
2013-07-19 11:13:43 +08:00
|
|
|
#include "clang/AST/StmtCXX.h"
|
|
|
|
#include "clang/AST/StmtOpenMP.h"
|
|
|
|
#include "clang/AST/StmtVisitor.h"
|
2013-03-22 14:34:35 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2013-07-19 11:13:43 +08:00
|
|
|
#include "clang/Sema/Initialization.h"
|
2013-03-22 14:34:35 +08:00
|
|
|
#include "clang/Sema/Lookup.h"
|
2013-07-19 11:13:43 +08:00
|
|
|
#include "clang/Sema/Scope.h"
|
|
|
|
#include "clang/Sema/ScopeInfo.h"
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "clang/Sema/SemaInternal.h"
|
2013-03-22 14:34:35 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Stack of data-sharing attributes for variables
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
/// \brief Default data sharing attributes, which can be applied to directive.
|
|
|
|
enum DefaultDataSharingAttributes {
|
|
|
|
DSA_unspecified = 0, /// \brief Data sharing attribute not specified.
|
|
|
|
DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'.
|
|
|
|
DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'.
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Stack for tracking declarations used in OpenMP directives and
|
|
|
|
/// clauses and their data-sharing attributes.
|
|
|
|
class DSAStackTy {
|
|
|
|
public:
|
|
|
|
struct DSAVarData {
|
|
|
|
OpenMPDirectiveKind DKind;
|
|
|
|
OpenMPClauseKind CKind;
|
|
|
|
DeclRefExpr *RefExpr;
|
|
|
|
DSAVarData() : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(0) { }
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
struct DSAInfo {
|
|
|
|
OpenMPClauseKind Attributes;
|
|
|
|
DeclRefExpr *RefExpr;
|
|
|
|
};
|
|
|
|
typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy;
|
|
|
|
|
|
|
|
struct SharingMapTy {
|
|
|
|
DeclSAMapTy SharingMap;
|
|
|
|
DefaultDataSharingAttributes DefaultAttr;
|
|
|
|
OpenMPDirectiveKind Directive;
|
|
|
|
DeclarationNameInfo DirectiveName;
|
|
|
|
Scope *CurScope;
|
|
|
|
SharingMapTy(OpenMPDirectiveKind DKind,
|
|
|
|
const DeclarationNameInfo &Name,
|
|
|
|
Scope *CurScope)
|
|
|
|
: SharingMap(), DefaultAttr(DSA_unspecified), Directive(DKind),
|
|
|
|
DirectiveName(Name), CurScope(CurScope) { }
|
|
|
|
SharingMapTy()
|
|
|
|
: SharingMap(), DefaultAttr(DSA_unspecified),
|
|
|
|
Directive(OMPD_unknown), DirectiveName(),
|
|
|
|
CurScope(0) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef SmallVector<SharingMapTy, 64> StackTy;
|
|
|
|
|
|
|
|
/// \brief Stack of used declaration and their data-sharing attributes.
|
|
|
|
StackTy Stack;
|
|
|
|
Sema &Actions;
|
|
|
|
|
|
|
|
typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator;
|
|
|
|
|
|
|
|
DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D);
|
2014-01-31 13:15:34 +08:00
|
|
|
|
|
|
|
/// \brief Checks if the variable is a local for OpenMP region.
|
|
|
|
bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter);
|
2013-09-07 02:03:48 +08:00
|
|
|
public:
|
|
|
|
explicit DSAStackTy(Sema &S) : Stack(1), Actions(S) { }
|
|
|
|
|
|
|
|
void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName,
|
|
|
|
Scope *CurScope) {
|
|
|
|
Stack.push_back(SharingMapTy(DKind, DirName, CurScope));
|
|
|
|
}
|
|
|
|
|
|
|
|
void pop() {
|
|
|
|
assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!");
|
|
|
|
Stack.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Adds explicit data sharing attribute to the specified declaration.
|
|
|
|
void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A);
|
|
|
|
|
|
|
|
/// \brief Returns data sharing attributes from top of the stack for the
|
|
|
|
/// specified declaration.
|
|
|
|
DSAVarData getTopDSA(VarDecl *D);
|
|
|
|
/// \brief Returns data-sharing attributes for the specified declaration.
|
|
|
|
DSAVarData getImplicitDSA(VarDecl *D);
|
2013-10-01 13:32:34 +08:00
|
|
|
/// \brief Checks if the specified variables has \a CKind data-sharing
|
|
|
|
/// attribute in \a DKind directive.
|
|
|
|
DSAVarData hasDSA(VarDecl *D, OpenMPClauseKind CKind,
|
|
|
|
OpenMPDirectiveKind DKind = OMPD_unknown);
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
/// \brief Returns currently analyzed directive.
|
|
|
|
OpenMPDirectiveKind getCurrentDirective() const {
|
|
|
|
return Stack.back().Directive;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Set default data sharing attribute to none.
|
|
|
|
void setDefaultDSANone() { Stack.back().DefaultAttr = DSA_none; }
|
|
|
|
/// \brief Set default data sharing attribute to shared.
|
|
|
|
void setDefaultDSAShared() { Stack.back().DefaultAttr = DSA_shared; }
|
|
|
|
|
|
|
|
DefaultDataSharingAttributes getDefaultDSA() const {
|
|
|
|
return Stack.back().DefaultAttr;
|
|
|
|
}
|
|
|
|
|
2014-03-31 11:36:38 +08:00
|
|
|
/// \brief Checks if the spewcified variable is threadprivate.
|
|
|
|
bool isThreadPrivate(VarDecl *D) {
|
|
|
|
DSAVarData DVar = getTopDSA(D);
|
|
|
|
return (DVar.CKind == OMPC_threadprivate || DVar.CKind == OMPC_copyin);
|
|
|
|
}
|
|
|
|
|
|
|
|
Scope *getCurScope() const { return Stack.back().CurScope; }
|
2013-09-07 02:03:48 +08:00
|
|
|
Scope *getCurScope() { return Stack.back().CurScope; }
|
|
|
|
};
|
|
|
|
} // end anonymous namespace.
|
|
|
|
|
|
|
|
DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter,
|
|
|
|
VarDecl *D) {
|
|
|
|
DSAVarData DVar;
|
|
|
|
if (Iter == Stack.rend() - 1) {
|
2014-03-18 20:19:12 +08:00
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a region but not in construct]
|
|
|
|
// File-scope or namespace-scope variables referenced in called routines
|
|
|
|
// in the region are shared unless they appear in a threadprivate
|
|
|
|
// directive.
|
|
|
|
// TODO
|
|
|
|
if (!D->isFunctionOrMethodVarDecl())
|
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a region but not in construct]
|
|
|
|
// Variables with static storage duration that are declared in called
|
|
|
|
// routines in the region are shared.
|
|
|
|
if (D->hasGlobalStorage())
|
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
return DVar;
|
|
|
|
}
|
2014-01-31 13:15:34 +08:00
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
DVar.DKind = Iter->Directive;
|
2014-01-31 13:15:34 +08:00
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, predetermined, p.1]
|
|
|
|
// Variables with automatic storage duration that are declared in a scope
|
|
|
|
// inside the construct are private.
|
|
|
|
if (DVar.DKind != OMPD_parallel) {
|
|
|
|
if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() &&
|
|
|
|
(D->getStorageClass() == SC_Auto ||
|
|
|
|
D->getStorageClass() == SC_None)) {
|
|
|
|
DVar.CKind = OMPC_private;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
// Explicitly specified attributes and local variables with predetermined
|
|
|
|
// attributes.
|
|
|
|
if (Iter->SharingMap.count(D)) {
|
|
|
|
DVar.RefExpr = Iter->SharingMap[D].RefExpr;
|
|
|
|
DVar.CKind = Iter->SharingMap[D].Attributes;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, implicitly determined, p.1]
|
|
|
|
// In a parallel or task construct, the data-sharing attributes of these
|
|
|
|
// variables are determined by the default clause, if present.
|
|
|
|
switch (Iter->DefaultAttr) {
|
|
|
|
case DSA_shared:
|
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
return DVar;
|
|
|
|
case DSA_none:
|
|
|
|
return DVar;
|
|
|
|
case DSA_unspecified:
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, implicitly determined, p.2]
|
|
|
|
// In a parallel construct, if no default clause is present, these
|
|
|
|
// variables are shared.
|
|
|
|
if (DVar.DKind == OMPD_parallel) {
|
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, implicitly determined, p.4]
|
|
|
|
// In a task construct, if no default clause is present, a variable that in
|
|
|
|
// the enclosing context is determined to be shared by all implicit tasks
|
|
|
|
// bound to the current team is shared.
|
|
|
|
// TODO
|
|
|
|
if (DVar.DKind == OMPD_task) {
|
|
|
|
DSAVarData DVarTemp;
|
2014-03-02 20:20:24 +08:00
|
|
|
for (StackTy::reverse_iterator I = std::next(Iter),
|
|
|
|
EE = std::prev(Stack.rend());
|
2013-09-07 02:03:48 +08:00
|
|
|
I != EE; ++I) {
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, implicitly determined, p.6]
|
|
|
|
// In a task construct, if no default clause is present, a variable
|
|
|
|
// whose data-sharing attribute is not determined by the rules above is
|
|
|
|
// firstprivate.
|
|
|
|
DVarTemp = getDSA(I, D);
|
|
|
|
if (DVarTemp.CKind != OMPC_shared) {
|
|
|
|
DVar.RefExpr = 0;
|
|
|
|
DVar.DKind = OMPD_task;
|
2013-10-01 13:32:34 +08:00
|
|
|
DVar.CKind = OMPC_firstprivate;
|
2013-09-07 02:03:48 +08:00
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
if (I->Directive == OMPD_parallel) break;
|
|
|
|
}
|
|
|
|
DVar.DKind = OMPD_task;
|
|
|
|
DVar.CKind =
|
2013-10-01 13:32:34 +08:00
|
|
|
(DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared;
|
2013-09-07 02:03:48 +08:00
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, implicitly determined, p.3]
|
|
|
|
// For constructs other than task, if no default clause is present, these
|
|
|
|
// variables inherit their data-sharing attributes from the enclosing
|
|
|
|
// context.
|
2014-03-02 20:20:24 +08:00
|
|
|
return getDSA(std::next(Iter), D);
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) {
|
|
|
|
if (A == OMPC_threadprivate) {
|
|
|
|
Stack[0].SharingMap[D].Attributes = A;
|
|
|
|
Stack[0].SharingMap[D].RefExpr = E;
|
|
|
|
} else {
|
|
|
|
assert(Stack.size() > 1 && "Data-sharing attributes stack is empty");
|
|
|
|
Stack.back().SharingMap[D].Attributes = A;
|
|
|
|
Stack.back().SharingMap[D].RefExpr = E;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-31 11:36:38 +08:00
|
|
|
bool
|
|
|
|
DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) {
|
2014-01-31 13:15:34 +08:00
|
|
|
if (Stack.size() > 2) {
|
|
|
|
reverse_iterator I = Iter, E = Stack.rend() - 1;
|
|
|
|
Scope *TopScope = 0;
|
|
|
|
while (I != E &&
|
|
|
|
I->Directive != OMPD_parallel) {
|
|
|
|
++I;
|
|
|
|
}
|
|
|
|
if (I == E) return false;
|
|
|
|
TopScope = I->CurScope ? I->CurScope->getParent() : 0;
|
|
|
|
Scope *CurScope = getCurScope();
|
|
|
|
while (CurScope != TopScope && !CurScope->isDeclScope(D)) {
|
2013-09-07 02:03:48 +08:00
|
|
|
CurScope = CurScope->getParent();
|
2014-01-31 13:15:34 +08:00
|
|
|
}
|
|
|
|
return CurScope != TopScope;
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
2014-01-31 13:15:34 +08:00
|
|
|
return false;
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D) {
|
|
|
|
DSAVarData DVar;
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, predetermined, p.1]
|
|
|
|
// Variables appearing in threadprivate directives are threadprivate.
|
|
|
|
if (D->getTLSKind() != VarDecl::TLS_None) {
|
|
|
|
DVar.CKind = OMPC_threadprivate;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
if (Stack[0].SharingMap.count(D)) {
|
|
|
|
DVar.RefExpr = Stack[0].SharingMap[D].RefExpr;
|
|
|
|
DVar.CKind = OMPC_threadprivate;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, predetermined, p.1]
|
|
|
|
// Variables with automatic storage duration that are declared in a scope
|
|
|
|
// inside the construct are private.
|
2014-01-31 13:15:34 +08:00
|
|
|
OpenMPDirectiveKind Kind = getCurrentDirective();
|
|
|
|
if (Kind != OMPD_parallel) {
|
2014-03-02 20:20:24 +08:00
|
|
|
if (isOpenMPLocal(D, std::next(Stack.rbegin())) && D->isLocalVarDecl() &&
|
2014-01-31 13:15:34 +08:00
|
|
|
(D->getStorageClass() == SC_Auto ||
|
|
|
|
D->getStorageClass() == SC_None))
|
|
|
|
DVar.CKind = OMPC_private;
|
|
|
|
return DVar;
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, predetermined, p.4]
|
|
|
|
// Static data memebers are shared.
|
|
|
|
if (D->isStaticDataMember()) {
|
2013-10-01 13:32:34 +08:00
|
|
|
// Variables with const-qualified type having no mutable member may be listed
|
|
|
|
// in a firstprivate clause, even if they are static data members.
|
|
|
|
DSAVarData DVarTemp = hasDSA(D, OMPC_firstprivate);
|
|
|
|
if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr)
|
|
|
|
return DVar;
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
QualType Type = D->getType().getNonReferenceType().getCanonicalType();
|
|
|
|
bool IsConstant = Type.isConstant(Actions.getASTContext());
|
|
|
|
while (Type->isArrayType()) {
|
|
|
|
QualType ElemType = cast<ArrayType>(Type.getTypePtr())->getElementType();
|
|
|
|
Type = ElemType.getNonReferenceType().getCanonicalType();
|
|
|
|
}
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, predetermined, p.6]
|
|
|
|
// Variables with const qualified type having no mutable member are
|
|
|
|
// shared.
|
|
|
|
CXXRecordDecl *RD = Actions.getLangOpts().CPlusPlus ?
|
|
|
|
Type->getAsCXXRecordDecl() : 0;
|
|
|
|
if (IsConstant &&
|
|
|
|
!(Actions.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) {
|
|
|
|
// Variables with const-qualified type having no mutable member may be
|
|
|
|
// listed in a firstprivate clause, even if they are static data members.
|
2013-10-01 13:32:34 +08:00
|
|
|
DSAVarData DVarTemp = hasDSA(D, OMPC_firstprivate);
|
|
|
|
if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr)
|
|
|
|
return DVar;
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, predetermined, p.7]
|
|
|
|
// Variables with static storage duration that are declared in a scope
|
|
|
|
// inside the construct are shared.
|
2014-01-31 13:15:34 +08:00
|
|
|
if (D->isStaticLocal()) {
|
2013-09-07 02:03:48 +08:00
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Explicitly specified attributes and local variables with predetermined
|
|
|
|
// attributes.
|
|
|
|
if (Stack.back().SharingMap.count(D)) {
|
|
|
|
DVar.RefExpr = Stack.back().SharingMap[D].RefExpr;
|
|
|
|
DVar.CKind = Stack.back().SharingMap[D].Attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D) {
|
2014-03-02 20:20:24 +08:00
|
|
|
return getDSA(std::next(Stack.rbegin()), D);
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
|
2013-10-01 13:32:34 +08:00
|
|
|
DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, OpenMPClauseKind CKind,
|
|
|
|
OpenMPDirectiveKind DKind) {
|
2014-03-02 20:20:24 +08:00
|
|
|
for (StackTy::reverse_iterator I = std::next(Stack.rbegin()),
|
|
|
|
E = std::prev(Stack.rend());
|
2013-10-01 13:32:34 +08:00
|
|
|
I != E; ++I) {
|
|
|
|
if (DKind != OMPD_unknown && DKind != I->Directive) continue;
|
|
|
|
DSAVarData DVar = getDSA(I, D);
|
|
|
|
if (DVar.CKind == CKind)
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
return DSAVarData();
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
void Sema::InitDataSharingAttributesStack() {
|
|
|
|
VarDataSharingAttributesStack = new DSAStackTy(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack)
|
|
|
|
|
|
|
|
void Sema::DestroyDataSharingAttributesStack() {
|
|
|
|
delete DSAStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind,
|
|
|
|
const DeclarationNameInfo &DirName,
|
|
|
|
Scope *CurScope) {
|
|
|
|
DSAStack->push(DKind, DirName, CurScope);
|
|
|
|
PushExpressionEvaluationContext(PotentiallyEvaluated);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sema::EndOpenMPDSABlock(Stmt *CurDirective) {
|
|
|
|
DSAStack->pop();
|
|
|
|
DiscardCleanupsInEvaluationContext();
|
|
|
|
PopExpressionEvaluationContext();
|
|
|
|
}
|
|
|
|
|
2013-03-22 14:34:35 +08:00
|
|
|
namespace {
|
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
class VarDeclFilterCCC : public CorrectionCandidateCallback {
|
|
|
|
private:
|
|
|
|
Sema &Actions;
|
|
|
|
public:
|
|
|
|
VarDeclFilterCCC(Sema &S) : Actions(S) { }
|
2014-03-12 12:55:44 +08:00
|
|
|
bool ValidateCandidate(const TypoCorrection &Candidate) override {
|
2013-05-13 12:18:18 +08:00
|
|
|
NamedDecl *ND = Candidate.getCorrectionDecl();
|
|
|
|
if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) {
|
|
|
|
return VD->hasGlobalStorage() &&
|
|
|
|
Actions.isDeclInScope(ND, Actions.getCurLexicalContext(),
|
|
|
|
Actions.getCurScope());
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope,
|
|
|
|
CXXScopeSpec &ScopeSpec,
|
|
|
|
const DeclarationNameInfo &Id) {
|
|
|
|
LookupResult Lookup(*this, Id, LookupOrdinaryName);
|
|
|
|
LookupParsedName(Lookup, CurScope, &ScopeSpec, true);
|
2013-03-22 14:34:35 +08:00
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
if (Lookup.isAmbiguous())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
VarDecl *VD;
|
|
|
|
if (!Lookup.isSingleResult()) {
|
|
|
|
VarDeclFilterCCC Validator(*this);
|
2013-08-17 08:46:16 +08:00
|
|
|
if (TypoCorrection Corrected = CorrectTypo(Id, LookupOrdinaryName, CurScope,
|
|
|
|
0, Validator)) {
|
|
|
|
diagnoseTypo(Corrected,
|
|
|
|
PDiag(Lookup.empty()? diag::err_undeclared_var_use_suggest
|
|
|
|
: diag::err_omp_expected_var_arg_suggest)
|
|
|
|
<< Id.getName());
|
|
|
|
VD = Corrected.getCorrectionDeclAs<VarDecl>();
|
2013-03-22 14:34:35 +08:00
|
|
|
} else {
|
2013-08-17 08:46:16 +08:00
|
|
|
Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use
|
|
|
|
: diag::err_omp_expected_var_arg)
|
|
|
|
<< Id.getName();
|
|
|
|
return ExprError();
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
} else {
|
|
|
|
if (!(VD = Lookup.getAsSingle<VarDecl>())) {
|
2013-08-17 08:46:16 +08:00
|
|
|
Diag(Id.getLoc(), diag::err_omp_expected_var_arg)
|
|
|
|
<< Id.getName();
|
2013-05-13 12:18:18 +08:00
|
|
|
Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at);
|
|
|
|
return ExprError();
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
}
|
|
|
|
Lookup.suppressDiagnostics();
|
2013-03-22 14:34:35 +08:00
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
// OpenMP [2.9.2, Syntax, C/C++]
|
|
|
|
// Variables must be file-scope, namespace-scope, or static block-scope.
|
|
|
|
if (!VD->hasGlobalStorage()) {
|
|
|
|
Diag(Id.getLoc(), diag::err_omp_global_var_arg)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate)
|
|
|
|
<< !VD->isStaticLocal();
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here) << VD;
|
|
|
|
return ExprError();
|
|
|
|
}
|
2013-03-22 14:34:35 +08:00
|
|
|
|
2013-09-26 11:24:06 +08:00
|
|
|
VarDecl *CanonicalVD = VD->getCanonicalDecl();
|
|
|
|
NamedDecl *ND = cast<NamedDecl>(CanonicalVD);
|
2013-05-13 12:18:18 +08:00
|
|
|
// OpenMP [2.9.2, Restrictions, C/C++, p.2]
|
|
|
|
// A threadprivate directive for file-scope variables must appear outside
|
|
|
|
// any definition or declaration.
|
2013-09-26 11:24:06 +08:00
|
|
|
if (CanonicalVD->getDeclContext()->isTranslationUnit() &&
|
|
|
|
!getCurLexicalContext()->isTranslationUnit()) {
|
|
|
|
Diag(Id.getLoc(), diag::err_omp_var_scope)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
return ExprError();
|
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
// OpenMP [2.9.2, Restrictions, C/C++, p.3]
|
|
|
|
// A threadprivate directive for static class member variables must appear
|
|
|
|
// in the class definition, in the same scope in which the member
|
|
|
|
// variables are declared.
|
2013-09-26 11:24:06 +08:00
|
|
|
if (CanonicalVD->isStaticDataMember() &&
|
|
|
|
!CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) {
|
|
|
|
Diag(Id.getLoc(), diag::err_omp_var_scope)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
return ExprError();
|
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
// OpenMP [2.9.2, Restrictions, C/C++, p.4]
|
|
|
|
// A threadprivate directive for namespace-scope variables must appear
|
|
|
|
// outside any definition or declaration other than the namespace
|
|
|
|
// definition itself.
|
2013-09-26 11:24:06 +08:00
|
|
|
if (CanonicalVD->getDeclContext()->isNamespace() &&
|
|
|
|
(!getCurLexicalContext()->isFileContext() ||
|
|
|
|
!getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) {
|
|
|
|
Diag(Id.getLoc(), diag::err_omp_var_scope)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
return ExprError();
|
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
// OpenMP [2.9.2, Restrictions, C/C++, p.6]
|
|
|
|
// A threadprivate directive for static block-scope variables must appear
|
|
|
|
// in the scope of the variable and not in a nested scope.
|
2013-09-26 11:24:06 +08:00
|
|
|
if (CanonicalVD->isStaticLocal() && CurScope &&
|
|
|
|
!isDeclInScope(ND, getCurLexicalContext(), CurScope)) {
|
2013-05-13 12:18:18 +08:00
|
|
|
Diag(Id.getLoc(), diag::err_omp_var_scope)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
return ExprError();
|
|
|
|
}
|
2013-03-22 14:34:35 +08:00
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
// OpenMP [2.9.2, Restrictions, C/C++, p.2-6]
|
|
|
|
// A threadprivate directive must lexically precede all references to any
|
|
|
|
// of the variables in its list.
|
|
|
|
if (VD->isUsed()) {
|
|
|
|
Diag(Id.getLoc(), diag::err_omp_var_used)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
return ExprError();
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
|
|
|
|
QualType ExprType = VD->getType().getNonReferenceType();
|
2014-03-07 16:03:37 +08:00
|
|
|
ExprResult DE = BuildDeclRefExpr(VD, ExprType, VK_LValue, Id.getLoc());
|
2013-05-13 12:18:18 +08:00
|
|
|
return DE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sema::DeclGroupPtrTy Sema::ActOnOpenMPThreadprivateDirective(
|
|
|
|
SourceLocation Loc,
|
|
|
|
ArrayRef<Expr *> VarList) {
|
|
|
|
if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) {
|
2013-03-22 14:34:35 +08:00
|
|
|
CurContext->addDecl(D);
|
|
|
|
return DeclGroupPtrTy::make(DeclGroupRef(D));
|
|
|
|
}
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPThreadPrivateDecl *Sema::CheckOMPThreadPrivateDecl(
|
|
|
|
SourceLocation Loc,
|
2013-05-13 12:18:18 +08:00
|
|
|
ArrayRef<Expr *> VarList) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
|
|
|
for (ArrayRef<Expr *>::iterator I = VarList.begin(),
|
2013-03-22 14:34:35 +08:00
|
|
|
E = VarList.end();
|
|
|
|
I != E; ++I) {
|
2013-05-13 12:18:18 +08:00
|
|
|
DeclRefExpr *DE = cast<DeclRefExpr>(*I);
|
|
|
|
VarDecl *VD = cast<VarDecl>(DE->getDecl());
|
|
|
|
SourceLocation ILoc = DE->getExprLoc();
|
2013-03-22 14:34:35 +08:00
|
|
|
|
|
|
|
// OpenMP [2.9.2, Restrictions, C/C++, p.10]
|
|
|
|
// A threadprivate variable must not have an incomplete type.
|
|
|
|
if (RequireCompleteType(ILoc, VD->getType(),
|
2013-05-13 12:18:18 +08:00
|
|
|
diag::err_omp_threadprivate_incomplete_type)) {
|
2013-03-22 14:34:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.2, Restrictions, C/C++, p.10]
|
|
|
|
// A threadprivate variable must not have a reference type.
|
|
|
|
if (VD->getType()->isReferenceType()) {
|
|
|
|
Diag(ILoc, diag::err_omp_ref_type_arg)
|
2013-07-19 11:13:43 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate)
|
|
|
|
<< VD->getType();
|
2013-05-13 12:18:18 +08:00
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
2013-03-22 14:34:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-04-13 10:43:54 +08:00
|
|
|
// Check if this is a TLS variable.
|
|
|
|
if (VD->getTLSKind()) {
|
2013-03-22 14:34:35 +08:00
|
|
|
Diag(ILoc, diag::err_omp_var_thread_local) << VD;
|
2013-05-13 12:18:18 +08:00
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
2013-03-22 14:34:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vars.push_back(*I);
|
2014-03-07 16:03:37 +08:00
|
|
|
DSAStack->addDSA(VD, DE, OMPC_threadprivate);
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2014-01-31 13:15:34 +08:00
|
|
|
OMPThreadPrivateDecl *D = 0;
|
|
|
|
if (!Vars.empty()) {
|
|
|
|
D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc,
|
|
|
|
Vars);
|
|
|
|
D->setAccess(AS_public);
|
|
|
|
}
|
|
|
|
return D;
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
namespace {
|
|
|
|
class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> {
|
|
|
|
DSAStackTy *Stack;
|
|
|
|
Sema &Actions;
|
|
|
|
bool ErrorFound;
|
|
|
|
CapturedStmt *CS;
|
2013-10-01 13:32:34 +08:00
|
|
|
llvm::SmallVector<Expr *, 8> ImplicitFirstprivate;
|
2013-09-07 02:03:48 +08:00
|
|
|
public:
|
|
|
|
void VisitDeclRefExpr(DeclRefExpr *E) {
|
|
|
|
if(VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {
|
|
|
|
// Skip internally declared variables.
|
|
|
|
if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) return;
|
|
|
|
|
|
|
|
SourceLocation ELoc = E->getExprLoc();
|
|
|
|
|
|
|
|
OpenMPDirectiveKind DKind = Stack->getCurrentDirective();
|
|
|
|
DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD);
|
|
|
|
if (DVar.CKind != OMPC_unknown) {
|
|
|
|
if (DKind == OMPD_task && DVar.CKind != OMPC_shared &&
|
2014-03-31 11:36:38 +08:00
|
|
|
!Stack->isThreadPrivate(VD) && !DVar.RefExpr)
|
2013-10-01 13:32:34 +08:00
|
|
|
ImplicitFirstprivate.push_back(DVar.RefExpr);
|
2013-09-07 02:03:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// The default(none) clause requires that each variable that is referenced
|
|
|
|
// in the construct, and does not have a predetermined data-sharing
|
|
|
|
// attribute, must have its data-sharing attribute explicitly determined
|
|
|
|
// by being listed in a data-sharing attribute clause.
|
|
|
|
if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none &&
|
|
|
|
(DKind == OMPD_parallel || DKind == OMPD_task)) {
|
|
|
|
ErrorFound = true;
|
|
|
|
Actions.Diag(ELoc, diag::err_omp_no_dsa_for_variable) << VD;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.3.6, Restrictions, p.2]
|
|
|
|
// A list item that appears in a reduction clause of the innermost
|
|
|
|
// enclosing worksharing or parallel construct may not be accessed in an
|
|
|
|
// explicit task.
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
// Define implicit data-sharing attributes for task.
|
|
|
|
DVar = Stack->getImplicitDSA(VD);
|
2013-10-01 13:32:34 +08:00
|
|
|
if (DKind == OMPD_task && DVar.CKind != OMPC_shared)
|
|
|
|
ImplicitFirstprivate.push_back(DVar.RefExpr);
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void VisitOMPExecutableDirective(OMPExecutableDirective *S) {
|
|
|
|
for (ArrayRef<OMPClause *>::iterator I = S->clauses().begin(),
|
|
|
|
E = S->clauses().end();
|
|
|
|
I != E; ++I)
|
|
|
|
if (OMPClause *C = *I)
|
|
|
|
for (StmtRange R = C->children(); R; ++R)
|
|
|
|
if (Stmt *Child = *R)
|
|
|
|
Visit(Child);
|
|
|
|
}
|
|
|
|
void VisitStmt(Stmt *S) {
|
|
|
|
for (Stmt::child_iterator I = S->child_begin(), E = S->child_end();
|
|
|
|
I != E; ++I)
|
|
|
|
if (Stmt *Child = *I)
|
|
|
|
if (!isa<OMPExecutableDirective>(Child))
|
|
|
|
Visit(Child);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isErrorFound() { return ErrorFound; }
|
2013-10-01 13:32:34 +08:00
|
|
|
ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; }
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
DSAAttrChecker(DSAStackTy *S, Sema &Actions, CapturedStmt *CS)
|
|
|
|
: Stack(S), Actions(Actions), ErrorFound(false), CS(CS) { }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind,
|
|
|
|
ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2013-09-07 02:03:48 +08:00
|
|
|
assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
StmtResult Res = StmtError();
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
// Check default data sharing attributes for referenced variables.
|
|
|
|
DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt));
|
|
|
|
DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt());
|
|
|
|
if (DSAChecker.isErrorFound())
|
|
|
|
return StmtError();
|
2013-10-01 13:32:34 +08:00
|
|
|
// Generate list of implicitly defined firstprivate variables.
|
|
|
|
llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit;
|
|
|
|
ClausesWithImplicit.append(Clauses.begin(), Clauses.end());
|
|
|
|
|
|
|
|
bool ErrorFound = false;
|
|
|
|
if (!DSAChecker.getImplicitFirstprivate().empty()) {
|
|
|
|
if (OMPClause *Implicit =
|
|
|
|
ActOnOpenMPFirstprivateClause(DSAChecker.getImplicitFirstprivate(),
|
|
|
|
SourceLocation(), SourceLocation(),
|
|
|
|
SourceLocation())) {
|
|
|
|
ClausesWithImplicit.push_back(Implicit);
|
|
|
|
ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() !=
|
|
|
|
DSAChecker.getImplicitFirstprivate().size();
|
|
|
|
} else
|
|
|
|
ErrorFound = true;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
switch (Kind) {
|
|
|
|
case OMPD_parallel:
|
2013-10-01 13:32:34 +08:00
|
|
|
Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt,
|
|
|
|
StartLoc, EndLoc);
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
2014-02-27 16:29:12 +08:00
|
|
|
case OMPD_simd:
|
|
|
|
Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt,
|
|
|
|
StartLoc, EndLoc);
|
|
|
|
break;
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPD_threadprivate:
|
|
|
|
case OMPD_task:
|
|
|
|
llvm_unreachable("OpenMP Directive is not allowed");
|
|
|
|
case OMPD_unknown:
|
|
|
|
case NUM_OPENMP_DIRECTIVES:
|
|
|
|
llvm_unreachable("Unknown OpenMP directive");
|
|
|
|
}
|
2013-10-01 13:32:34 +08:00
|
|
|
|
|
|
|
if (ErrorFound) return StmtError();
|
2013-07-19 11:13:43 +08:00
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
|
|
|
return Owned(OMPParallelDirective::Create(Context, StartLoc, EndLoc,
|
|
|
|
Clauses, AStmt));
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:29:12 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
Stmt *CStmt = AStmt;
|
|
|
|
while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(CStmt))
|
|
|
|
CStmt = CS->getCapturedStmt();
|
|
|
|
while (AttributedStmt *AS = dyn_cast_or_null<AttributedStmt>(CStmt))
|
|
|
|
CStmt = AS->getSubStmt();
|
|
|
|
ForStmt *For = dyn_cast<ForStmt>(CStmt);
|
|
|
|
if (!For) {
|
|
|
|
Diag(CStmt->getLocStart(), diag::err_omp_not_for)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_simd);
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Checking loop canonical form, collapsing etc.
|
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
return Owned(OMPSimdDirective::Create(Context, StartLoc, EndLoc,
|
|
|
|
Clauses, AStmt));
|
|
|
|
}
|
|
|
|
|
2014-02-13 13:29:23 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind,
|
|
|
|
Expr *Expr,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
OMPClause *Res = 0;
|
|
|
|
switch (Kind) {
|
|
|
|
case OMPC_if:
|
|
|
|
Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-03-06 14:15:19 +08:00
|
|
|
case OMPC_num_threads:
|
|
|
|
Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-03-21 12:51:18 +08:00
|
|
|
case OMPC_safelen:
|
|
|
|
Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_default:
|
|
|
|
case OMPC_private:
|
|
|
|
case OMPC_firstprivate:
|
|
|
|
case OMPC_shared:
|
2014-03-31 11:36:38 +08:00
|
|
|
case OMPC_copyin:
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_threadprivate:
|
|
|
|
case OMPC_unknown:
|
|
|
|
case NUM_OPENMP_CLAUSES:
|
|
|
|
llvm_unreachable("Clause is not allowed.");
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
Expr *ValExpr = Condition;
|
|
|
|
if (!Condition->isValueDependent() && !Condition->isTypeDependent() &&
|
|
|
|
!Condition->isInstantiationDependent() &&
|
|
|
|
!Condition->containsUnexpandedParameterPack()) {
|
|
|
|
ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(),
|
|
|
|
Condition->getExprLoc(),
|
|
|
|
Condition);
|
|
|
|
if (Val.isInvalid())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ValExpr = Val.take();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-03-06 14:15:19 +08:00
|
|
|
ExprResult Sema::PerformImplicitIntegerConversion(SourceLocation Loc,
|
|
|
|
Expr *Op) {
|
|
|
|
if (!Op)
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
class IntConvertDiagnoser : public ICEConvertDiagnoser {
|
|
|
|
public:
|
|
|
|
IntConvertDiagnoser()
|
|
|
|
: ICEConvertDiagnoser(/*AllowScopedEnumerations*/false,
|
|
|
|
false, true) {}
|
2014-03-12 12:55:44 +08:00
|
|
|
SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc,
|
|
|
|
QualType T) override {
|
2014-03-06 14:15:19 +08:00
|
|
|
return S.Diag(Loc, diag::err_omp_not_integral) << T;
|
|
|
|
}
|
2014-03-12 12:55:44 +08:00
|
|
|
SemaDiagnosticBuilder diagnoseIncomplete(
|
|
|
|
Sema &S, SourceLocation Loc, QualType T) override {
|
2014-03-06 14:15:19 +08:00
|
|
|
return S.Diag(Loc, diag::err_omp_incomplete_type) << T;
|
|
|
|
}
|
2014-03-12 12:55:44 +08:00
|
|
|
SemaDiagnosticBuilder diagnoseExplicitConv(
|
|
|
|
Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) override {
|
2014-03-06 14:15:19 +08:00
|
|
|
return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy;
|
|
|
|
}
|
2014-03-12 12:55:44 +08:00
|
|
|
SemaDiagnosticBuilder noteExplicitConv(
|
|
|
|
Sema &S, CXXConversionDecl *Conv, QualType ConvTy) override {
|
2014-03-06 14:15:19 +08:00
|
|
|
return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here)
|
|
|
|
<< ConvTy->isEnumeralType() << ConvTy;
|
|
|
|
}
|
2014-03-12 12:55:44 +08:00
|
|
|
SemaDiagnosticBuilder diagnoseAmbiguous(
|
|
|
|
Sema &S, SourceLocation Loc, QualType T) override {
|
2014-03-06 14:15:19 +08:00
|
|
|
return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T;
|
|
|
|
}
|
2014-03-12 12:55:44 +08:00
|
|
|
SemaDiagnosticBuilder noteAmbiguous(
|
|
|
|
Sema &S, CXXConversionDecl *Conv, QualType ConvTy) override {
|
2014-03-06 14:15:19 +08:00
|
|
|
return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here)
|
|
|
|
<< ConvTy->isEnumeralType() << ConvTy;
|
|
|
|
}
|
2014-03-12 12:55:44 +08:00
|
|
|
SemaDiagnosticBuilder diagnoseConversion(
|
|
|
|
Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) override {
|
2014-03-06 14:15:19 +08:00
|
|
|
llvm_unreachable("conversion functions are permitted");
|
|
|
|
}
|
|
|
|
} ConvertDiagnoser;
|
|
|
|
return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser);
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
Expr *ValExpr = NumThreads;
|
|
|
|
if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() &&
|
|
|
|
!NumThreads->isInstantiationDependent() &&
|
|
|
|
!NumThreads->containsUnexpandedParameterPack()) {
|
|
|
|
SourceLocation NumThreadsLoc = NumThreads->getLocStart();
|
|
|
|
ExprResult Val =
|
|
|
|
PerformImplicitIntegerConversion(NumThreadsLoc, NumThreads);
|
|
|
|
if (Val.isInvalid())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ValExpr = Val.take();
|
|
|
|
|
|
|
|
// OpenMP [2.5, Restrictions]
|
|
|
|
// The num_threads expression must evaluate to a positive integer value.
|
|
|
|
llvm::APSInt Result;
|
|
|
|
if (ValExpr->isIntegerConstantExpr(Result, Context) &&
|
|
|
|
Result.isSigned() && !Result.isStrictlyPositive()) {
|
|
|
|
Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause)
|
|
|
|
<< "num_threads" << NumThreads->getSourceRange();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new (Context) OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc,
|
|
|
|
EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-03-21 12:51:18 +08:00
|
|
|
ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E,
|
|
|
|
OpenMPClauseKind CKind) {
|
|
|
|
if (!E)
|
|
|
|
return ExprError();
|
|
|
|
if (E->isValueDependent() || E->isTypeDependent() ||
|
|
|
|
E->isInstantiationDependent() || E->containsUnexpandedParameterPack())
|
|
|
|
return Owned(E);
|
|
|
|
llvm::APSInt Result;
|
|
|
|
ExprResult ICE = VerifyIntegerConstantExpression(E, &Result);
|
|
|
|
if (ICE.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
if (!Result.isStrictlyPositive()) {
|
|
|
|
Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause)
|
|
|
|
<< getOpenMPClauseName(CKind) << E->getSourceRange();
|
|
|
|
return ExprError();
|
|
|
|
}
|
|
|
|
return ICE;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
// OpenMP [2.8.1, simd construct, Description]
|
|
|
|
// The parameter of the safelen clause must be a constant
|
|
|
|
// positive integer expression.
|
|
|
|
ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen);
|
|
|
|
if (Safelen.isInvalid())
|
|
|
|
return 0;
|
|
|
|
return new (Context)
|
|
|
|
OMPSafelenClause(Safelen.take(), StartLoc, LParenLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSimpleClause(OpenMPClauseKind Kind,
|
|
|
|
unsigned Argument,
|
|
|
|
SourceLocation ArgumentLoc,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
OMPClause *Res = 0;
|
|
|
|
switch (Kind) {
|
|
|
|
case OMPC_default:
|
2013-09-07 02:03:48 +08:00
|
|
|
Res =
|
|
|
|
ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument),
|
|
|
|
ArgumentLoc, StartLoc, LParenLoc, EndLoc);
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_if:
|
2014-03-06 14:15:19 +08:00
|
|
|
case OMPC_num_threads:
|
2014-03-21 12:51:18 +08:00
|
|
|
case OMPC_safelen:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_private:
|
2013-10-01 13:32:34 +08:00
|
|
|
case OMPC_firstprivate:
|
2013-09-07 02:03:48 +08:00
|
|
|
case OMPC_shared:
|
2014-03-31 11:36:38 +08:00
|
|
|
case OMPC_copyin:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_threadprivate:
|
|
|
|
case OMPC_unknown:
|
|
|
|
case NUM_OPENMP_CLAUSES:
|
|
|
|
llvm_unreachable("Clause is not allowed.");
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind,
|
|
|
|
SourceLocation KindKwLoc,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
if (Kind == OMPC_DEFAULT_unknown) {
|
|
|
|
std::string Values;
|
2014-03-22 01:34:28 +08:00
|
|
|
static_assert(NUM_OPENMP_DEFAULT_KINDS > 1,
|
|
|
|
"NUM_OPENMP_DEFAULT_KINDS not greater than 1");
|
|
|
|
std::string Sep(", ");
|
2013-07-19 11:13:43 +08:00
|
|
|
for (unsigned i = OMPC_DEFAULT_unknown + 1;
|
|
|
|
i < NUM_OPENMP_DEFAULT_KINDS; ++i) {
|
|
|
|
Values += "'";
|
|
|
|
Values += getOpenMPSimpleClauseTypeName(OMPC_default, i);
|
|
|
|
Values += "'";
|
|
|
|
switch (i) {
|
|
|
|
case NUM_OPENMP_DEFAULT_KINDS - 2:
|
|
|
|
Values += " or ";
|
|
|
|
break;
|
|
|
|
case NUM_OPENMP_DEFAULT_KINDS - 1:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Values += Sep;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Diag(KindKwLoc, diag::err_omp_unexpected_clause_value)
|
|
|
|
<< Values << getOpenMPClauseName(OMPC_default);
|
|
|
|
return 0;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
switch (Kind) {
|
|
|
|
case OMPC_DEFAULT_none:
|
|
|
|
DSAStack->setDefaultDSANone();
|
|
|
|
break;
|
|
|
|
case OMPC_DEFAULT_shared:
|
|
|
|
DSAStack->setDefaultDSAShared();
|
|
|
|
break;
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_DEFAULT_unknown:
|
|
|
|
case NUM_OPENMP_DEFAULT_KINDS:
|
|
|
|
llvm_unreachable("Clause kind is not allowed.");
|
2013-09-07 02:03:48 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-19 11:13:43 +08:00
|
|
|
return new (Context) OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc,
|
|
|
|
EndLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPVarListClause(OpenMPClauseKind Kind,
|
|
|
|
ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
OMPClause *Res = 0;
|
|
|
|
switch (Kind) {
|
|
|
|
case OMPC_private:
|
|
|
|
Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2013-10-01 13:32:34 +08:00
|
|
|
case OMPC_firstprivate:
|
|
|
|
Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2013-09-07 02:03:48 +08:00
|
|
|
case OMPC_shared:
|
|
|
|
Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-03-31 11:36:38 +08:00
|
|
|
case OMPC_copyin:
|
|
|
|
Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_if:
|
2014-03-06 14:15:19 +08:00
|
|
|
case OMPC_num_threads:
|
2014-03-21 12:51:18 +08:00
|
|
|
case OMPC_safelen:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_default:
|
|
|
|
case OMPC_threadprivate:
|
|
|
|
case OMPC_unknown:
|
|
|
|
case NUM_OPENMP_CLAUSES:
|
|
|
|
llvm_unreachable("Clause is not allowed.");
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
|
|
|
for (ArrayRef<Expr *>::iterator I = VarList.begin(), E = VarList.end();
|
|
|
|
I != E; ++I) {
|
2013-09-24 11:17:45 +08:00
|
|
|
assert(*I && "NULL expr in OpenMP private clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(*I)) {
|
2013-07-19 11:13:43 +08:00
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(*I);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation ELoc = (*I)->getExprLoc();
|
|
|
|
// OpenMP [2.1, C/C++]
|
|
|
|
// A list item is a variable name.
|
|
|
|
// OpenMP [2.9.3.3, Restrictions, p.1]
|
|
|
|
// A variable that is part of another variable (as an array or
|
|
|
|
// structure element) cannot appear in a private clause.
|
|
|
|
DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(*I);
|
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name)
|
|
|
|
<< (*I)->getSourceRange();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Decl *D = DE->getDecl();
|
|
|
|
VarDecl *VD = cast<VarDecl>(D);
|
|
|
|
|
|
|
|
QualType Type = VD->getType();
|
|
|
|
if (Type->isDependentType() || Type->isInstantiationDependentType()) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(DE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (RequireCompleteType(ELoc, Type,
|
|
|
|
diag::err_omp_private_incomplete_type)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Type->isReferenceType()) {
|
|
|
|
Diag(ELoc, diag::err_omp_clause_ref_type_arg)
|
|
|
|
<< getOpenMPClauseName(OMPC_private) << Type;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.3.3, Restrictions, C/C++, p.1]
|
|
|
|
// A variable of class type (or array thereof) that appears in a private
|
|
|
|
// clause requires an accesible, unambiguous default constructor for the
|
|
|
|
// class type.
|
|
|
|
while (Type.getNonReferenceType()->isArrayType()) {
|
|
|
|
Type = cast<ArrayType>(
|
|
|
|
Type.getNonReferenceType().getTypePtr())->getElementType();
|
|
|
|
}
|
|
|
|
CXXRecordDecl *RD = getLangOpts().CPlusPlus ?
|
|
|
|
Type.getNonReferenceType()->getAsCXXRecordDecl() : 0;
|
|
|
|
if (RD) {
|
|
|
|
CXXConstructorDecl *CD = LookupDefaultConstructor(RD);
|
|
|
|
PartialDiagnostic PD =
|
|
|
|
PartialDiagnostic(PartialDiagnostic::NullDiagnostic());
|
|
|
|
if (!CD ||
|
|
|
|
CheckConstructorAccess(ELoc, CD,
|
|
|
|
InitializedEntity::InitializeTemporary(Type),
|
|
|
|
CD->getAccess(), PD) == AR_inaccessible ||
|
|
|
|
CD->isDeleted()) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_method)
|
|
|
|
<< getOpenMPClauseName(OMPC_private) << 0;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
Diag(RD->getLocation(), diag::note_previous_decl) << RD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MarkFunctionReferenced(ELoc, CD);
|
|
|
|
DiagnoseUseOfDecl(CD, ELoc);
|
|
|
|
|
|
|
|
CXXDestructorDecl *DD = RD->getDestructor();
|
|
|
|
if (DD) {
|
|
|
|
if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible ||
|
|
|
|
DD->isDeleted()) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_method)
|
|
|
|
<< getOpenMPClauseName(OMPC_private) << 4;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
Diag(RD->getLocation(), diag::note_previous_decl) << RD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MarkFunctionReferenced(ELoc, DD);
|
|
|
|
DiagnoseUseOfDecl(DD, ELoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct]
|
|
|
|
// Variables with the predetermined data-sharing attributes may not be
|
|
|
|
// listed in data-sharing attributes clauses, except for the cases
|
|
|
|
// listed below. For these exceptions only, listing a predetermined
|
|
|
|
// variable in a data-sharing attribute clause is allowed and overrides
|
|
|
|
// the variable's predetermined data-sharing attributes.
|
|
|
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD);
|
|
|
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_private);
|
|
|
|
if (DVar.RefExpr) {
|
|
|
|
Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind);
|
|
|
|
} else {
|
|
|
|
Diag(VD->getLocation(), diag::note_omp_predetermined_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DSAStack->addDSA(VD, DE, OMPC_private);
|
2013-07-19 11:13:43 +08:00
|
|
|
Vars.push_back(DE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty()) return 0;
|
|
|
|
|
|
|
|
return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
|
|
|
|
}
|
|
|
|
|
2013-10-01 13:32:34 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
|
|
|
for (ArrayRef<Expr *>::iterator I = VarList.begin(), E = VarList.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
assert(*I && "NULL expr in OpenMP firstprivate clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(*I)) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(*I);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation ELoc = (*I)->getExprLoc();
|
|
|
|
// OpenMP [2.1, C/C++]
|
|
|
|
// A list item is a variable name.
|
|
|
|
// OpenMP [2.9.3.3, Restrictions, p.1]
|
|
|
|
// A variable that is part of another variable (as an array or
|
|
|
|
// structure element) cannot appear in a private clause.
|
|
|
|
DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(*I);
|
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name)
|
|
|
|
<< (*I)->getSourceRange();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Decl *D = DE->getDecl();
|
|
|
|
VarDecl *VD = cast<VarDecl>(D);
|
|
|
|
|
|
|
|
QualType Type = VD->getType();
|
|
|
|
if (Type->isDependentType() || Type->isInstantiationDependentType()) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(DE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if (RequireCompleteType(ELoc, Type,
|
|
|
|
diag::err_omp_firstprivate_incomplete_type)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Type->isReferenceType()) {
|
|
|
|
Diag(ELoc, diag::err_omp_clause_ref_type_arg)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate) << Type;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.3.4, Restrictions, C/C++, p.1]
|
|
|
|
// A variable of class type (or array thereof) that appears in a private
|
|
|
|
// clause requires an accesible, unambiguous copy constructor for the
|
|
|
|
// class type.
|
|
|
|
Type = Context.getBaseElementType(Type);
|
|
|
|
CXXRecordDecl *RD = getLangOpts().CPlusPlus ?
|
|
|
|
Type.getNonReferenceType()->getAsCXXRecordDecl() : 0;
|
|
|
|
if (RD) {
|
|
|
|
CXXConstructorDecl *CD = LookupCopyingConstructor(RD, 0);
|
|
|
|
PartialDiagnostic PD =
|
|
|
|
PartialDiagnostic(PartialDiagnostic::NullDiagnostic());
|
|
|
|
if (!CD ||
|
|
|
|
CheckConstructorAccess(ELoc, CD,
|
|
|
|
InitializedEntity::InitializeTemporary(Type),
|
|
|
|
CD->getAccess(), PD) == AR_inaccessible ||
|
|
|
|
CD->isDeleted()) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_method)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate) << 1;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
Diag(RD->getLocation(), diag::note_previous_decl) << RD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MarkFunctionReferenced(ELoc, CD);
|
|
|
|
DiagnoseUseOfDecl(CD, ELoc);
|
|
|
|
|
|
|
|
CXXDestructorDecl *DD = RD->getDestructor();
|
|
|
|
if (DD) {
|
|
|
|
if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible ||
|
|
|
|
DD->isDeleted()) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_method)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate) << 4;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
Diag(RD->getLocation(), diag::note_previous_decl) << RD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MarkFunctionReferenced(ELoc, DD);
|
|
|
|
DiagnoseUseOfDecl(DD, ELoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If StartLoc and EndLoc are invalid - this is an implicit firstprivate
|
|
|
|
// variable and it was checked already.
|
|
|
|
if (StartLoc.isValid() && EndLoc.isValid()) {
|
|
|
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD);
|
|
|
|
Type = Type.getNonReferenceType().getCanonicalType();
|
|
|
|
bool IsConstant = Type.isConstant(Context);
|
|
|
|
Type = Context.getBaseElementType(Type);
|
|
|
|
// OpenMP [2.4.13, Data-sharing Attribute Clauses]
|
|
|
|
// A list item that specifies a given variable may not appear in more
|
|
|
|
// than one clause on the same directive, except that a variable may be
|
|
|
|
// specified in both firstprivate and lastprivate clauses.
|
|
|
|
// TODO: add processing for lastprivate.
|
|
|
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate &&
|
|
|
|
DVar.RefExpr) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate);
|
|
|
|
Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct]
|
|
|
|
// Variables with the predetermined data-sharing attributes may not be
|
|
|
|
// listed in data-sharing attributes clauses, except for the cases
|
|
|
|
// listed below. For these exceptions only, listing a predetermined
|
|
|
|
// variable in a data-sharing attribute clause is allowed and overrides
|
|
|
|
// the variable's predetermined data-sharing attributes.
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, p.2]
|
|
|
|
// Variables with const-qualified type having no mutable member may be
|
|
|
|
// listed in a firstprivate clause, even if they are static data members.
|
|
|
|
if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr &&
|
|
|
|
DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate);
|
|
|
|
Diag(VD->getLocation(), diag::note_omp_predetermined_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.3.4, Restrictions, p.2]
|
|
|
|
// A list item that is private within a parallel region must not appear
|
|
|
|
// in a firstprivate clause on a worksharing construct if any of the
|
|
|
|
// worksharing regions arising from the worksharing construct ever bind
|
|
|
|
// to any of the parallel regions arising from the parallel construct.
|
|
|
|
// OpenMP [2.9.3.4, Restrictions, p.3]
|
|
|
|
// A list item that appears in a reduction clause of a parallel construct
|
|
|
|
// must not appear in a firstprivate clause on a worksharing or task
|
|
|
|
// construct if any of the worksharing or task regions arising from the
|
|
|
|
// worksharing or task construct ever bind to any of the parallel regions
|
|
|
|
// arising from the parallel construct.
|
|
|
|
// OpenMP [2.9.3.4, Restrictions, p.4]
|
|
|
|
// A list item that appears in a reduction clause in worksharing
|
|
|
|
// construct must not appear in a firstprivate clause in a task construct
|
|
|
|
// encountered during execution of any of the worksharing regions arising
|
|
|
|
// from the worksharing construct.
|
|
|
|
// TODO:
|
|
|
|
}
|
|
|
|
|
|
|
|
DSAStack->addDSA(VD, DE, OMPC_firstprivate);
|
|
|
|
Vars.push_back(DE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty()) return 0;
|
|
|
|
|
|
|
|
return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc,
|
|
|
|
Vars);
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
|
|
|
for (ArrayRef<Expr *>::iterator I = VarList.begin(), E = VarList.end();
|
|
|
|
I != E; ++I) {
|
2013-09-24 11:17:45 +08:00
|
|
|
assert(*I && "NULL expr in OpenMP shared clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(*I)) {
|
2013-09-07 02:03:48 +08:00
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(*I);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation ELoc = (*I)->getExprLoc();
|
|
|
|
// OpenMP [2.1, C/C++]
|
|
|
|
// A list item is a variable name.
|
2014-03-06 20:27:56 +08:00
|
|
|
// OpenMP [2.14.3.2, Restrictions, p.1]
|
|
|
|
// A variable that is part of another variable (as an array or structure
|
|
|
|
// element) cannot appear in a shared unless it is a static data member
|
|
|
|
// of a C++ class.
|
2013-09-07 02:03:48 +08:00
|
|
|
DeclRefExpr *DE = dyn_cast<DeclRefExpr>(*I);
|
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name)
|
|
|
|
<< (*I)->getSourceRange();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Decl *D = DE->getDecl();
|
|
|
|
VarDecl *VD = cast<VarDecl>(D);
|
|
|
|
|
|
|
|
QualType Type = VD->getType();
|
|
|
|
if (Type->isDependentType() || Type->isInstantiationDependentType()) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(DE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct]
|
|
|
|
// Variables with the predetermined data-sharing attributes may not be
|
|
|
|
// listed in data-sharing attributes clauses, except for the cases
|
|
|
|
// listed below. For these exceptions only, listing a predetermined
|
|
|
|
// variable in a data-sharing attribute clause is allowed and overrides
|
|
|
|
// the variable's predetermined data-sharing attributes.
|
|
|
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD);
|
|
|
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && DVar.RefExpr) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_shared);
|
|
|
|
Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DSAStack->addDSA(VD, DE, OMPC_shared);
|
|
|
|
Vars.push_back(DE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty()) return 0;
|
|
|
|
|
|
|
|
return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
|
|
|
|
}
|
|
|
|
|
2014-03-31 11:36:38 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
|
|
|
for (ArrayRef<Expr *>::iterator I = VarList.begin(), E = VarList.end();
|
|
|
|
I != E; ++I) {
|
|
|
|
assert(*I && "NULL expr in OpenMP copyin clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(*I)) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(*I);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation ELoc = (*I)->getExprLoc();
|
|
|
|
// OpenMP [2.1, C/C++]
|
|
|
|
// A list item is a variable name.
|
|
|
|
// OpenMP [2.14.4.1, Restrictions, p.1]
|
|
|
|
// A list item that appears in a copyin clause must be threadprivate.
|
|
|
|
DeclRefExpr *DE = dyn_cast<DeclRefExpr>(*I);
|
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name)
|
|
|
|
<< (*I)->getSourceRange();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Decl *D = DE->getDecl();
|
|
|
|
VarDecl *VD = cast<VarDecl>(D);
|
|
|
|
|
|
|
|
QualType Type = VD->getType();
|
|
|
|
if (Type->isDependentType() || Type->isInstantiationDependentType()) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(DE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.14.4.1, Restrictions, C/C++, p.1]
|
|
|
|
// A list item that appears in a copyin clause must be threadprivate.
|
|
|
|
if (!DSAStack->isThreadPrivate(VD)) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_access)
|
|
|
|
<< getOpenMPClauseName(OMPC_copyin)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.14.4.1, Restrictions, C/C++, p.2]
|
|
|
|
// A variable of class type (or array thereof) that appears in a
|
|
|
|
// copyin clause requires an accesible, unambiguous copy assignment
|
|
|
|
// operator for the class type.
|
|
|
|
Type = Context.getBaseElementType(Type);
|
|
|
|
CXXRecordDecl *RD = getLangOpts().CPlusPlus ?
|
|
|
|
Type->getAsCXXRecordDecl() : 0;
|
|
|
|
if (RD) {
|
|
|
|
CXXMethodDecl *MD = LookupCopyingAssignment(RD, 0, false, 0);
|
|
|
|
DeclAccessPair FoundDecl = DeclAccessPair::make(MD, MD->getAccess());
|
|
|
|
if (!MD ||
|
|
|
|
CheckMemberAccess(ELoc, RD, FoundDecl) == AR_inaccessible ||
|
|
|
|
MD->isDeleted()) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_method)
|
|
|
|
<< getOpenMPClauseName(OMPC_copyin) << 2;
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl :
|
|
|
|
diag::note_defined_here) << VD;
|
|
|
|
Diag(RD->getLocation(), diag::note_previous_decl) << RD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
MarkFunctionReferenced(ELoc, MD);
|
|
|
|
DiagnoseUseOfDecl(MD, ELoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
DSAStack->addDSA(VD, DE, OMPC_copyin);
|
|
|
|
Vars.push_back(DE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty()) return 0;
|
|
|
|
|
|
|
|
return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
#undef DSAStack
|