2014-05-06 18:08:46 +08:00
|
|
|
//===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===//
|
2013-03-22 14:34:35 +08:00
|
|
|
//
|
|
|
|
// 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
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-08-14 20:25:37 +08:00
|
|
|
#include "TreeTransform.h"
|
2014-05-06 18:08:46 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2014-11-11 12:05:39 +08:00
|
|
|
#include "clang/AST/ASTMutationListener.h"
|
2013-03-22 14:34:35 +08:00
|
|
|
#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"
|
2014-05-06 18:08:46 +08:00
|
|
|
#include "clang/Basic/OpenMPKinds.h"
|
2015-07-14 06:54:53 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2014-05-06 18:08:46 +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 {
|
2014-05-28 13:53:51 +08:00
|
|
|
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'.
|
2013-09-07 02:03:48 +08:00
|
|
|
};
|
2014-06-19 17:13:45 +08:00
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
template <class T> struct MatchesAny {
|
2014-06-18 15:08:49 +08:00
|
|
|
explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {}
|
2014-06-18 12:14:57 +08:00
|
|
|
bool operator()(T Kind) {
|
|
|
|
for (auto KindEl : Arr)
|
|
|
|
if (KindEl == Kind)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ArrayRef<T> Arr;
|
|
|
|
};
|
2014-06-18 15:08:49 +08:00
|
|
|
struct MatchesAlways {
|
2014-06-18 12:14:57 +08:00
|
|
|
MatchesAlways() {}
|
2014-06-19 17:13:45 +08:00
|
|
|
template <class T> bool operator()(T) { return true; }
|
2014-06-18 12:14:57 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause;
|
|
|
|
typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective;
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
/// \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;
|
2014-06-27 18:37:06 +08:00
|
|
|
SourceLocation ImplicitDSALoc;
|
|
|
|
DSAVarData()
|
|
|
|
: DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr),
|
|
|
|
ImplicitDSALoc() {}
|
2013-09-07 02:03:48 +08:00
|
|
|
};
|
2014-05-28 13:53:51 +08:00
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
private:
|
|
|
|
struct DSAInfo {
|
|
|
|
OpenMPClauseKind Attributes;
|
|
|
|
DeclRefExpr *RefExpr;
|
|
|
|
};
|
|
|
|
typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy;
|
2014-05-29 22:36:25 +08:00
|
|
|
typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy;
|
2015-04-30 12:23:23 +08:00
|
|
|
typedef llvm::DenseSet<VarDecl *> LoopControlVariablesSetTy;
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
struct SharingMapTy {
|
|
|
|
DeclSAMapTy SharingMap;
|
2014-05-29 22:36:25 +08:00
|
|
|
AlignedMapTy AlignedMap;
|
2015-04-30 12:23:23 +08:00
|
|
|
LoopControlVariablesSetTy LCVSet;
|
2013-09-07 02:03:48 +08:00
|
|
|
DefaultDataSharingAttributes DefaultAttr;
|
2014-06-27 18:37:06 +08:00
|
|
|
SourceLocation DefaultAttrLoc;
|
2013-09-07 02:03:48 +08:00
|
|
|
OpenMPDirectiveKind Directive;
|
|
|
|
DeclarationNameInfo DirectiveName;
|
|
|
|
Scope *CurScope;
|
2014-06-27 18:37:06 +08:00
|
|
|
SourceLocation ConstructLoc;
|
2015-09-25 18:37:12 +08:00
|
|
|
/// \brief first argument (Expr *) contains optional argument of the
|
|
|
|
/// 'ordered' clause, the second one is true if the regions has 'ordered'
|
|
|
|
/// clause, false otherwise.
|
|
|
|
llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion;
|
2015-07-01 14:57:41 +08:00
|
|
|
bool NowaitRegion;
|
2015-09-15 20:52:43 +08:00
|
|
|
bool CancelRegion;
|
2015-04-30 12:23:23 +08:00
|
|
|
unsigned CollapseNumber;
|
2014-10-09 12:18:56 +08:00
|
|
|
SourceLocation InnerTeamsRegionLoc;
|
2014-05-28 13:53:51 +08:00
|
|
|
SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name,
|
2014-06-27 18:37:06 +08:00
|
|
|
Scope *CurScope, SourceLocation Loc)
|
2015-04-30 12:23:23 +08:00
|
|
|
: SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified),
|
2014-06-27 18:37:06 +08:00
|
|
|
Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope),
|
2015-09-25 18:37:12 +08:00
|
|
|
ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false),
|
2015-09-15 20:52:43 +08:00
|
|
|
CancelRegion(false), CollapseNumber(1), InnerTeamsRegionLoc() {}
|
2013-09-07 02:03:48 +08:00
|
|
|
SharingMapTy()
|
2015-04-30 12:23:23 +08:00
|
|
|
: SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified),
|
2014-06-27 18:37:06 +08:00
|
|
|
Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr),
|
2015-09-25 18:37:12 +08:00
|
|
|
ConstructLoc(), OrderedRegion(), NowaitRegion(false),
|
2015-09-15 20:52:43 +08:00
|
|
|
CancelRegion(false), CollapseNumber(1), InnerTeamsRegionLoc() {}
|
2013-09-07 02:03:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef SmallVector<SharingMapTy, 64> StackTy;
|
|
|
|
|
|
|
|
/// \brief Stack of used declaration and their data-sharing attributes.
|
|
|
|
StackTy Stack;
|
2015-05-08 18:41:21 +08:00
|
|
|
/// \brief true, if check for DSA must be from parent directive, false, if
|
|
|
|
/// from current directive.
|
2015-06-23 12:51:00 +08:00
|
|
|
OpenMPClauseKind ClauseKindMode;
|
2014-06-19 17:13:45 +08:00
|
|
|
Sema &SemaRef;
|
2015-07-28 00:38:06 +08:00
|
|
|
bool ForceCapturing;
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
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);
|
2014-05-28 13:53:51 +08:00
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
public:
|
2015-06-23 12:51:00 +08:00
|
|
|
explicit DSAStackTy(Sema &S)
|
2015-07-28 00:38:06 +08:00
|
|
|
: Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S),
|
|
|
|
ForceCapturing(false) {}
|
2015-05-08 18:41:21 +08:00
|
|
|
|
2015-06-23 12:51:00 +08:00
|
|
|
bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; }
|
|
|
|
void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; }
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2015-07-28 00:38:06 +08:00
|
|
|
bool isForceVarCapturing() const { return ForceCapturing; }
|
|
|
|
void setForceVarCapturing(bool V) { ForceCapturing = V; }
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName,
|
2014-06-27 18:37:06 +08:00
|
|
|
Scope *CurScope, SourceLocation Loc) {
|
|
|
|
Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc));
|
|
|
|
Stack.back().DefaultAttrLoc = Loc;
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void pop() {
|
|
|
|
assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!");
|
|
|
|
Stack.pop_back();
|
|
|
|
}
|
|
|
|
|
2014-05-29 22:36:25 +08:00
|
|
|
/// \brief If 'aligned' declaration for given variable \a D was not seen yet,
|
2014-06-06 20:02:07 +08:00
|
|
|
/// add it and return NULL; otherwise return previous occurrence's expression
|
2014-05-29 22:36:25 +08:00
|
|
|
/// for diagnostics.
|
|
|
|
DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE);
|
|
|
|
|
2015-04-30 12:23:23 +08:00
|
|
|
/// \brief Register specified variable as loop control variable.
|
|
|
|
void addLoopControlVariable(VarDecl *D);
|
|
|
|
/// \brief Check if the specified variable is a loop control variable for
|
|
|
|
/// current region.
|
|
|
|
bool isLoopControlVariable(VarDecl *D);
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
/// \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.
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAVarData getTopDSA(VarDecl *D, bool FromParent);
|
2013-09-07 02:03:48 +08:00
|
|
|
/// \brief Returns data-sharing attributes for the specified declaration.
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAVarData getImplicitDSA(VarDecl *D, bool FromParent);
|
2014-06-18 12:14:57 +08:00
|
|
|
/// \brief Checks if the specified variables has data-sharing attributes which
|
|
|
|
/// match specified \a CPred predicate in any directive which matches \a DPred
|
|
|
|
/// predicate.
|
|
|
|
template <class ClausesPredicate, class DirectivesPredicate>
|
|
|
|
DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred,
|
2014-07-11 19:25:16 +08:00
|
|
|
DirectivesPredicate DPred, bool FromParent);
|
2014-06-18 12:14:57 +08:00
|
|
|
/// \brief Checks if the specified variables has data-sharing attributes which
|
|
|
|
/// match specified \a CPred predicate in any innermost directive which
|
|
|
|
/// matches \a DPred predicate.
|
|
|
|
template <class ClausesPredicate, class DirectivesPredicate>
|
|
|
|
DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred,
|
2014-07-11 19:25:16 +08:00
|
|
|
DirectivesPredicate DPred,
|
|
|
|
bool FromParent);
|
2015-06-23 12:51:00 +08:00
|
|
|
/// \brief Checks if the specified variables has explicit data-sharing
|
|
|
|
/// attributes which match specified \a CPred predicate at the specified
|
|
|
|
/// OpenMP region.
|
|
|
|
bool hasExplicitDSA(VarDecl *D,
|
|
|
|
const llvm::function_ref<bool(OpenMPClauseKind)> &CPred,
|
|
|
|
unsigned Level);
|
2014-07-21 17:42:05 +08:00
|
|
|
/// \brief Finds a directive which matches specified \a DPred predicate.
|
|
|
|
template <class NamedDirectivesPredicate>
|
|
|
|
bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent);
|
2013-10-01 13:32:34 +08:00
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
/// \brief Returns currently analyzed directive.
|
|
|
|
OpenMPDirectiveKind getCurrentDirective() const {
|
|
|
|
return Stack.back().Directive;
|
|
|
|
}
|
2014-06-24 12:39:47 +08:00
|
|
|
/// \brief Returns parent directive.
|
|
|
|
OpenMPDirectiveKind getParentDirective() const {
|
|
|
|
if (Stack.size() > 2)
|
|
|
|
return Stack[Stack.size() - 2].Directive;
|
|
|
|
return OMPD_unknown;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
/// \brief Set default data sharing attribute to none.
|
2014-06-27 18:37:06 +08:00
|
|
|
void setDefaultDSANone(SourceLocation Loc) {
|
|
|
|
Stack.back().DefaultAttr = DSA_none;
|
|
|
|
Stack.back().DefaultAttrLoc = Loc;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
/// \brief Set default data sharing attribute to shared.
|
2014-06-27 18:37:06 +08:00
|
|
|
void setDefaultDSAShared(SourceLocation Loc) {
|
|
|
|
Stack.back().DefaultAttr = DSA_shared;
|
|
|
|
Stack.back().DefaultAttrLoc = Loc;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
DefaultDataSharingAttributes getDefaultDSA() const {
|
|
|
|
return Stack.back().DefaultAttr;
|
|
|
|
}
|
2014-06-27 18:37:06 +08:00
|
|
|
SourceLocation getDefaultDSALocation() const {
|
|
|
|
return Stack.back().DefaultAttrLoc;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
/// \brief Checks if the specified variable is a threadprivate.
|
2014-03-31 11:36:38 +08:00
|
|
|
bool isThreadPrivate(VarDecl *D) {
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAVarData DVar = getTopDSA(D, false);
|
2014-06-18 12:14:57 +08:00
|
|
|
return isOpenMPThreadPrivate(DVar.CKind);
|
2014-03-31 11:36:38 +08:00
|
|
|
}
|
|
|
|
|
2014-07-22 14:45:04 +08:00
|
|
|
/// \brief Marks current region as ordered (it has an 'ordered' clause).
|
2015-09-25 18:37:12 +08:00
|
|
|
void setOrderedRegion(bool IsOrdered, Expr *Param) {
|
|
|
|
Stack.back().OrderedRegion.setInt(IsOrdered);
|
|
|
|
Stack.back().OrderedRegion.setPointer(Param);
|
2014-07-22 14:45:04 +08:00
|
|
|
}
|
|
|
|
/// \brief Returns true, if parent region is ordered (has associated
|
|
|
|
/// 'ordered' clause), false - otherwise.
|
|
|
|
bool isParentOrderedRegion() const {
|
|
|
|
if (Stack.size() > 2)
|
2015-09-25 18:37:12 +08:00
|
|
|
return Stack[Stack.size() - 2].OrderedRegion.getInt();
|
2014-07-22 14:45:04 +08:00
|
|
|
return false;
|
|
|
|
}
|
2015-09-25 18:37:12 +08:00
|
|
|
/// \brief Returns optional parameter for the ordered region.
|
|
|
|
Expr *getParentOrderedRegionParam() const {
|
|
|
|
if (Stack.size() > 2)
|
|
|
|
return Stack[Stack.size() - 2].OrderedRegion.getPointer();
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-07-01 14:57:41 +08:00
|
|
|
/// \brief Marks current region as nowait (it has a 'nowait' clause).
|
|
|
|
void setNowaitRegion(bool IsNowait = true) {
|
|
|
|
Stack.back().NowaitRegion = IsNowait;
|
|
|
|
}
|
|
|
|
/// \brief Returns true, if parent region is nowait (has associated
|
|
|
|
/// 'nowait' clause), false - otherwise.
|
|
|
|
bool isParentNowaitRegion() const {
|
|
|
|
if (Stack.size() > 2)
|
|
|
|
return Stack[Stack.size() - 2].NowaitRegion;
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-15 20:52:43 +08:00
|
|
|
/// \brief Marks parent region as cancel region.
|
|
|
|
void setParentCancelRegion(bool Cancel = true) {
|
|
|
|
if (Stack.size() > 2)
|
|
|
|
Stack[Stack.size() - 2].CancelRegion =
|
|
|
|
Stack[Stack.size() - 2].CancelRegion || Cancel;
|
|
|
|
}
|
|
|
|
/// \brief Return true if current region has inner cancel construct.
|
|
|
|
bool isCancelRegion() const {
|
|
|
|
return Stack.back().CancelRegion;
|
|
|
|
}
|
2014-07-22 14:45:04 +08:00
|
|
|
|
2015-04-30 12:23:23 +08:00
|
|
|
/// \brief Set collapse value for the region.
|
|
|
|
void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; }
|
|
|
|
/// \brief Return collapse value for region.
|
|
|
|
unsigned getCollapseNumber() const {
|
|
|
|
return Stack.back().CollapseNumber;
|
|
|
|
}
|
|
|
|
|
2014-10-09 12:18:56 +08:00
|
|
|
/// \brief Marks current target region as one with closely nested teams
|
|
|
|
/// region.
|
|
|
|
void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) {
|
|
|
|
if (Stack.size() > 2)
|
|
|
|
Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc;
|
|
|
|
}
|
|
|
|
/// \brief Returns true, if current region has closely nested teams region.
|
|
|
|
bool hasInnerTeamsRegion() const {
|
|
|
|
return getInnerTeamsRegionLoc().isValid();
|
|
|
|
}
|
|
|
|
/// \brief Returns location of the nested teams region (if any).
|
|
|
|
SourceLocation getInnerTeamsRegionLoc() const {
|
|
|
|
if (Stack.size() > 1)
|
|
|
|
return Stack.back().InnerTeamsRegionLoc;
|
|
|
|
return SourceLocation();
|
|
|
|
}
|
|
|
|
|
2014-03-31 11:36:38 +08:00
|
|
|
Scope *getCurScope() const { return Stack.back().CurScope; }
|
2013-09-07 02:03:48 +08:00
|
|
|
Scope *getCurScope() { return Stack.back().CurScope; }
|
2014-06-27 18:37:06 +08:00
|
|
|
SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; }
|
2013-09-07 02:03:48 +08:00
|
|
|
};
|
2014-07-11 19:25:16 +08:00
|
|
|
bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) {
|
|
|
|
return isOpenMPParallelDirective(DKind) || DKind == OMPD_task ||
|
2014-10-09 12:18:56 +08:00
|
|
|
isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown;
|
2014-07-11 19:25:16 +08:00
|
|
|
}
|
2014-05-28 13:53:51 +08:00
|
|
|
} // namespace
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter,
|
|
|
|
VarDecl *D) {
|
2015-04-16 21:49:42 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2013-09-07 02:03:48 +08:00
|
|
|
DSAVarData DVar;
|
2014-06-25 12:09:13 +08:00
|
|
|
if (Iter == std::prev(Stack.rend())) {
|
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.
|
2014-07-24 10:33:58 +08:00
|
|
|
if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D))
|
2014-03-18 20:19:12 +08:00
|
|
|
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.
|
2014-06-18 12:14:57 +08:00
|
|
|
if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() &&
|
|
|
|
(D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) {
|
|
|
|
DVar.CKind = OMPC_private;
|
|
|
|
return DVar;
|
2014-01-31 13:15:34 +08:00
|
|
|
}
|
|
|
|
|
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;
|
2014-07-11 19:25:16 +08:00
|
|
|
DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
|
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, 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;
|
2014-06-27 18:37:06 +08:00
|
|
|
DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
|
2013-09-07 02:03:48 +08:00
|
|
|
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.
|
2014-06-27 18:37:06 +08:00
|
|
|
DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;
|
2014-10-09 12:18:56 +08:00
|
|
|
if (isOpenMPParallelDirective(DVar.DKind) ||
|
|
|
|
isOpenMPTeamsDirective(DVar.DKind)) {
|
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, 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.
|
|
|
|
if (DVar.DKind == OMPD_task) {
|
|
|
|
DSAVarData DVarTemp;
|
[OPENMP] Initial codegen for 'omp task' directive.
The task region is emmitted in several steps:
Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, kmp_routine_entry_t *task_entry).
Here task_entry is a pointer to the function:
kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
TaskFunction(gtid, tt->part_id, tt->shareds);
return 0;
}
Copy a list of shared variables to field shareds of the resulting structure kmp_task_t returned by the previous call (if any).
Copy a pointer to destructions function to field destructions of the resulting structure kmp_task_t.
Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *new_task), where new_task is a resulting structure from previous items.
Differential Revision: http://reviews.llvm.org/D7560
llvm-svn: 231762
2015-03-10 15:28:44 +08:00
|
|
|
for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend();
|
2013-09-07 02:03:48 +08:00
|
|
|
I != EE; ++I) {
|
2014-05-28 13:53:51 +08:00
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables
|
|
|
|
// Referenced
|
2013-09-07 02:03:48 +08:00
|
|
|
// 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) {
|
2014-05-15 21:04:49 +08:00
|
|
|
DVar.RefExpr = nullptr;
|
2013-09-07 02:03:48 +08:00
|
|
|
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;
|
|
|
|
}
|
2014-07-11 19:25:16 +08:00
|
|
|
if (isParallelOrTaskRegion(I->Directive))
|
2014-05-28 13:53:51 +08:00
|
|
|
break;
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
DVar.DKind = OMPD_task;
|
|
|
|
DVar.CKind =
|
2014-05-28 13:53:51 +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
|
|
|
}
|
|
|
|
|
2014-05-29 22:36:25 +08:00
|
|
|
DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) {
|
|
|
|
assert(Stack.size() > 1 && "Data sharing attributes stack is empty");
|
2015-04-16 21:49:42 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2014-05-29 22:36:25 +08:00
|
|
|
auto It = Stack.back().AlignedMap.find(D);
|
|
|
|
if (It == Stack.back().AlignedMap.end()) {
|
|
|
|
assert(NewDE && "Unexpected nullptr expr to be added into aligned map");
|
|
|
|
Stack.back().AlignedMap[D] = NewDE;
|
|
|
|
return nullptr;
|
|
|
|
} else {
|
|
|
|
assert(It->second && "Unexpected nullptr expr in the aligned map");
|
|
|
|
return It->second;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-30 12:23:23 +08:00
|
|
|
void DSAStackTy::addLoopControlVariable(VarDecl *D) {
|
|
|
|
assert(Stack.size() > 1 && "Data-sharing attributes stack is empty");
|
|
|
|
D = D->getCanonicalDecl();
|
|
|
|
Stack.back().LCVSet.insert(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DSAStackTy::isLoopControlVariable(VarDecl *D) {
|
|
|
|
assert(Stack.size() > 1 && "Data-sharing attributes stack is empty");
|
|
|
|
D = D->getCanonicalDecl();
|
|
|
|
return Stack.back().LCVSet.count(D) > 0;
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) {
|
2015-04-16 21:49:42 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2013-09-07 02:03:48 +08:00
|
|
|
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-05-28 13:53:51 +08:00
|
|
|
bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) {
|
2015-04-16 21:49:42 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2014-01-31 13:15:34 +08:00
|
|
|
if (Stack.size() > 2) {
|
2014-06-18 12:14:57 +08:00
|
|
|
reverse_iterator I = Iter, E = std::prev(Stack.rend());
|
2014-05-15 21:04:49 +08:00
|
|
|
Scope *TopScope = nullptr;
|
2014-07-11 19:25:16 +08:00
|
|
|
while (I != E && !isParallelOrTaskRegion(I->Directive)) {
|
2014-01-31 13:15:34 +08:00
|
|
|
++I;
|
|
|
|
}
|
2014-05-28 13:53:51 +08:00
|
|
|
if (I == E)
|
|
|
|
return false;
|
2014-05-15 21:04:49 +08:00
|
|
|
TopScope = I->CurScope ? I->CurScope->getParent() : nullptr;
|
2014-01-31 13:15:34 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-08 18:41:21 +08:00
|
|
|
/// \brief Build a variable declaration for OpenMP loop iteration variable.
|
|
|
|
static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type,
|
2015-09-10 17:48:30 +08:00
|
|
|
StringRef Name, const AttrVec *Attrs = nullptr) {
|
2015-05-08 18:41:21 +08:00
|
|
|
DeclContext *DC = SemaRef.CurContext;
|
|
|
|
IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name);
|
|
|
|
TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc);
|
|
|
|
VarDecl *Decl =
|
|
|
|
VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None);
|
2015-09-10 17:48:30 +08:00
|
|
|
if (Attrs) {
|
|
|
|
for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end());
|
|
|
|
I != E; ++I)
|
|
|
|
Decl->addAttr(*I);
|
|
|
|
}
|
2015-05-08 18:41:21 +08:00
|
|
|
Decl->setImplicit();
|
|
|
|
return Decl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty,
|
|
|
|
SourceLocation Loc,
|
|
|
|
bool RefersToCapture = false) {
|
|
|
|
D->setReferenced();
|
|
|
|
D->markUsed(S.Context);
|
|
|
|
return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(),
|
|
|
|
SourceLocation(), D, RefersToCapture, Loc, Ty,
|
|
|
|
VK_LValue);
|
|
|
|
}
|
|
|
|
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) {
|
2015-04-16 21:49:42 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2013-09-07 02:03:48 +08:00
|
|
|
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.
|
2015-07-14 06:54:53 +08:00
|
|
|
if ((D->getTLSKind() != VarDecl::TLS_None &&
|
|
|
|
!(D->hasAttr<OMPThreadPrivateDeclAttr>() &&
|
|
|
|
SemaRef.getLangOpts().OpenMPUseTLS &&
|
|
|
|
SemaRef.getASTContext().getTargetInfo().isTLSSupported())) ||
|
2015-05-06 14:34:55 +08:00
|
|
|
(D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() &&
|
|
|
|
!D->isLocalVarDecl())) {
|
2015-05-08 18:41:21 +08:00
|
|
|
addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(),
|
|
|
|
D->getLocation()),
|
2015-05-06 15:25:08 +08:00
|
|
|
OMPC_threadprivate);
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
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-07-11 19:25:16 +08:00
|
|
|
OpenMPDirectiveKind Kind =
|
|
|
|
FromParent ? getParentDirective() : getCurrentDirective();
|
|
|
|
auto StartI = std::next(Stack.rbegin());
|
|
|
|
auto EndI = std::prev(Stack.rend());
|
|
|
|
if (FromParent && StartI != EndI) {
|
|
|
|
StartI = std::next(StartI);
|
|
|
|
}
|
|
|
|
if (!isParallelOrTaskRegion(Kind)) {
|
2014-07-24 10:33:58 +08:00
|
|
|
if (isOpenMPLocal(D, StartI) &&
|
|
|
|
((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto ||
|
|
|
|
D->getStorageClass() == SC_None)) ||
|
|
|
|
isa<ParmVarDecl>(D))) {
|
2014-01-31 13:15:34 +08:00
|
|
|
DVar.CKind = OMPC_private;
|
|
|
|
return DVar;
|
2014-04-22 21:09:42 +08:00
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2015-01-16 15:11:33 +08:00
|
|
|
// OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
|
|
|
|
// in a Construct, C/C++, predetermined, p.4]
|
|
|
|
// Static data members are shared.
|
|
|
|
// 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.
|
2015-09-16 02:56:58 +08:00
|
|
|
if (D->isStaticDataMember()) {
|
2015-01-20 15:03:46 +08:00
|
|
|
DSAVarData DVarTemp =
|
|
|
|
hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent);
|
|
|
|
if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr)
|
|
|
|
return DVar;
|
|
|
|
|
2015-01-16 15:11:33 +08:00
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
return DVar;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QualType Type = D->getType().getNonReferenceType().getCanonicalType();
|
2015-05-19 15:46:42 +08:00
|
|
|
bool IsConstant = Type.isConstant(SemaRef.getASTContext());
|
|
|
|
Type = SemaRef.getASTContext().getBaseElementType(Type);
|
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.6]
|
|
|
|
// Variables with const qualified type having no mutable member are
|
|
|
|
// shared.
|
2014-05-15 21:04:49 +08:00
|
|
|
CXXRecordDecl *RD =
|
2014-06-19 17:13:45 +08:00
|
|
|
SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr;
|
2013-09-07 02:03:48 +08:00
|
|
|
if (IsConstant &&
|
2014-06-19 17:13:45 +08:00
|
|
|
!(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) {
|
2013-09-07 02:03:48 +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.
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate),
|
|
|
|
MatchesAlways(), FromParent);
|
2013-10-01 13:32:34 +08:00
|
|
|
if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr)
|
|
|
|
return DVar;
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
DVar.CKind = OMPC_shared;
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Explicitly specified attributes and local variables with predetermined
|
|
|
|
// attributes.
|
2014-07-11 19:25:16 +08:00
|
|
|
auto I = std::prev(StartI);
|
|
|
|
if (I->SharingMap.count(D)) {
|
|
|
|
DVar.RefExpr = I->SharingMap[D].RefExpr;
|
|
|
|
DVar.CKind = I->SharingMap[D].Attributes;
|
|
|
|
DVar.ImplicitDSALoc = I->DefaultAttrLoc;
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) {
|
2015-04-16 21:49:42 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2014-07-11 19:25:16 +08:00
|
|
|
auto StartI = Stack.rbegin();
|
|
|
|
auto EndI = std::prev(Stack.rend());
|
|
|
|
if (FromParent && StartI != EndI) {
|
|
|
|
StartI = std::next(StartI);
|
|
|
|
}
|
|
|
|
return getDSA(StartI, D);
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
template <class ClausesPredicate, class DirectivesPredicate>
|
|
|
|
DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred,
|
2014-07-11 19:25:16 +08:00
|
|
|
DirectivesPredicate DPred,
|
|
|
|
bool FromParent) {
|
2015-04-16 21:49:42 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2014-07-11 19:25:16 +08:00
|
|
|
auto StartI = std::next(Stack.rbegin());
|
|
|
|
auto EndI = std::prev(Stack.rend());
|
|
|
|
if (FromParent && StartI != EndI) {
|
|
|
|
StartI = std::next(StartI);
|
|
|
|
}
|
|
|
|
for (auto I = StartI, EE = EndI; I != EE; ++I) {
|
|
|
|
if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive))
|
2014-05-28 13:53:51 +08:00
|
|
|
continue;
|
2013-10-01 13:32:34 +08:00
|
|
|
DSAVarData DVar = getDSA(I, D);
|
2014-06-18 12:14:57 +08:00
|
|
|
if (CPred(DVar.CKind))
|
2013-10-01 13:32:34 +08:00
|
|
|
return DVar;
|
|
|
|
}
|
|
|
|
return DSAVarData();
|
|
|
|
}
|
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
template <class ClausesPredicate, class DirectivesPredicate>
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData
|
|
|
|
DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred,
|
|
|
|
DirectivesPredicate DPred, bool FromParent) {
|
2015-04-16 21:49:42 +08:00
|
|
|
D = D->getCanonicalDecl();
|
2014-07-11 19:25:16 +08:00
|
|
|
auto StartI = std::next(Stack.rbegin());
|
|
|
|
auto EndI = std::prev(Stack.rend());
|
|
|
|
if (FromParent && StartI != EndI) {
|
|
|
|
StartI = std::next(StartI);
|
|
|
|
}
|
|
|
|
for (auto I = StartI, EE = EndI; I != EE; ++I) {
|
2014-06-18 12:14:57 +08:00
|
|
|
if (!DPred(I->Directive))
|
2014-07-11 19:25:16 +08:00
|
|
|
break;
|
2014-06-16 15:08:35 +08:00
|
|
|
DSAVarData DVar = getDSA(I, D);
|
2014-06-18 12:14:57 +08:00
|
|
|
if (CPred(DVar.CKind))
|
2014-06-16 15:08:35 +08:00
|
|
|
return DVar;
|
|
|
|
return DSAVarData();
|
|
|
|
}
|
|
|
|
return DSAVarData();
|
|
|
|
}
|
|
|
|
|
2015-06-23 12:51:00 +08:00
|
|
|
bool DSAStackTy::hasExplicitDSA(
|
|
|
|
VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred,
|
|
|
|
unsigned Level) {
|
|
|
|
if (CPred(ClauseKindMode))
|
|
|
|
return true;
|
|
|
|
if (isClauseParsingMode())
|
|
|
|
++Level;
|
|
|
|
D = D->getCanonicalDecl();
|
|
|
|
auto StartI = Stack.rbegin();
|
|
|
|
auto EndI = std::prev(Stack.rend());
|
2015-06-23 18:01:20 +08:00
|
|
|
if (std::distance(StartI, EndI) <= (int)Level)
|
2015-06-23 12:51:00 +08:00
|
|
|
return false;
|
|
|
|
std::advance(StartI, Level);
|
|
|
|
return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr &&
|
|
|
|
CPred(StartI->SharingMap[D].Attributes);
|
|
|
|
}
|
|
|
|
|
2014-07-21 17:42:05 +08:00
|
|
|
template <class NamedDirectivesPredicate>
|
|
|
|
bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) {
|
|
|
|
auto StartI = std::next(Stack.rbegin());
|
|
|
|
auto EndI = std::prev(Stack.rend());
|
|
|
|
if (FromParent && StartI != EndI) {
|
|
|
|
StartI = std::next(StartI);
|
|
|
|
}
|
|
|
|
for (auto I = StartI, EE = EndI; I != EE; ++I) {
|
|
|
|
if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
void Sema::InitDataSharingAttributesStack() {
|
|
|
|
VarDataSharingAttributesStack = new DSAStackTy(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack)
|
|
|
|
|
2014-12-16 15:00:22 +08:00
|
|
|
bool Sema::IsOpenMPCapturedVar(VarDecl *VD) {
|
|
|
|
assert(LangOpts.OpenMP && "OpenMP is not allowed");
|
2015-04-16 21:49:42 +08:00
|
|
|
VD = VD->getCanonicalDecl();
|
2015-08-04 16:10:48 +08:00
|
|
|
if (DSAStack->getCurrentDirective() != OMPD_unknown &&
|
|
|
|
(!DSAStack->isClauseParsingMode() ||
|
|
|
|
DSAStack->getParentDirective() != OMPD_unknown)) {
|
2015-05-08 18:41:21 +08:00
|
|
|
if (DSAStack->isLoopControlVariable(VD) ||
|
|
|
|
(VD->hasLocalStorage() &&
|
2015-07-28 00:38:06 +08:00
|
|
|
isParallelOrTaskRegion(DSAStack->getCurrentDirective())) ||
|
|
|
|
DSAStack->isForceVarCapturing())
|
2015-04-30 12:23:23 +08:00
|
|
|
return true;
|
2015-06-23 12:51:00 +08:00
|
|
|
auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode());
|
2014-12-16 15:00:22 +08:00
|
|
|
if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind))
|
|
|
|
return true;
|
|
|
|
DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(),
|
2015-06-23 12:51:00 +08:00
|
|
|
DSAStack->isClauseParsingMode());
|
2014-12-16 15:00:22 +08:00
|
|
|
return DVarPrivate.CKind != OMPC_unknown;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-23 12:51:00 +08:00
|
|
|
bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) {
|
|
|
|
assert(LangOpts.OpenMP && "OpenMP is not allowed");
|
|
|
|
return DSAStack->hasExplicitDSA(
|
|
|
|
VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level);
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; }
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind,
|
|
|
|
const DeclarationNameInfo &DirName,
|
2014-06-27 18:37:06 +08:00
|
|
|
Scope *CurScope, SourceLocation Loc) {
|
|
|
|
DSAStack->push(DKind, DirName, CurScope, Loc);
|
2013-09-07 02:03:48 +08:00
|
|
|
PushExpressionEvaluationContext(PotentiallyEvaluated);
|
|
|
|
}
|
|
|
|
|
2015-06-23 12:51:00 +08:00
|
|
|
void Sema::StartOpenMPClause(OpenMPClauseKind K) {
|
|
|
|
DSAStack->setClauseParsingMode(K);
|
2015-05-08 18:41:21 +08:00
|
|
|
}
|
|
|
|
|
2015-06-23 12:51:00 +08:00
|
|
|
void Sema::EndOpenMPClause() {
|
|
|
|
DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown);
|
2015-05-08 18:41:21 +08:00
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
void Sema::EndOpenMPDSABlock(Stmt *CurDirective) {
|
2014-06-18 12:14:57 +08:00
|
|
|
// OpenMP [2.14.3.5, Restrictions, C/C++, p.1]
|
|
|
|
// A variable of class type (or array thereof) that appears in a lastprivate
|
|
|
|
// clause requires an accessible, unambiguous default constructor for the
|
|
|
|
// class type, unless the list item is also specified in a firstprivate
|
|
|
|
// clause.
|
|
|
|
if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) {
|
2015-04-16 12:54:05 +08:00
|
|
|
for (auto *C : D->clauses()) {
|
|
|
|
if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) {
|
|
|
|
SmallVector<Expr *, 8> PrivateCopies;
|
|
|
|
for (auto *DE : Clause->varlists()) {
|
|
|
|
if (DE->isValueDependent() || DE->isTypeDependent()) {
|
|
|
|
PrivateCopies.push_back(nullptr);
|
2014-06-18 12:14:57 +08:00
|
|
|
continue;
|
2015-04-16 12:54:05 +08:00
|
|
|
}
|
|
|
|
auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl());
|
2015-08-18 14:47:21 +08:00
|
|
|
QualType Type = VD->getType().getNonReferenceType();
|
2014-07-11 19:25:16 +08:00
|
|
|
auto DVar = DSAStack->getTopDSA(VD, false);
|
2014-06-18 12:14:57 +08:00
|
|
|
if (DVar.CKind == OMPC_lastprivate) {
|
2015-04-16 12:54:05 +08:00
|
|
|
// Generate helper private variable and initialize it with the
|
|
|
|
// default value. The address of the original variable is replaced
|
|
|
|
// by the address of the new private variable in CodeGen. This new
|
|
|
|
// variable is not added to IdResolver, so the code in the OpenMP
|
|
|
|
// region uses original variable for proper diagnostics.
|
2015-09-10 17:48:30 +08:00
|
|
|
auto *VDPrivate = buildVarDecl(
|
|
|
|
*this, DE->getExprLoc(), Type.getUnqualifiedType(),
|
|
|
|
VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-04-16 12:54:05 +08:00
|
|
|
ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false);
|
|
|
|
if (VDPrivate->isInvalidDecl())
|
|
|
|
continue;
|
2015-05-08 18:41:21 +08:00
|
|
|
PrivateCopies.push_back(buildDeclRefExpr(
|
|
|
|
*this, VDPrivate, DE->getType(), DE->getExprLoc()));
|
2015-04-16 12:54:05 +08:00
|
|
|
} else {
|
|
|
|
// The variable is also a firstprivate, so initialization sequence
|
|
|
|
// for private copy is generated already.
|
|
|
|
PrivateCopies.push_back(nullptr);
|
2014-06-18 12:14:57 +08:00
|
|
|
}
|
|
|
|
}
|
2015-04-16 12:54:05 +08:00
|
|
|
// Set initializers to private copies if no errors were found.
|
|
|
|
if (PrivateCopies.size() == Clause->varlist_size()) {
|
|
|
|
Clause->setPrivateCopies(PrivateCopies);
|
|
|
|
}
|
2014-06-18 12:14:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
DSAStack->pop();
|
|
|
|
DiscardCleanupsInEvaluationContext();
|
|
|
|
PopExpressionEvaluationContext();
|
|
|
|
}
|
|
|
|
|
2015-03-21 18:12:56 +08:00
|
|
|
static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV,
|
|
|
|
Expr *NumIterations, Sema &SemaRef,
|
|
|
|
Scope *S);
|
|
|
|
|
2013-03-22 14:34:35 +08:00
|
|
|
namespace {
|
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
class VarDeclFilterCCC : public CorrectionCandidateCallback {
|
|
|
|
private:
|
2014-06-19 17:13:45 +08:00
|
|
|
Sema &SemaRef;
|
2014-05-28 13:53:51 +08:00
|
|
|
|
2013-05-13 12:18:18 +08:00
|
|
|
public:
|
2014-06-19 17:13:45 +08:00
|
|
|
explicit VarDeclFilterCCC(Sema &S) : SemaRef(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() &&
|
2014-06-19 17:13:45 +08:00
|
|
|
SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(),
|
|
|
|
SemaRef.getCurScope());
|
2013-05-13 12:18:18 +08:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2014-05-28 13:53:51 +08:00
|
|
|
} // namespace
|
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()) {
|
2014-10-28 02:07:29 +08:00
|
|
|
if (TypoCorrection Corrected = CorrectTypo(
|
|
|
|
Id, LookupOrdinaryName, CurScope, nullptr,
|
|
|
|
llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) {
|
2013-08-17 08:46:16 +08:00
|
|
|
diagnoseTypo(Corrected,
|
2014-05-15 21:04:49 +08:00
|
|
|
PDiag(Lookup.empty()
|
|
|
|
? diag::err_undeclared_var_use_suggest
|
|
|
|
: diag::err_omp_expected_var_arg_suggest)
|
|
|
|
<< Id.getName());
|
2013-08-17 08:46:16 +08:00
|
|
|
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>())) {
|
2014-05-28 13:53:51 +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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal();
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
2013-05-13 12:18:18 +08:00
|
|
|
Diag(VD->getLocation(),
|
2014-05-28 13:53:51 +08:00
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
2013-05-13 12:18:18 +08:00
|
|
|
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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
2013-09-26 11:24:06 +08:00
|
|
|
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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
2013-09-26 11:24:06 +08:00
|
|
|
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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
2013-09-26 11:24:06 +08:00
|
|
|
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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
2013-05-13 12:18:18 +08:00
|
|
|
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.
|
2015-04-16 21:49:42 +08:00
|
|
|
if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) {
|
2013-05-13 12:18:18 +08:00
|
|
|
Diag(Id.getLoc(), diag::err_omp_var_used)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD;
|
2013-05-13 12:18:18 +08:00
|
|
|
return ExprError();
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2013-05-13 12:18:18 +08:00
|
|
|
|
|
|
|
QualType ExprType = VD->getType().getNonReferenceType();
|
2015-05-08 18:41:21 +08:00
|
|
|
ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc());
|
2013-05-13 12:18:18 +08:00
|
|
|
return DE;
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
Sema::DeclGroupPtrTy
|
|
|
|
Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc,
|
|
|
|
ArrayRef<Expr *> VarList) {
|
2013-05-13 12:18:18 +08:00
|
|
|
if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) {
|
2013-03-22 14:34:35 +08:00
|
|
|
CurContext->addDecl(D);
|
|
|
|
return DeclGroupPtrTy::make(DeclGroupRef(D));
|
|
|
|
}
|
|
|
|
return DeclGroupPtrTy();
|
|
|
|
}
|
|
|
|
|
2014-05-28 15:40:25 +08:00
|
|
|
namespace {
|
|
|
|
class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> {
|
|
|
|
Sema &SemaRef;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool VisitDeclRefExpr(const DeclRefExpr *E) {
|
|
|
|
if (auto VD = dyn_cast<VarDecl>(E->getDecl())) {
|
|
|
|
if (VD->hasLocalStorage()) {
|
|
|
|
SemaRef.Diag(E->getLocStart(),
|
|
|
|
diag::err_omp_local_var_in_threadprivate_init)
|
|
|
|
<< E->getSourceRange();
|
|
|
|
SemaRef.Diag(VD->getLocation(), diag::note_defined_here)
|
|
|
|
<< VD << VD->getSourceRange();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool VisitStmt(const Stmt *S) {
|
|
|
|
for (auto Child : S->children()) {
|
|
|
|
if (Child && Visit(Child))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-18 15:08:49 +08:00
|
|
|
explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {}
|
2014-05-28 15:40:25 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
OMPThreadPrivateDecl *
|
|
|
|
Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) {
|
2013-05-13 12:18:18 +08:00
|
|
|
SmallVector<Expr *, 8> Vars;
|
2014-05-28 13:53:51 +08:00
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr);
|
2013-05-13 12:18:18 +08:00
|
|
|
VarDecl *VD = cast<VarDecl>(DE->getDecl());
|
|
|
|
SourceLocation ILoc = DE->getExprLoc();
|
2013-03-22 14:34:35 +08:00
|
|
|
|
2015-04-16 13:39:01 +08:00
|
|
|
QualType QType = VD->getType();
|
|
|
|
if (QType->isDependentType() || QType->isInstantiationDependentType()) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(DE);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-07-14 06:54:53 +08:00
|
|
|
// Check if this is a TLS variable. If TLS is not being supported, produce
|
|
|
|
// the corresponding diagnostic.
|
|
|
|
if ((VD->getTLSKind() != VarDecl::TLS_None &&
|
|
|
|
!(VD->hasAttr<OMPThreadPrivateDeclAttr>() &&
|
|
|
|
getLangOpts().OpenMPUseTLS &&
|
|
|
|
getASTContext().getTargetInfo().isTLSSupported())) ||
|
2015-05-06 14:34:55 +08:00
|
|
|
(VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() &&
|
|
|
|
!VD->isLocalVarDecl())) {
|
2015-01-13 11:35:30 +08:00
|
|
|
Diag(ILoc, diag::err_omp_var_thread_local)
|
|
|
|
<< VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1);
|
2014-05-28 13:53:51 +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;
|
|
|
|
}
|
|
|
|
|
2014-05-28 15:40:25 +08:00
|
|
|
// Check if initial value of threadprivate variable reference variable with
|
|
|
|
// local storage (it is not supported by runtime).
|
|
|
|
if (auto Init = VD->getAnyInitializer()) {
|
|
|
|
LocalVarRefChecker Checker(*this);
|
2014-06-18 12:14:57 +08:00
|
|
|
if (Checker.Visit(Init))
|
|
|
|
continue;
|
2014-05-28 15:40:25 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
Vars.push_back(RefExpr);
|
2014-03-07 16:03:37 +08:00
|
|
|
DSAStack->addDSA(VD, DE, OMPC_threadprivate);
|
2014-11-11 12:05:39 +08:00
|
|
|
VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(
|
|
|
|
Context, SourceRange(Loc, Loc)));
|
|
|
|
if (auto *ML = Context.getASTMutationListener())
|
|
|
|
ML->DeclarationMarkedOpenMPThreadPrivate(VD);
|
2013-03-22 14:34:35 +08:00
|
|
|
}
|
2014-05-15 21:04:49 +08:00
|
|
|
OMPThreadPrivateDecl *D = nullptr;
|
2014-01-31 13:15:34 +08:00
|
|
|
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
|
|
|
|
2014-06-19 17:13:45 +08:00
|
|
|
static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack,
|
|
|
|
const VarDecl *VD, DSAStackTy::DSAVarData DVar,
|
|
|
|
bool IsLoopIterVar = false) {
|
|
|
|
if (DVar.RefExpr) {
|
|
|
|
SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
enum {
|
|
|
|
PDSA_StaticMemberShared,
|
|
|
|
PDSA_StaticLocalVarShared,
|
|
|
|
PDSA_LoopIterVarPrivate,
|
|
|
|
PDSA_LoopIterVarLinear,
|
|
|
|
PDSA_LoopIterVarLastprivate,
|
|
|
|
PDSA_ConstVarShared,
|
|
|
|
PDSA_GlobalVarShared,
|
2014-07-11 19:25:16 +08:00
|
|
|
PDSA_TaskVarFirstprivate,
|
2014-06-27 18:37:06 +08:00
|
|
|
PDSA_LocalVarPrivate,
|
|
|
|
PDSA_Implicit
|
|
|
|
} Reason = PDSA_Implicit;
|
2014-06-19 17:13:45 +08:00
|
|
|
bool ReportHint = false;
|
2014-07-11 19:25:16 +08:00
|
|
|
auto ReportLoc = VD->getLocation();
|
2014-06-19 17:13:45 +08:00
|
|
|
if (IsLoopIterVar) {
|
|
|
|
if (DVar.CKind == OMPC_private)
|
|
|
|
Reason = PDSA_LoopIterVarPrivate;
|
|
|
|
else if (DVar.CKind == OMPC_lastprivate)
|
|
|
|
Reason = PDSA_LoopIterVarLastprivate;
|
|
|
|
else
|
|
|
|
Reason = PDSA_LoopIterVarLinear;
|
2014-07-11 19:25:16 +08:00
|
|
|
} else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) {
|
|
|
|
Reason = PDSA_TaskVarFirstprivate;
|
|
|
|
ReportLoc = DVar.ImplicitDSALoc;
|
2014-06-19 17:13:45 +08:00
|
|
|
} else if (VD->isStaticLocal())
|
|
|
|
Reason = PDSA_StaticLocalVarShared;
|
|
|
|
else if (VD->isStaticDataMember())
|
|
|
|
Reason = PDSA_StaticMemberShared;
|
|
|
|
else if (VD->isFileVarDecl())
|
|
|
|
Reason = PDSA_GlobalVarShared;
|
|
|
|
else if (VD->getType().isConstant(SemaRef.getASTContext()))
|
|
|
|
Reason = PDSA_ConstVarShared;
|
2014-06-27 18:37:06 +08:00
|
|
|
else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) {
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportHint = true;
|
|
|
|
Reason = PDSA_LocalVarPrivate;
|
|
|
|
}
|
2014-06-27 18:37:06 +08:00
|
|
|
if (Reason != PDSA_Implicit) {
|
2014-07-11 19:25:16 +08:00
|
|
|
SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa)
|
2014-06-27 18:37:06 +08:00
|
|
|
<< Reason << ReportHint
|
|
|
|
<< getOpenMPDirectiveName(Stack->getCurrentDirective());
|
|
|
|
} else if (DVar.ImplicitDSALoc.isValid()) {
|
|
|
|
SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind);
|
|
|
|
}
|
2014-06-19 17:13:45 +08:00
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
namespace {
|
|
|
|
class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> {
|
|
|
|
DSAStackTy *Stack;
|
2014-06-19 17:13:45 +08:00
|
|
|
Sema &SemaRef;
|
2013-09-07 02:03:48 +08:00
|
|
|
bool ErrorFound;
|
|
|
|
CapturedStmt *CS;
|
2013-10-01 13:32:34 +08:00
|
|
|
llvm::SmallVector<Expr *, 8> ImplicitFirstprivate;
|
2014-07-07 21:01:15 +08:00
|
|
|
llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA;
|
2014-05-28 13:53:51 +08:00
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
public:
|
|
|
|
void VisitDeclRefExpr(DeclRefExpr *E) {
|
2014-07-11 19:25:16 +08:00
|
|
|
if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) {
|
2013-09-07 02:03:48 +08:00
|
|
|
// Skip internally declared variables.
|
2014-05-28 13:53:51 +08:00
|
|
|
if (VD->isLocalVarDecl() && !CS->capturesVariable(VD))
|
|
|
|
return;
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2014-07-11 19:25:16 +08:00
|
|
|
auto DVar = Stack->getTopDSA(VD, false);
|
|
|
|
// Check if the variable has explicit DSA set and stop analysis if it so.
|
|
|
|
if (DVar.RefExpr) return;
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2014-07-11 19:25:16 +08:00
|
|
|
auto ELoc = E->getExprLoc();
|
|
|
|
auto DKind = Stack->getCurrentDirective();
|
2013-09-07 02:03:48 +08:00
|
|
|
// 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 &&
|
2014-07-11 19:25:16 +08:00
|
|
|
isParallelOrTaskRegion(DKind) &&
|
2014-07-07 21:01:15 +08:00
|
|
|
VarsWithInheritedDSA.count(VD) == 0) {
|
|
|
|
VarsWithInheritedDSA[VD] = E;
|
2013-09-07 02:03:48 +08:00
|
|
|
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.
|
2014-06-18 12:14:57 +08:00
|
|
|
DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction),
|
2014-07-11 19:25:16 +08:00
|
|
|
[](OpenMPDirectiveKind K) -> bool {
|
|
|
|
return isOpenMPParallelDirective(K) ||
|
2014-10-09 12:18:56 +08:00
|
|
|
isOpenMPWorksharingDirective(K) ||
|
|
|
|
isOpenMPTeamsDirective(K);
|
2014-07-11 19:25:16 +08:00
|
|
|
},
|
|
|
|
false);
|
2014-06-16 15:08:35 +08:00
|
|
|
if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) {
|
|
|
|
ErrorFound = true;
|
2014-06-19 17:13:45 +08:00
|
|
|
SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task);
|
|
|
|
ReportOriginalDSA(SemaRef, Stack, VD, DVar);
|
2014-06-16 15:08:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
// Define implicit data-sharing attributes for task.
|
2014-07-11 19:25:16 +08:00
|
|
|
DVar = Stack->getImplicitDSA(VD, false);
|
2013-10-01 13:32:34 +08:00
|
|
|
if (DKind == OMPD_task && DVar.CKind != OMPC_shared)
|
2014-07-11 19:25:16 +08:00
|
|
|
ImplicitFirstprivate.push_back(E);
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void VisitOMPExecutableDirective(OMPExecutableDirective *S) {
|
2014-07-11 19:25:16 +08:00
|
|
|
for (auto *C : S->clauses()) {
|
|
|
|
// Skip analysis of arguments of implicitly defined firstprivate clause
|
|
|
|
// for task directives.
|
|
|
|
if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid()))
|
|
|
|
for (auto *CC : C->children()) {
|
|
|
|
if (CC)
|
|
|
|
Visit(CC);
|
|
|
|
}
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
}
|
|
|
|
void VisitStmt(Stmt *S) {
|
2014-07-11 19:25:16 +08:00
|
|
|
for (auto *C : S->children()) {
|
|
|
|
if (C && !isa<OMPExecutableDirective>(C))
|
|
|
|
Visit(C);
|
|
|
|
}
|
2014-05-28 13:53:51 +08:00
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
bool isErrorFound() { return ErrorFound; }
|
2013-10-01 13:32:34 +08:00
|
|
|
ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; }
|
2014-07-07 21:01:15 +08:00
|
|
|
llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() {
|
|
|
|
return VarsWithInheritedDSA;
|
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2014-06-19 17:13:45 +08:00
|
|
|
DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS)
|
|
|
|
: Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {}
|
2013-09-07 02:03:48 +08:00
|
|
|
};
|
2014-05-28 13:53:51 +08:00
|
|
|
} // namespace
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2014-06-27 18:37:06 +08:00
|
|
|
void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) {
|
2014-05-06 18:08:46 +08:00
|
|
|
switch (DKind) {
|
|
|
|
case OMPD_parallel: {
|
|
|
|
QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
|
2015-09-10 16:12:02 +08:00
|
|
|
QualType KmpInt32PtrTy =
|
|
|
|
Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
|
2014-06-25 12:09:13 +08:00
|
|
|
Sema::CapturedParamNameType Params[] = {
|
2014-06-18 12:14:57 +08:00
|
|
|
std::make_pair(".global_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(".bound_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
2014-05-06 18:08:46 +08:00
|
|
|
};
|
2014-06-27 18:37:06 +08:00
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
2014-05-06 18:08:46 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OMPD_simd: {
|
2014-06-25 12:09:13 +08:00
|
|
|
Sema::CapturedParamNameType Params[] = {
|
2014-06-18 12:14:57 +08:00
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
2014-06-27 18:37:06 +08:00
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
2014-06-18 12:14:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case OMPD_for: {
|
2014-06-25 12:09:13 +08:00
|
|
|
Sema::CapturedParamNameType Params[] = {
|
2014-06-18 12:14:57 +08:00
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
2014-05-06 18:08:46 +08:00
|
|
|
};
|
2014-06-27 18:37:06 +08:00
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
2014-05-06 18:08:46 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-09-18 13:12:34 +08:00
|
|
|
case OMPD_for_simd: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-06-25 19:44:49 +08:00
|
|
|
case OMPD_sections: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
2014-06-27 18:37:06 +08:00
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
2014-06-25 19:44:49 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-06-26 16:21:58 +08:00
|
|
|
case OMPD_section: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
2014-06-27 18:37:06 +08:00
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
2014-06-26 16:21:58 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-06-26 20:05:45 +08:00
|
|
|
case OMPD_single: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
2014-06-27 18:37:06 +08:00
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
2014-06-26 20:05:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-07-17 16:54:58 +08:00
|
|
|
case OMPD_master: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-21 17:42:05 +08:00
|
|
|
case OMPD_critical: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-07 21:01:15 +08:00
|
|
|
case OMPD_parallel_for: {
|
|
|
|
QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
|
2015-09-10 16:12:02 +08:00
|
|
|
QualType KmpInt32PtrTy =
|
|
|
|
Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
|
2014-07-07 21:01:15 +08:00
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(".global_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(".bound_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-09-23 17:33:00 +08:00
|
|
|
case OMPD_parallel_for_simd: {
|
|
|
|
QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
|
2015-09-10 16:12:02 +08:00
|
|
|
QualType KmpInt32PtrTy =
|
|
|
|
Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
|
2014-09-23 17:33:00 +08:00
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(".global_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(".bound_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-08 16:12:03 +08:00
|
|
|
case OMPD_parallel_sections: {
|
2015-04-14 11:29:22 +08:00
|
|
|
QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
|
2015-09-10 16:12:02 +08:00
|
|
|
QualType KmpInt32PtrTy =
|
|
|
|
Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
|
2014-07-08 16:12:03 +08:00
|
|
|
Sema::CapturedParamNameType Params[] = {
|
2015-04-14 11:29:22 +08:00
|
|
|
std::make_pair(".global_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(".bound_tid.", KmpInt32PtrTy),
|
2014-07-08 16:12:03 +08:00
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-11 19:25:16 +08:00
|
|
|
case OMPD_task: {
|
[OPENMP] Initial codegen for 'omp task' directive.
The task region is emmitted in several steps:
Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, kmp_routine_entry_t *task_entry).
Here task_entry is a pointer to the function:
kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
TaskFunction(gtid, tt->part_id, tt->shareds);
return 0;
}
Copy a list of shared variables to field shareds of the resulting structure kmp_task_t returned by the previous call (if any).
Copy a pointer to destructions function to field destructions of the resulting structure kmp_task_t.
Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *new_task), where new_task is a resulting structure from previous items.
Differential Revision: http://reviews.llvm.org/D7560
llvm-svn: 231762
2015-03-10 15:28:44 +08:00
|
|
|
QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
|
[OPENMP] Prepare codegen for privates in tasks for non-capturing of privates in CapturedStmt.
Reworked codegen for privates in tasks:
call @kmpc_omp_task_alloc();
...
call @kmpc_omp_task(task_proxy);
void map_privates(.privates_rec. *privs, type1 ** priv1_ref, ..., typen **privn_ref) {
*priv1_ref = &privs->private1;
...
*privn_ref = &privs->privaten;
ret void
}
i32 task_entry(i32 ThreadId, i32 PartId, void* privs, void (void*, ...) map_privates, shareds* captures) {
type1 **priv1;
...
typen **privn;
call map_privates(privs, priv1, ..., privn);
<Task body with priv1, .., privn instead of the captured variables>.
ret i32
}
i32 task_proxy(i32 ThreadId, kmp_task_t_with_privates *tt) {
call task_entry(ThreadId, tt->task_data.PartId, &tt->privates, map_privates, tt->task_data.shareds);
}
llvm-svn: 238010
2015-05-22 16:56:35 +08:00
|
|
|
QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()};
|
|
|
|
FunctionProtoType::ExtProtoInfo EPI;
|
|
|
|
EPI.Variadic = true;
|
|
|
|
QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI);
|
2014-07-11 19:25:16 +08:00
|
|
|
Sema::CapturedParamNameType Params[] = {
|
[OPENMP] Initial codegen for 'omp task' directive.
The task region is emmitted in several steps:
Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, kmp_routine_entry_t *task_entry).
Here task_entry is a pointer to the function:
kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
TaskFunction(gtid, tt->part_id, tt->shareds);
return 0;
}
Copy a list of shared variables to field shareds of the resulting structure kmp_task_t returned by the previous call (if any).
Copy a pointer to destructions function to field destructions of the resulting structure kmp_task_t.
Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *new_task), where new_task is a resulting structure from previous items.
Differential Revision: http://reviews.llvm.org/D7560
llvm-svn: 231762
2015-03-10 15:28:44 +08:00
|
|
|
std::make_pair(".global_tid.", KmpInt32Ty),
|
|
|
|
std::make_pair(".part_id.", KmpInt32Ty),
|
[OPENMP] Prepare codegen for privates in tasks for non-capturing of privates in CapturedStmt.
Reworked codegen for privates in tasks:
call @kmpc_omp_task_alloc();
...
call @kmpc_omp_task(task_proxy);
void map_privates(.privates_rec. *privs, type1 ** priv1_ref, ..., typen **privn_ref) {
*priv1_ref = &privs->private1;
...
*privn_ref = &privs->privaten;
ret void
}
i32 task_entry(i32 ThreadId, i32 PartId, void* privs, void (void*, ...) map_privates, shareds* captures) {
type1 **priv1;
...
typen **privn;
call map_privates(privs, priv1, ..., privn);
<Task body with priv1, .., privn instead of the captured variables>.
ret i32
}
i32 task_proxy(i32 ThreadId, kmp_task_t_with_privates *tt) {
call task_entry(ThreadId, tt->task_data.PartId, &tt->privates, map_privates, tt->task_data.shareds);
}
llvm-svn: 238010
2015-05-22 16:56:35 +08:00
|
|
|
std::make_pair(".privates.",
|
|
|
|
Context.VoidPtrTy.withConst().withRestrict()),
|
|
|
|
std::make_pair(
|
|
|
|
".copy_fn.",
|
|
|
|
Context.getPointerType(CopyFnType).withConst().withRestrict()),
|
2014-07-11 19:25:16 +08:00
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
[OPENMP] Initial codegen for 'omp task' directive.
The task region is emmitted in several steps:
Emit a call to kmp_task_t *__kmpc_omp_task_alloc(ident_t *, kmp_int32 gtid, kmp_int32 flags, size_t sizeof_kmp_task_t, size_t sizeof_shareds, kmp_routine_entry_t *task_entry).
Here task_entry is a pointer to the function:
kmp_int32 .omp_task_entry.(kmp_int32 gtid, kmp_task_t *tt) {
TaskFunction(gtid, tt->part_id, tt->shareds);
return 0;
}
Copy a list of shared variables to field shareds of the resulting structure kmp_task_t returned by the previous call (if any).
Copy a pointer to destructions function to field destructions of the resulting structure kmp_task_t.
Emit a call to kmp_int32 __kmpc_omp_task(ident_t *, kmp_int32 gtid, kmp_task_t *new_task), where new_task is a resulting structure from previous items.
Differential Revision: http://reviews.llvm.org/D7560
llvm-svn: 231762
2015-03-10 15:28:44 +08:00
|
|
|
// Mark this captured region as inlined, because we don't use outlined
|
|
|
|
// function directly.
|
|
|
|
getCurCapturedRegion()->TheCapturedDecl->addAttr(
|
|
|
|
AlwaysInlineAttr::CreateImplicit(
|
|
|
|
Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange()));
|
2014-07-11 19:25:16 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-07-22 14:45:04 +08:00
|
|
|
case OMPD_ordered: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-07-22 18:10:35 +08:00
|
|
|
case OMPD_atomic: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2015-07-21 21:44:28 +08:00
|
|
|
case OMPD_target_data:
|
2014-09-19 16:19:49 +08:00
|
|
|
case OMPD_target: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-10-09 12:18:56 +08:00
|
|
|
case OMPD_teams: {
|
|
|
|
QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
|
2015-09-10 16:12:02 +08:00
|
|
|
QualType KmpInt32PtrTy =
|
|
|
|
Context.getPointerType(KmpInt32Ty).withConst().withRestrict();
|
2014-10-09 12:18:56 +08:00
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(".global_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(".bound_tid.", KmpInt32PtrTy),
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2015-06-18 20:14:09 +08:00
|
|
|
case OMPD_taskgroup: {
|
|
|
|
Sema::CapturedParamNameType Params[] = {
|
|
|
|
std::make_pair(StringRef(), QualType()) // __context with shared vars
|
|
|
|
};
|
|
|
|
ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP,
|
|
|
|
Params);
|
|
|
|
break;
|
|
|
|
}
|
2014-05-06 18:08:46 +08:00
|
|
|
case OMPD_threadprivate:
|
2014-11-21 19:33:46 +08:00
|
|
|
case OMPD_taskyield:
|
|
|
|
case OMPD_barrier:
|
|
|
|
case OMPD_taskwait:
|
2015-07-01 14:57:41 +08:00
|
|
|
case OMPD_cancellation_point:
|
2015-07-02 19:25:17 +08:00
|
|
|
case OMPD_cancel:
|
2014-11-21 19:33:46 +08:00
|
|
|
case OMPD_flush:
|
2014-05-06 18:08:46 +08:00
|
|
|
llvm_unreachable("OpenMP Directive is not allowed");
|
|
|
|
case OMPD_unknown:
|
|
|
|
llvm_unreachable("Unknown OpenMP directive");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 15:48:16 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
|
|
|
|
ArrayRef<OMPClause *> Clauses) {
|
|
|
|
if (!S.isUsable()) {
|
|
|
|
ActOnCapturedRegionError();
|
|
|
|
return StmtError();
|
|
|
|
}
|
2015-05-12 16:35:28 +08:00
|
|
|
// This is required for proper codegen.
|
2015-04-02 15:48:16 +08:00
|
|
|
for (auto *Clause : Clauses) {
|
2015-05-20 11:46:04 +08:00
|
|
|
if (isOpenMPPrivate(Clause->getClauseKind()) ||
|
2015-07-28 00:38:06 +08:00
|
|
|
Clause->getClauseKind() == OMPC_copyprivate ||
|
|
|
|
(getLangOpts().OpenMPUseTLS &&
|
|
|
|
getASTContext().getTargetInfo().isTLSSupported() &&
|
|
|
|
Clause->getClauseKind() == OMPC_copyin)) {
|
|
|
|
DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin);
|
2015-05-12 16:35:28 +08:00
|
|
|
// Mark all variables in private list clauses as used in inner region.
|
2015-04-02 15:48:16 +08:00
|
|
|
for (auto *VarRef : Clause->children()) {
|
|
|
|
if (auto *E = cast_or_null<Expr>(VarRef)) {
|
2015-04-02 21:07:08 +08:00
|
|
|
MarkDeclarationsReferencedInExpr(E);
|
2015-04-02 15:48:16 +08:00
|
|
|
}
|
|
|
|
}
|
2015-07-28 00:38:06 +08:00
|
|
|
DSAStack->setForceVarCapturing(/*V=*/false);
|
2015-05-12 16:35:28 +08:00
|
|
|
} else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) &&
|
|
|
|
Clause->getClauseKind() == OMPC_schedule) {
|
|
|
|
// Mark all variables in private list clauses as used in inner region.
|
|
|
|
// Required for proper codegen of combined directives.
|
|
|
|
// TODO: add processing for other clauses.
|
|
|
|
if (auto *E = cast_or_null<Expr>(
|
|
|
|
cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) {
|
|
|
|
MarkDeclarationsReferencedInExpr(E);
|
|
|
|
}
|
2015-04-02 15:48:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ActOnCapturedRegionEnd(S.get());
|
|
|
|
}
|
|
|
|
|
2014-07-21 17:42:05 +08:00
|
|
|
static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack,
|
|
|
|
OpenMPDirectiveKind CurrentRegion,
|
|
|
|
const DeclarationNameInfo &CurrentName,
|
2015-07-01 14:57:41 +08:00
|
|
|
OpenMPDirectiveKind CancelRegion,
|
2014-07-21 17:42:05 +08:00
|
|
|
SourceLocation StartLoc) {
|
2014-06-30 18:22:46 +08:00
|
|
|
// Allowed nesting of constructs
|
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)|
|
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | parallel | parallel | * |
|
|
|
|
// | parallel | for | * |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | parallel | for simd | * |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | parallel | master | * |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | parallel | critical | * |
|
2014-06-30 18:22:46 +08:00
|
|
|
// | parallel | simd | * |
|
|
|
|
// | parallel | sections | * |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | parallel | section | + |
|
2014-06-30 18:22:46 +08:00
|
|
|
// | parallel | single | * |
|
2014-07-07 21:01:15 +08:00
|
|
|
// | parallel | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | parallel |parallel for simd| * |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | parallel |parallel sections| * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | parallel | task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | parallel | taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | parallel | barrier | * |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | parallel | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | parallel | taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | parallel | flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | parallel | ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | parallel | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | parallel | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | parallel | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | parallel | cancellation | |
|
|
|
|
// | | point | ! |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | parallel | cancel | ! |
|
2014-06-30 18:22:46 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | for | parallel | * |
|
|
|
|
// | for | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | for | for simd | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | for | master | + |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | for | critical | * |
|
2014-06-30 18:22:46 +08:00
|
|
|
// | for | simd | * |
|
|
|
|
// | for | sections | + |
|
|
|
|
// | for | section | + |
|
|
|
|
// | for | single | + |
|
2014-07-07 21:01:15 +08:00
|
|
|
// | for | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | for |parallel for simd| * |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | for |parallel sections| * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | for | task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | for | taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | for | barrier | + |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | for | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | for | taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | for | flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | for | ordered | * (if construct is ordered) |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | for | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | for | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | for | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | for | cancellation | |
|
|
|
|
// | | point | ! |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | for | cancel | ! |
|
2014-06-30 18:22:46 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
2014-07-17 16:54:58 +08:00
|
|
|
// | master | parallel | * |
|
|
|
|
// | master | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | master | for simd | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | master | master | * |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | master | critical | * |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | master | simd | * |
|
|
|
|
// | master | sections | + |
|
|
|
|
// | master | section | + |
|
|
|
|
// | master | single | + |
|
|
|
|
// | master | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | master |parallel for simd| * |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | master |parallel sections| * |
|
|
|
|
// | master | task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | master | taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | master | barrier | + |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | master | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | master | taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | master | flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | master | ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | master | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | master | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | master | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | master | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | master | cancel | |
|
2014-07-17 16:54:58 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
2014-07-21 17:42:05 +08:00
|
|
|
// | critical | parallel | * |
|
|
|
|
// | critical | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | critical | for simd | + |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | critical | master | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | critical | critical | * (should have different names) |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | critical | simd | * |
|
|
|
|
// | critical | sections | + |
|
|
|
|
// | critical | section | + |
|
|
|
|
// | critical | single | + |
|
|
|
|
// | critical | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | critical |parallel for simd| * |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | critical |parallel sections| * |
|
|
|
|
// | critical | task | * |
|
|
|
|
// | critical | taskyield | * |
|
|
|
|
// | critical | barrier | + |
|
|
|
|
// | critical | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | critical | taskgroup | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | critical | ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | critical | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | critical | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | critical | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | critical | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | critical | cancel | |
|
2014-07-21 17:42:05 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
2014-06-30 18:22:46 +08:00
|
|
|
// | simd | parallel | |
|
|
|
|
// | simd | for | |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | simd | for simd | |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | simd | master | |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | simd | critical | |
|
2014-06-30 18:22:46 +08:00
|
|
|
// | simd | simd | |
|
|
|
|
// | simd | sections | |
|
|
|
|
// | simd | section | |
|
|
|
|
// | simd | single | |
|
2014-07-07 21:01:15 +08:00
|
|
|
// | simd | parallel for | |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | simd |parallel for simd| |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | simd |parallel sections| |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | simd | task | |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | simd | taskyield | |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | simd | barrier | |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | simd | taskwait | |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | simd | taskgroup | |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | simd | flush | |
|
2015-09-28 14:39:35 +08:00
|
|
|
// | simd | ordered | + (with simd clause) |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | simd | atomic | |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | simd | target | |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | simd | teams | |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | simd | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | simd | cancel | |
|
2014-06-30 18:22:46 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
2014-09-18 13:12:34 +08:00
|
|
|
// | for simd | parallel | |
|
|
|
|
// | for simd | for | |
|
|
|
|
// | for simd | for simd | |
|
|
|
|
// | for simd | master | |
|
|
|
|
// | for simd | critical | |
|
|
|
|
// | for simd | simd | |
|
|
|
|
// | for simd | sections | |
|
|
|
|
// | for simd | section | |
|
|
|
|
// | for simd | single | |
|
|
|
|
// | for simd | parallel for | |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | for simd |parallel for simd| |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | for simd |parallel sections| |
|
|
|
|
// | for simd | task | |
|
|
|
|
// | for simd | taskyield | |
|
|
|
|
// | for simd | barrier | |
|
|
|
|
// | for simd | taskwait | |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | for simd | taskgroup | |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | for simd | flush | |
|
2015-09-28 14:39:35 +08:00
|
|
|
// | for simd | ordered | + (with simd clause) |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | for simd | atomic | |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | for simd | target | |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | for simd | teams | |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | for simd | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | for simd | cancel | |
|
2014-09-18 13:12:34 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
2014-09-23 17:33:00 +08:00
|
|
|
// | parallel for simd| parallel | |
|
|
|
|
// | parallel for simd| for | |
|
|
|
|
// | parallel for simd| for simd | |
|
|
|
|
// | parallel for simd| master | |
|
|
|
|
// | parallel for simd| critical | |
|
|
|
|
// | parallel for simd| simd | |
|
|
|
|
// | parallel for simd| sections | |
|
|
|
|
// | parallel for simd| section | |
|
|
|
|
// | parallel for simd| single | |
|
|
|
|
// | parallel for simd| parallel for | |
|
|
|
|
// | parallel for simd|parallel for simd| |
|
|
|
|
// | parallel for simd|parallel sections| |
|
|
|
|
// | parallel for simd| task | |
|
|
|
|
// | parallel for simd| taskyield | |
|
|
|
|
// | parallel for simd| barrier | |
|
|
|
|
// | parallel for simd| taskwait | |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | parallel for simd| taskgroup | |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | parallel for simd| flush | |
|
2015-09-28 14:39:35 +08:00
|
|
|
// | parallel for simd| ordered | + (with simd clause) |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | parallel for simd| atomic | |
|
|
|
|
// | parallel for simd| target | |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | parallel for simd| teams | |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | parallel for simd| cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | parallel for simd| cancel | |
|
2014-09-23 17:33:00 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
2014-06-30 18:22:46 +08:00
|
|
|
// | sections | parallel | * |
|
|
|
|
// | sections | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | sections | for simd | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | sections | master | + |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | sections | critical | * |
|
2014-06-30 18:22:46 +08:00
|
|
|
// | sections | simd | * |
|
|
|
|
// | sections | sections | + |
|
|
|
|
// | sections | section | * |
|
|
|
|
// | sections | single | + |
|
2014-07-07 21:01:15 +08:00
|
|
|
// | sections | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | sections |parallel for simd| * |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | sections |parallel sections| * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | sections | task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | sections | taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | sections | barrier | + |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | sections | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | sections | taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | sections | flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | sections | ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | sections | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | sections | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | sections | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | sections | cancellation | |
|
|
|
|
// | | point | ! |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | sections | cancel | ! |
|
2014-06-30 18:22:46 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | section | parallel | * |
|
|
|
|
// | section | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | section | for simd | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | section | master | + |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | section | critical | * |
|
2014-06-30 18:22:46 +08:00
|
|
|
// | section | simd | * |
|
|
|
|
// | section | sections | + |
|
|
|
|
// | section | section | + |
|
|
|
|
// | section | single | + |
|
2014-07-07 21:01:15 +08:00
|
|
|
// | section | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | section |parallel for simd| * |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | section |parallel sections| * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | section | task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | section | taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | section | barrier | + |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | section | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | section | taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | section | flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | section | ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | section | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | section | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | section | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | section | cancellation | |
|
|
|
|
// | | point | ! |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | section | cancel | ! |
|
2014-06-30 18:22:46 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | single | parallel | * |
|
|
|
|
// | single | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | single | for simd | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | single | master | + |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | single | critical | * |
|
2014-06-30 18:22:46 +08:00
|
|
|
// | single | simd | * |
|
|
|
|
// | single | sections | + |
|
|
|
|
// | single | section | + |
|
|
|
|
// | single | single | + |
|
2014-07-07 21:01:15 +08:00
|
|
|
// | single | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | single |parallel for simd| * |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | single |parallel sections| * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | single | task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | single | taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | single | barrier | + |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | single | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | single | taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | single | flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | single | ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | single | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | single | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | single | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | single | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | single | cancel | |
|
2014-07-07 21:01:15 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | parallel for | parallel | * |
|
|
|
|
// | parallel for | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | parallel for | for simd | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | parallel for | master | + |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | parallel for | critical | * |
|
2014-07-07 21:01:15 +08:00
|
|
|
// | parallel for | simd | * |
|
|
|
|
// | parallel for | sections | + |
|
|
|
|
// | parallel for | section | + |
|
|
|
|
// | parallel for | single | + |
|
|
|
|
// | parallel for | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | parallel for |parallel for simd| * |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | parallel for |parallel sections| * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | parallel for | task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | parallel for | taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | parallel for | barrier | + |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | parallel for | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | parallel for | taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | parallel for | flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | parallel for | ordered | * (if construct is ordered) |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | parallel for | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | parallel for | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | parallel for | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | parallel for | cancellation | |
|
|
|
|
// | | point | ! |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | parallel for | cancel | ! |
|
2014-07-08 16:12:03 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | parallel sections| parallel | * |
|
|
|
|
// | parallel sections| for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | parallel sections| for simd | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | parallel sections| master | + |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | parallel sections| critical | + |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | parallel sections| simd | * |
|
|
|
|
// | parallel sections| sections | + |
|
|
|
|
// | parallel sections| section | * |
|
|
|
|
// | parallel sections| single | + |
|
|
|
|
// | parallel sections| parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | parallel sections|parallel for simd| * |
|
2014-07-08 16:12:03 +08:00
|
|
|
// | parallel sections|parallel sections| * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | parallel sections| task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | parallel sections| taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | parallel sections| barrier | + |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | parallel sections| taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | parallel sections| taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | parallel sections| flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | parallel sections| ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | parallel sections| atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | parallel sections| target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | parallel sections| teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | parallel sections| cancellation | |
|
|
|
|
// | | point | ! |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | parallel sections| cancel | ! |
|
2014-07-11 19:25:16 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | task | parallel | * |
|
|
|
|
// | task | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | task | for simd | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | task | master | + |
|
2014-07-21 17:42:05 +08:00
|
|
|
// | task | critical | * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | task | simd | * |
|
|
|
|
// | task | sections | + |
|
2014-07-17 16:54:58 +08:00
|
|
|
// | task | section | + |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | task | single | + |
|
|
|
|
// | task | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | task |parallel for simd| * |
|
2014-07-11 19:25:16 +08:00
|
|
|
// | task |parallel sections| * |
|
|
|
|
// | task | task | * |
|
2014-07-18 15:47:19 +08:00
|
|
|
// | task | taskyield | * |
|
2014-07-18 17:11:51 +08:00
|
|
|
// | task | barrier | + |
|
2014-07-18 18:17:07 +08:00
|
|
|
// | task | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | task | taskgroup | * |
|
2014-07-21 19:26:11 +08:00
|
|
|
// | task | flush | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | task | ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | task | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | task | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | task | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | task | cancellation | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | | point | ! |
|
|
|
|
// | task | cancel | ! |
|
2014-07-22 14:45:04 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | ordered | parallel | * |
|
|
|
|
// | ordered | for | + |
|
2014-09-18 13:12:34 +08:00
|
|
|
// | ordered | for simd | + |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | ordered | master | * |
|
|
|
|
// | ordered | critical | * |
|
|
|
|
// | ordered | simd | * |
|
|
|
|
// | ordered | sections | + |
|
|
|
|
// | ordered | section | + |
|
|
|
|
// | ordered | single | + |
|
|
|
|
// | ordered | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | ordered |parallel for simd| * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | ordered |parallel sections| * |
|
|
|
|
// | ordered | task | * |
|
|
|
|
// | ordered | taskyield | * |
|
|
|
|
// | ordered | barrier | + |
|
|
|
|
// | ordered | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | ordered | taskgroup | * |
|
2014-07-22 14:45:04 +08:00
|
|
|
// | ordered | flush | * |
|
|
|
|
// | ordered | ordered | + |
|
2014-07-22 18:10:35 +08:00
|
|
|
// | ordered | atomic | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | ordered | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | ordered | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | ordered | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | ordered | cancel | |
|
2014-09-19 16:19:49 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | atomic | parallel | |
|
|
|
|
// | atomic | for | |
|
|
|
|
// | atomic | for simd | |
|
|
|
|
// | atomic | master | |
|
|
|
|
// | atomic | critical | |
|
|
|
|
// | atomic | simd | |
|
|
|
|
// | atomic | sections | |
|
|
|
|
// | atomic | section | |
|
|
|
|
// | atomic | single | |
|
|
|
|
// | atomic | parallel for | |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | atomic |parallel for simd| |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | atomic |parallel sections| |
|
|
|
|
// | atomic | task | |
|
|
|
|
// | atomic | taskyield | |
|
|
|
|
// | atomic | barrier | |
|
|
|
|
// | atomic | taskwait | |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | atomic | taskgroup | |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | atomic | flush | |
|
|
|
|
// | atomic | ordered | |
|
|
|
|
// | atomic | atomic | |
|
|
|
|
// | atomic | target | |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | atomic | teams | |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | atomic | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | atomic | cancel | |
|
2014-09-19 16:19:49 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | target | parallel | * |
|
|
|
|
// | target | for | * |
|
|
|
|
// | target | for simd | * |
|
|
|
|
// | target | master | * |
|
|
|
|
// | target | critical | * |
|
|
|
|
// | target | simd | * |
|
|
|
|
// | target | sections | * |
|
|
|
|
// | target | section | * |
|
|
|
|
// | target | single | * |
|
|
|
|
// | target | parallel for | * |
|
2014-09-23 17:33:00 +08:00
|
|
|
// | target |parallel for simd| * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | target |parallel sections| * |
|
|
|
|
// | target | task | * |
|
|
|
|
// | target | taskyield | * |
|
|
|
|
// | target | barrier | * |
|
|
|
|
// | target | taskwait | * |
|
2015-06-18 20:14:09 +08:00
|
|
|
// | target | taskgroup | * |
|
2014-09-19 16:19:49 +08:00
|
|
|
// | target | flush | * |
|
|
|
|
// | target | ordered | * |
|
|
|
|
// | target | atomic | * |
|
|
|
|
// | target | target | * |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | target | teams | * |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | target | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | target | cancel | |
|
2014-10-09 12:18:56 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
|
|
|
// | teams | parallel | * |
|
|
|
|
// | teams | for | + |
|
|
|
|
// | teams | for simd | + |
|
|
|
|
// | teams | master | + |
|
|
|
|
// | teams | critical | + |
|
|
|
|
// | teams | simd | + |
|
|
|
|
// | teams | sections | + |
|
|
|
|
// | teams | section | + |
|
|
|
|
// | teams | single | + |
|
|
|
|
// | teams | parallel for | * |
|
|
|
|
// | teams |parallel for simd| * |
|
|
|
|
// | teams |parallel sections| * |
|
|
|
|
// | teams | task | + |
|
|
|
|
// | teams | taskyield | + |
|
|
|
|
// | teams | barrier | + |
|
|
|
|
// | teams | taskwait | + |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | teams | taskgroup | + |
|
2014-10-09 12:18:56 +08:00
|
|
|
// | teams | flush | + |
|
|
|
|
// | teams | ordered | + |
|
|
|
|
// | teams | atomic | + |
|
|
|
|
// | teams | target | + |
|
|
|
|
// | teams | teams | + |
|
2015-07-01 14:57:41 +08:00
|
|
|
// | teams | cancellation | |
|
|
|
|
// | | point | |
|
2015-07-02 19:25:17 +08:00
|
|
|
// | teams | cancel | |
|
2014-06-30 18:22:46 +08:00
|
|
|
// +------------------+-----------------+------------------------------------+
|
2014-06-24 12:39:47 +08:00
|
|
|
if (Stack->getCurScope()) {
|
|
|
|
auto ParentRegion = Stack->getParentDirective();
|
|
|
|
bool NestingProhibited = false;
|
|
|
|
bool CloseNesting = true;
|
2014-07-22 14:45:04 +08:00
|
|
|
enum {
|
|
|
|
NoRecommend,
|
|
|
|
ShouldBeInParallelRegion,
|
2014-10-09 12:18:56 +08:00
|
|
|
ShouldBeInOrderedRegion,
|
|
|
|
ShouldBeInTargetRegion
|
2014-07-22 14:45:04 +08:00
|
|
|
} Recommend = NoRecommend;
|
2015-09-28 14:39:35 +08:00
|
|
|
if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) {
|
2014-06-24 12:39:47 +08:00
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// OpenMP constructs may not be nested inside a simd region.
|
2015-09-28 14:39:35 +08:00
|
|
|
// OpenMP [2.8.1,simd Construct, Restrictions]
|
|
|
|
// An ordered construct with the simd clause is the only OpenMP construct
|
|
|
|
// that can appear in the simd region.
|
2014-06-24 12:39:47 +08:00
|
|
|
SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd);
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-22 18:10:35 +08:00
|
|
|
if (ParentRegion == OMPD_atomic) {
|
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// OpenMP constructs may not be nested inside an atomic region.
|
|
|
|
SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic);
|
|
|
|
return true;
|
|
|
|
}
|
2014-06-26 16:21:58 +08:00
|
|
|
if (CurrentRegion == OMPD_section) {
|
|
|
|
// OpenMP [2.7.2, sections Construct, Restrictions]
|
|
|
|
// Orphaned section directives are prohibited. That is, the section
|
|
|
|
// directives must appear within the sections construct and must not be
|
|
|
|
// encountered elsewhere in the sections region.
|
2014-07-08 16:12:03 +08:00
|
|
|
if (ParentRegion != OMPD_sections &&
|
|
|
|
ParentRegion != OMPD_parallel_sections) {
|
2014-06-26 16:21:58 +08:00
|
|
|
SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive)
|
|
|
|
<< (ParentRegion != OMPD_unknown)
|
|
|
|
<< getOpenMPDirectiveName(ParentRegion);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-22 14:45:04 +08:00
|
|
|
// Allow some constructs to be orphaned (they could be used in functions,
|
|
|
|
// called from OpenMP regions with the required preconditions).
|
|
|
|
if (ParentRegion == OMPD_unknown)
|
|
|
|
return false;
|
2015-07-02 19:25:17 +08:00
|
|
|
if (CurrentRegion == OMPD_cancellation_point ||
|
|
|
|
CurrentRegion == OMPD_cancel) {
|
2015-07-01 14:57:41 +08:00
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// A cancellation point construct for which construct-type-clause is
|
|
|
|
// taskgroup must be nested inside a task construct. A cancellation
|
|
|
|
// point construct for which construct-type-clause is not taskgroup must
|
|
|
|
// be closely nested inside an OpenMP construct that matches the type
|
|
|
|
// specified in construct-type-clause.
|
2015-07-02 19:25:17 +08:00
|
|
|
// A cancel construct for which construct-type-clause is taskgroup must be
|
|
|
|
// nested inside a task construct. A cancel construct for which
|
|
|
|
// construct-type-clause is not taskgroup must be closely nested inside an
|
|
|
|
// OpenMP construct that matches the type specified in
|
|
|
|
// construct-type-clause.
|
2015-07-01 14:57:41 +08:00
|
|
|
NestingProhibited =
|
|
|
|
!((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) ||
|
2015-09-15 20:52:43 +08:00
|
|
|
(CancelRegion == OMPD_for &&
|
|
|
|
(ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) ||
|
2015-07-01 14:57:41 +08:00
|
|
|
(CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) ||
|
|
|
|
(CancelRegion == OMPD_sections &&
|
2015-09-15 20:52:43 +08:00
|
|
|
(ParentRegion == OMPD_section || ParentRegion == OMPD_sections ||
|
|
|
|
ParentRegion == OMPD_parallel_sections)));
|
2015-07-01 14:57:41 +08:00
|
|
|
} else if (CurrentRegion == OMPD_master) {
|
2014-07-17 16:54:58 +08:00
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// A master region may not be closely nested inside a worksharing,
|
2014-07-22 18:10:35 +08:00
|
|
|
// atomic, or explicit task region.
|
2014-07-17 16:54:58 +08:00
|
|
|
NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) ||
|
|
|
|
ParentRegion == OMPD_task;
|
2014-07-21 17:42:05 +08:00
|
|
|
} else if (CurrentRegion == OMPD_critical && CurrentName.getName()) {
|
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// A critical region may not be nested (closely or otherwise) inside a
|
|
|
|
// critical region with the same name. Note that this restriction is not
|
|
|
|
// sufficient to prevent deadlock.
|
|
|
|
SourceLocation PreviousCriticalLoc;
|
|
|
|
bool DeadLock =
|
|
|
|
Stack->hasDirective([CurrentName, &PreviousCriticalLoc](
|
|
|
|
OpenMPDirectiveKind K,
|
|
|
|
const DeclarationNameInfo &DNI,
|
|
|
|
SourceLocation Loc)
|
|
|
|
->bool {
|
|
|
|
if (K == OMPD_critical &&
|
|
|
|
DNI.getName() == CurrentName.getName()) {
|
|
|
|
PreviousCriticalLoc = Loc;
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
false /* skip top directive */);
|
|
|
|
if (DeadLock) {
|
|
|
|
SemaRef.Diag(StartLoc,
|
|
|
|
diag::err_omp_prohibited_region_critical_same_name)
|
|
|
|
<< CurrentName.getName();
|
|
|
|
if (PreviousCriticalLoc.isValid())
|
|
|
|
SemaRef.Diag(PreviousCriticalLoc,
|
|
|
|
diag::note_omp_previous_critical_region);
|
|
|
|
return true;
|
|
|
|
}
|
2014-07-18 17:11:51 +08:00
|
|
|
} else if (CurrentRegion == OMPD_barrier) {
|
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// A barrier region may not be closely nested inside a worksharing,
|
2014-07-22 18:10:35 +08:00
|
|
|
// explicit task, critical, ordered, atomic, or master region.
|
2014-07-22 14:45:04 +08:00
|
|
|
NestingProhibited =
|
|
|
|
isOpenMPWorksharingDirective(ParentRegion) ||
|
|
|
|
ParentRegion == OMPD_task || ParentRegion == OMPD_master ||
|
|
|
|
ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered;
|
2014-07-17 16:54:58 +08:00
|
|
|
} else if (isOpenMPWorksharingDirective(CurrentRegion) &&
|
2014-09-18 13:12:34 +08:00
|
|
|
!isOpenMPParallelDirective(CurrentRegion)) {
|
2014-06-24 12:39:47 +08:00
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// A worksharing region may not be closely nested inside a worksharing,
|
|
|
|
// explicit task, critical, ordered, atomic, or master region.
|
2014-07-22 14:45:04 +08:00
|
|
|
NestingProhibited =
|
2014-09-18 13:12:34 +08:00
|
|
|
isOpenMPWorksharingDirective(ParentRegion) ||
|
2014-07-22 14:45:04 +08:00
|
|
|
ParentRegion == OMPD_task || ParentRegion == OMPD_master ||
|
|
|
|
ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered;
|
|
|
|
Recommend = ShouldBeInParallelRegion;
|
|
|
|
} else if (CurrentRegion == OMPD_ordered) {
|
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// An ordered region may not be closely nested inside a critical,
|
2014-07-22 18:10:35 +08:00
|
|
|
// atomic, or explicit task region.
|
2014-07-22 14:45:04 +08:00
|
|
|
// An ordered region must be closely nested inside a loop region (or
|
|
|
|
// parallel loop region) with an ordered clause.
|
2015-09-28 14:39:35 +08:00
|
|
|
// OpenMP [2.8.1,simd Construct, Restrictions]
|
|
|
|
// An ordered construct with the simd clause is the only OpenMP construct
|
|
|
|
// that can appear in the simd region.
|
2014-07-22 14:45:04 +08:00
|
|
|
NestingProhibited = ParentRegion == OMPD_critical ||
|
2014-07-17 16:54:58 +08:00
|
|
|
ParentRegion == OMPD_task ||
|
2015-09-28 14:39:35 +08:00
|
|
|
!(isOpenMPSimdDirective(ParentRegion) ||
|
|
|
|
Stack->isParentOrderedRegion());
|
2014-07-22 14:45:04 +08:00
|
|
|
Recommend = ShouldBeInOrderedRegion;
|
2014-10-09 12:18:56 +08:00
|
|
|
} else if (isOpenMPTeamsDirective(CurrentRegion)) {
|
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// If specified, a teams construct must be contained within a target
|
|
|
|
// construct.
|
|
|
|
NestingProhibited = ParentRegion != OMPD_target;
|
|
|
|
Recommend = ShouldBeInTargetRegion;
|
|
|
|
Stack->setParentTeamsRegionLoc(Stack->getConstructLoc());
|
|
|
|
}
|
|
|
|
if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) {
|
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// distribute, parallel, parallel sections, parallel workshare, and the
|
|
|
|
// parallel loop and parallel loop SIMD constructs are the only OpenMP
|
|
|
|
// constructs that can be closely nested in the teams region.
|
|
|
|
// TODO: add distribute directive.
|
|
|
|
NestingProhibited = !isOpenMPParallelDirective(CurrentRegion);
|
|
|
|
Recommend = ShouldBeInParallelRegion;
|
2014-06-24 12:39:47 +08:00
|
|
|
}
|
|
|
|
if (NestingProhibited) {
|
|
|
|
SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region)
|
2014-07-22 14:45:04 +08:00
|
|
|
<< CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend
|
|
|
|
<< getOpenMPDirectiveName(CurrentRegion);
|
2014-06-24 12:39:47 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-03 15:23:48 +08:00
|
|
|
static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind,
|
|
|
|
ArrayRef<OMPClause *> Clauses,
|
|
|
|
ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) {
|
|
|
|
bool ErrorFound = false;
|
|
|
|
unsigned NamedModifiersNumber = 0;
|
|
|
|
SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers(
|
|
|
|
OMPD_unknown + 1);
|
2015-09-16 01:23:56 +08:00
|
|
|
SmallVector<SourceLocation, 4> NameModifierLoc;
|
2015-09-03 15:23:48 +08:00
|
|
|
for (const auto *C : Clauses) {
|
|
|
|
if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) {
|
|
|
|
// At most one if clause without a directive-name-modifier can appear on
|
|
|
|
// the directive.
|
|
|
|
OpenMPDirectiveKind CurNM = IC->getNameModifier();
|
|
|
|
if (FoundNameModifiers[CurNM]) {
|
|
|
|
S.Diag(C->getLocStart(), diag::err_omp_more_one_clause)
|
|
|
|
<< getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if)
|
|
|
|
<< (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM);
|
|
|
|
ErrorFound = true;
|
2015-09-16 01:23:56 +08:00
|
|
|
} else if (CurNM != OMPD_unknown) {
|
|
|
|
NameModifierLoc.push_back(IC->getNameModifierLoc());
|
2015-09-03 15:23:48 +08:00
|
|
|
++NamedModifiersNumber;
|
2015-09-16 01:23:56 +08:00
|
|
|
}
|
2015-09-03 15:23:48 +08:00
|
|
|
FoundNameModifiers[CurNM] = IC;
|
|
|
|
if (CurNM == OMPD_unknown)
|
|
|
|
continue;
|
|
|
|
// Check if the specified name modifier is allowed for the current
|
|
|
|
// directive.
|
|
|
|
// At most one if clause with the particular directive-name-modifier can
|
|
|
|
// appear on the directive.
|
|
|
|
bool MatchFound = false;
|
|
|
|
for (auto NM : AllowedNameModifiers) {
|
|
|
|
if (CurNM == NM) {
|
|
|
|
MatchFound = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!MatchFound) {
|
|
|
|
S.Diag(IC->getNameModifierLoc(),
|
|
|
|
diag::err_omp_wrong_if_directive_name_modifier)
|
|
|
|
<< getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind);
|
|
|
|
ErrorFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// If any if clause on the directive includes a directive-name-modifier then
|
|
|
|
// all if clauses on the directive must include a directive-name-modifier.
|
|
|
|
if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) {
|
|
|
|
if (NamedModifiersNumber == AllowedNameModifiers.size()) {
|
|
|
|
S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(),
|
|
|
|
diag::err_omp_no_more_if_clause);
|
|
|
|
} else {
|
|
|
|
std::string Values;
|
|
|
|
std::string Sep(", ");
|
|
|
|
unsigned AllowedCnt = 0;
|
|
|
|
unsigned TotalAllowedNum =
|
|
|
|
AllowedNameModifiers.size() - NamedModifiersNumber;
|
|
|
|
for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End;
|
|
|
|
++Cnt) {
|
|
|
|
OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt];
|
|
|
|
if (!FoundNameModifiers[NM]) {
|
|
|
|
Values += "'";
|
|
|
|
Values += getOpenMPDirectiveName(NM);
|
|
|
|
Values += "'";
|
|
|
|
if (AllowedCnt + 2 == TotalAllowedNum)
|
|
|
|
Values += " or ";
|
|
|
|
else if (AllowedCnt + 1 != TotalAllowedNum)
|
|
|
|
Values += Sep;
|
|
|
|
++AllowedCnt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(),
|
|
|
|
diag::err_omp_unnamed_if_clause)
|
|
|
|
<< (TotalAllowedNum > 1) << Values;
|
|
|
|
}
|
2015-09-16 01:23:56 +08:00
|
|
|
for (auto Loc : NameModifierLoc) {
|
|
|
|
S.Diag(Loc, diag::note_omp_previous_named_if_clause);
|
|
|
|
}
|
2015-09-03 15:23:48 +08:00
|
|
|
ErrorFound = true;
|
|
|
|
}
|
|
|
|
return ErrorFound;
|
|
|
|
}
|
|
|
|
|
2015-07-01 14:57:41 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPExecutableDirective(
|
|
|
|
OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName,
|
|
|
|
OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) {
|
2013-07-19 11:13:43 +08:00
|
|
|
StmtResult Res = StmtError();
|
2015-07-01 14:57:41 +08:00
|
|
|
if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion,
|
|
|
|
StartLoc))
|
2014-06-24 12:39:47 +08:00
|
|
|
return StmtError();
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2013-10-01 13:32:34 +08:00
|
|
|
llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit;
|
2014-07-18 15:47:19 +08:00
|
|
|
llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA;
|
2013-10-01 13:32:34 +08:00
|
|
|
bool ErrorFound = false;
|
2014-07-21 19:26:11 +08:00
|
|
|
ClausesWithImplicit.append(Clauses.begin(), Clauses.end());
|
2014-07-18 15:47:19 +08:00
|
|
|
if (AStmt) {
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
// Generate list of implicitly defined firstprivate variables.
|
|
|
|
VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA();
|
|
|
|
|
|
|
|
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-10-01 13:32:34 +08:00
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
|
2015-09-03 15:23:48 +08:00
|
|
|
llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers;
|
2013-07-19 11:13:43 +08:00
|
|
|
switch (Kind) {
|
|
|
|
case OMPD_parallel:
|
2014-05-28 13:53:51 +08:00
|
|
|
Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc);
|
2015-09-03 15:23:48 +08:00
|
|
|
AllowedNameModifiers.push_back(OMPD_parallel);
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
2014-02-27 16:29:12 +08:00
|
|
|
case OMPD_simd:
|
2014-07-07 21:01:15 +08:00
|
|
|
Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc,
|
|
|
|
VarsWithInheritedDSA);
|
2014-02-27 16:29:12 +08:00
|
|
|
break;
|
2014-06-18 12:14:57 +08:00
|
|
|
case OMPD_for:
|
2014-07-07 21:01:15 +08:00
|
|
|
Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc,
|
|
|
|
VarsWithInheritedDSA);
|
2014-06-18 12:14:57 +08:00
|
|
|
break;
|
2014-09-18 13:12:34 +08:00
|
|
|
case OMPD_for_simd:
|
|
|
|
Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc, VarsWithInheritedDSA);
|
|
|
|
break;
|
2014-06-25 19:44:49 +08:00
|
|
|
case OMPD_sections:
|
|
|
|
Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc);
|
|
|
|
break;
|
2014-06-26 16:21:58 +08:00
|
|
|
case OMPD_section:
|
|
|
|
assert(ClausesWithImplicit.empty() &&
|
2014-07-17 16:54:58 +08:00
|
|
|
"No clauses are allowed for 'omp section' directive");
|
2014-06-26 16:21:58 +08:00
|
|
|
Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc);
|
|
|
|
break;
|
2014-06-26 20:05:45 +08:00
|
|
|
case OMPD_single:
|
|
|
|
Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc);
|
|
|
|
break;
|
2014-07-17 16:54:58 +08:00
|
|
|
case OMPD_master:
|
|
|
|
assert(ClausesWithImplicit.empty() &&
|
|
|
|
"No clauses are allowed for 'omp master' directive");
|
|
|
|
Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-21 17:42:05 +08:00
|
|
|
case OMPD_critical:
|
|
|
|
assert(ClausesWithImplicit.empty() &&
|
|
|
|
"No clauses are allowed for 'omp critical' directive");
|
|
|
|
Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-07 21:01:15 +08:00
|
|
|
case OMPD_parallel_for:
|
|
|
|
Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc, VarsWithInheritedDSA);
|
2015-09-03 15:23:48 +08:00
|
|
|
AllowedNameModifiers.push_back(OMPD_parallel);
|
2014-07-07 21:01:15 +08:00
|
|
|
break;
|
2014-09-23 17:33:00 +08:00
|
|
|
case OMPD_parallel_for_simd:
|
|
|
|
Res = ActOnOpenMPParallelForSimdDirective(
|
|
|
|
ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA);
|
2015-09-03 15:23:48 +08:00
|
|
|
AllowedNameModifiers.push_back(OMPD_parallel);
|
2014-09-23 17:33:00 +08:00
|
|
|
break;
|
2014-07-08 16:12:03 +08:00
|
|
|
case OMPD_parallel_sections:
|
|
|
|
Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt,
|
|
|
|
StartLoc, EndLoc);
|
2015-09-03 15:23:48 +08:00
|
|
|
AllowedNameModifiers.push_back(OMPD_parallel);
|
2014-07-08 16:12:03 +08:00
|
|
|
break;
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPD_task:
|
2014-07-11 19:25:16 +08:00
|
|
|
Res =
|
|
|
|
ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc);
|
2015-09-03 15:23:48 +08:00
|
|
|
AllowedNameModifiers.push_back(OMPD_task);
|
2014-07-11 19:25:16 +08:00
|
|
|
break;
|
2014-07-18 15:47:19 +08:00
|
|
|
case OMPD_taskyield:
|
|
|
|
assert(ClausesWithImplicit.empty() &&
|
|
|
|
"No clauses are allowed for 'omp taskyield' directive");
|
|
|
|
assert(AStmt == nullptr &&
|
|
|
|
"No associated statement allowed for 'omp taskyield' directive");
|
|
|
|
Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-18 17:11:51 +08:00
|
|
|
case OMPD_barrier:
|
|
|
|
assert(ClausesWithImplicit.empty() &&
|
|
|
|
"No clauses are allowed for 'omp barrier' directive");
|
|
|
|
assert(AStmt == nullptr &&
|
|
|
|
"No associated statement allowed for 'omp barrier' directive");
|
|
|
|
Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-18 18:17:07 +08:00
|
|
|
case OMPD_taskwait:
|
|
|
|
assert(ClausesWithImplicit.empty() &&
|
|
|
|
"No clauses are allowed for 'omp taskwait' directive");
|
|
|
|
assert(AStmt == nullptr &&
|
|
|
|
"No associated statement allowed for 'omp taskwait' directive");
|
|
|
|
Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc);
|
|
|
|
break;
|
2015-06-18 20:14:09 +08:00
|
|
|
case OMPD_taskgroup:
|
|
|
|
assert(ClausesWithImplicit.empty() &&
|
|
|
|
"No clauses are allowed for 'omp taskgroup' directive");
|
|
|
|
Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPD_flush:
|
|
|
|
assert(AStmt == nullptr &&
|
|
|
|
"No associated statement allowed for 'omp flush' directive");
|
|
|
|
Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-22 14:45:04 +08:00
|
|
|
case OMPD_ordered:
|
2015-09-25 18:37:12 +08:00
|
|
|
Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc);
|
2014-07-22 14:45:04 +08:00
|
|
|
break;
|
2014-07-22 18:10:35 +08:00
|
|
|
case OMPD_atomic:
|
|
|
|
Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc);
|
|
|
|
break;
|
2014-10-09 12:18:56 +08:00
|
|
|
case OMPD_teams:
|
|
|
|
Res =
|
|
|
|
ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc);
|
|
|
|
break;
|
2014-09-19 16:19:49 +08:00
|
|
|
case OMPD_target:
|
|
|
|
Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc);
|
2015-09-03 15:23:48 +08:00
|
|
|
AllowedNameModifiers.push_back(OMPD_target);
|
2014-09-19 16:19:49 +08:00
|
|
|
break;
|
2015-07-01 14:57:41 +08:00
|
|
|
case OMPD_cancellation_point:
|
|
|
|
assert(ClausesWithImplicit.empty() &&
|
|
|
|
"No clauses are allowed for 'omp cancellation point' directive");
|
|
|
|
assert(AStmt == nullptr && "No associated statement allowed for 'omp "
|
|
|
|
"cancellation point' directive");
|
|
|
|
Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion);
|
|
|
|
break;
|
2015-07-02 19:25:17 +08:00
|
|
|
case OMPD_cancel:
|
|
|
|
assert(AStmt == nullptr &&
|
|
|
|
"No associated statement allowed for 'omp cancel' directive");
|
2015-09-18 16:07:34 +08:00
|
|
|
Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc,
|
|
|
|
CancelRegion);
|
|
|
|
AllowedNameModifiers.push_back(OMPD_cancel);
|
2015-07-02 19:25:17 +08:00
|
|
|
break;
|
2015-07-21 21:44:28 +08:00
|
|
|
case OMPD_target_data:
|
|
|
|
Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc,
|
|
|
|
EndLoc);
|
2015-09-03 15:23:48 +08:00
|
|
|
AllowedNameModifiers.push_back(OMPD_target_data);
|
2015-07-21 21:44:28 +08:00
|
|
|
break;
|
2014-07-11 19:25:16 +08:00
|
|
|
case OMPD_threadprivate:
|
2013-07-19 11:13:43 +08:00
|
|
|
llvm_unreachable("OpenMP Directive is not allowed");
|
|
|
|
case OMPD_unknown:
|
|
|
|
llvm_unreachable("Unknown OpenMP directive");
|
|
|
|
}
|
2013-10-01 13:32:34 +08:00
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
for (auto P : VarsWithInheritedDSA) {
|
|
|
|
Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable)
|
|
|
|
<< P.first << P.second->getSourceRange();
|
|
|
|
}
|
2015-09-03 15:23:48 +08:00
|
|
|
ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound;
|
|
|
|
|
|
|
|
if (!AllowedNameModifiers.empty())
|
|
|
|
ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) ||
|
|
|
|
ErrorFound;
|
2014-07-07 21:01:15 +08:00
|
|
|
|
2014-05-28 13:53:51 +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) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
2014-05-06 18:08:46 +08:00
|
|
|
CapturedStmt *CS = cast<CapturedStmt>(AStmt);
|
|
|
|
// 1.2.2 OpenMP Language Terminology
|
|
|
|
// Structured block - An executable statement with a single entry at the
|
|
|
|
// top and a single exit at the bottom.
|
|
|
|
// The point of exit cannot be a branch out of the structured block.
|
|
|
|
// longjmp() and throw() must not violate the entry/exit criteria.
|
|
|
|
CS->getCapturedDecl()->setNothrow();
|
|
|
|
|
2013-07-19 11:13:43 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
2015-09-15 20:52:43 +08:00
|
|
|
return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt,
|
|
|
|
DSAStack->isCancelRegion());
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
2014-06-03 18:16:47 +08:00
|
|
|
namespace {
|
|
|
|
/// \brief Helper class for checking canonical form of the OpenMP loops and
|
|
|
|
/// extracting iteration space of each loop in the loop nest, that will be used
|
|
|
|
/// for IR generation.
|
|
|
|
class OpenMPIterationSpaceChecker {
|
|
|
|
/// \brief Reference to Sema.
|
|
|
|
Sema &SemaRef;
|
|
|
|
/// \brief A location for diagnostics (when there is no some better location).
|
|
|
|
SourceLocation DefaultLoc;
|
|
|
|
/// \brief A location for diagnostics (when increment is not compatible).
|
|
|
|
SourceLocation ConditionLoc;
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief A source location for referring to loop init later.
|
|
|
|
SourceRange InitSrcRange;
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief A source location for referring to condition later.
|
|
|
|
SourceRange ConditionSrcRange;
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief A source location for referring to increment later.
|
|
|
|
SourceRange IncrementSrcRange;
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief Loop variable.
|
|
|
|
VarDecl *Var;
|
2014-07-25 14:27:47 +08:00
|
|
|
/// \brief Reference to loop variable.
|
|
|
|
DeclRefExpr *VarRef;
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief Lower bound (initializer for the var).
|
|
|
|
Expr *LB;
|
|
|
|
/// \brief Upper bound.
|
|
|
|
Expr *UB;
|
|
|
|
/// \brief Loop step (increment).
|
|
|
|
Expr *Step;
|
|
|
|
/// \brief This flag is true when condition is one of:
|
|
|
|
/// Var < UB
|
|
|
|
/// Var <= UB
|
|
|
|
/// UB > Var
|
|
|
|
/// UB >= Var
|
|
|
|
bool TestIsLessOp;
|
|
|
|
/// \brief This flag is true when condition is strict ( < or > ).
|
|
|
|
bool TestIsStrictOp;
|
|
|
|
/// \brief This flag is true when step is subtracted on each iteration.
|
|
|
|
bool SubtractStep;
|
|
|
|
|
|
|
|
public:
|
|
|
|
OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc)
|
|
|
|
: SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc),
|
2014-10-01 14:03:56 +08:00
|
|
|
InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()),
|
|
|
|
IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr),
|
2014-07-25 14:27:47 +08:00
|
|
|
LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false),
|
|
|
|
TestIsStrictOp(false), SubtractStep(false) {}
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief Check init-expr for canonical loop form and save loop counter
|
|
|
|
/// variable - #Var and its initialization value - #LB.
|
2015-04-30 12:23:23 +08:00
|
|
|
bool CheckInit(Stmt *S, bool EmitDiags = true);
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief Check test-expr for canonical form, save upper-bound (#UB), flags
|
|
|
|
/// for less/greater and for strict/non-strict comparison.
|
|
|
|
bool CheckCond(Expr *S);
|
|
|
|
/// \brief Check incr-expr for canonical loop form and return true if it
|
|
|
|
/// does not conform, otherwise save loop step (#Step).
|
|
|
|
bool CheckInc(Expr *S);
|
|
|
|
/// \brief Return the loop counter variable.
|
|
|
|
VarDecl *GetLoopVar() const { return Var; }
|
2014-07-25 14:27:47 +08:00
|
|
|
/// \brief Return the reference expression to loop counter variable.
|
|
|
|
DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; }
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief Source range of the loop init.
|
|
|
|
SourceRange GetInitSrcRange() const { return InitSrcRange; }
|
|
|
|
/// \brief Source range of the loop condition.
|
|
|
|
SourceRange GetConditionSrcRange() const { return ConditionSrcRange; }
|
|
|
|
/// \brief Source range of the loop increment.
|
|
|
|
SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; }
|
|
|
|
/// \brief True if the step should be subtracted.
|
|
|
|
bool ShouldSubtractStep() const { return SubtractStep; }
|
|
|
|
/// \brief Build the expression to calculate the number of iterations.
|
2014-10-06 19:16:29 +08:00
|
|
|
Expr *BuildNumIterations(Scope *S, const bool LimitedType) const;
|
2015-04-22 19:59:37 +08:00
|
|
|
/// \brief Build the precondition expression for the loops.
|
|
|
|
Expr *BuildPreCond(Scope *S, Expr *Cond) const;
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief Build reference expression to the counter be used for codegen.
|
|
|
|
Expr *BuildCounterVar() const;
|
2015-08-06 20:30:57 +08:00
|
|
|
/// \brief Build reference expression to the private counter be used for
|
|
|
|
/// codegen.
|
|
|
|
Expr *BuildPrivateCounterVar() const;
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief Build initization of the counter be used for codegen.
|
|
|
|
Expr *BuildCounterInit() const;
|
|
|
|
/// \brief Build step of the counter be used for codegen.
|
|
|
|
Expr *BuildCounterStep() const;
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief Return true if any expression is dependent.
|
|
|
|
bool Dependent() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// \brief Check the right-hand side of an assignment in the increment
|
|
|
|
/// expression.
|
|
|
|
bool CheckIncRHS(Expr *RHS);
|
|
|
|
/// \brief Helper to set loop counter variable and its initializer.
|
2014-07-25 14:27:47 +08:00
|
|
|
bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB);
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief Helper to set upper bound.
|
|
|
|
bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR,
|
2015-09-21 09:23:32 +08:00
|
|
|
SourceLocation SL);
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief Helper to set loop increment.
|
|
|
|
bool SetStep(Expr *NewStep, bool Subtract);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool OpenMPIterationSpaceChecker::Dependent() const {
|
|
|
|
if (!Var) {
|
|
|
|
assert(!LB && !UB && !Step);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) ||
|
|
|
|
(UB && UB->isValueDependent()) || (Step && Step->isValueDependent());
|
|
|
|
}
|
|
|
|
|
2015-07-15 20:14:07 +08:00
|
|
|
template <typename T>
|
|
|
|
static T *getExprAsWritten(T *E) {
|
|
|
|
if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E))
|
|
|
|
E = ExprTemp->getSubExpr();
|
|
|
|
|
|
|
|
if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E))
|
|
|
|
E = MTE->GetTemporaryExpr();
|
|
|
|
|
|
|
|
while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E))
|
|
|
|
E = Binder->getSubExpr();
|
|
|
|
|
|
|
|
if (auto *ICE = dyn_cast<ImplicitCastExpr>(E))
|
|
|
|
E = ICE->getSubExprAsWritten();
|
|
|
|
return E->IgnoreParens();
|
|
|
|
}
|
|
|
|
|
2014-07-25 14:27:47 +08:00
|
|
|
bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar,
|
|
|
|
DeclRefExpr *NewVarRefExpr,
|
|
|
|
Expr *NewLB) {
|
2014-06-03 18:16:47 +08:00
|
|
|
// State consistency checking to ensure correct usage.
|
2014-07-25 14:27:47 +08:00
|
|
|
assert(Var == nullptr && LB == nullptr && VarRef == nullptr &&
|
|
|
|
UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp);
|
2014-06-03 18:16:47 +08:00
|
|
|
if (!NewVar || !NewLB)
|
|
|
|
return true;
|
|
|
|
Var = NewVar;
|
2014-07-25 14:27:47 +08:00
|
|
|
VarRef = NewVarRefExpr;
|
2015-07-15 20:14:07 +08:00
|
|
|
if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB))
|
|
|
|
if (const CXXConstructorDecl *Ctor = CE->getConstructor())
|
2015-07-16 12:19:43 +08:00
|
|
|
if ((Ctor->isCopyOrMoveConstructor() ||
|
|
|
|
Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) &&
|
|
|
|
CE->getNumArgs() > 0 && CE->getArg(0) != nullptr)
|
2015-07-15 20:14:07 +08:00
|
|
|
NewLB = CE->getArg(0)->IgnoreParenImpCasts();
|
2014-06-03 18:16:47 +08:00
|
|
|
LB = NewLB;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp,
|
|
|
|
const SourceRange &SR,
|
2015-09-21 09:23:32 +08:00
|
|
|
SourceLocation SL) {
|
2014-06-03 18:16:47 +08:00
|
|
|
// State consistency checking to ensure correct usage.
|
|
|
|
assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr &&
|
|
|
|
!TestIsLessOp && !TestIsStrictOp);
|
|
|
|
if (!NewUB)
|
|
|
|
return true;
|
|
|
|
UB = NewUB;
|
|
|
|
TestIsLessOp = LessOp;
|
|
|
|
TestIsStrictOp = StrictOp;
|
|
|
|
ConditionSrcRange = SR;
|
|
|
|
ConditionLoc = SL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) {
|
|
|
|
// State consistency checking to ensure correct usage.
|
|
|
|
assert(Var != nullptr && LB != nullptr && Step == nullptr);
|
|
|
|
if (!NewStep)
|
|
|
|
return true;
|
|
|
|
if (!NewStep->isValueDependent()) {
|
|
|
|
// Check that the step is integer expression.
|
|
|
|
SourceLocation StepLoc = NewStep->getLocStart();
|
|
|
|
ExprResult Val =
|
|
|
|
SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep);
|
|
|
|
if (Val.isInvalid())
|
|
|
|
return true;
|
|
|
|
NewStep = Val.get();
|
|
|
|
|
|
|
|
// OpenMP [2.6, Canonical Loop Form, Restrictions]
|
|
|
|
// If test-expr is of form var relational-op b and relational-op is < or
|
|
|
|
// <= then incr-expr must cause var to increase on each iteration of the
|
|
|
|
// loop. If test-expr is of form var relational-op b and relational-op is
|
|
|
|
// > or >= then incr-expr must cause var to decrease on each iteration of
|
|
|
|
// the loop.
|
|
|
|
// If test-expr is of form b relational-op var and relational-op is < or
|
|
|
|
// <= then incr-expr must cause var to decrease on each iteration of the
|
|
|
|
// loop. If test-expr is of form b relational-op var and relational-op is
|
|
|
|
// > or >= then incr-expr must cause var to increase on each iteration of
|
|
|
|
// the loop.
|
|
|
|
llvm::APSInt Result;
|
|
|
|
bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context);
|
|
|
|
bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation();
|
|
|
|
bool IsConstNeg =
|
|
|
|
IsConstant && Result.isSigned() && (Subtract != Result.isNegative());
|
2014-10-01 14:03:56 +08:00
|
|
|
bool IsConstPos =
|
|
|
|
IsConstant && Result.isSigned() && (Subtract == Result.isNegative());
|
2014-06-03 18:16:47 +08:00
|
|
|
bool IsConstZero = IsConstant && !Result.getBoolValue();
|
|
|
|
if (UB && (IsConstZero ||
|
|
|
|
(TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract))
|
2014-10-01 14:03:56 +08:00
|
|
|
: (IsConstPos || (IsUnsigned && !Subtract))))) {
|
2014-06-03 18:16:47 +08:00
|
|
|
SemaRef.Diag(NewStep->getExprLoc(),
|
|
|
|
diag::err_omp_loop_incr_not_compatible)
|
|
|
|
<< Var << TestIsLessOp << NewStep->getSourceRange();
|
|
|
|
SemaRef.Diag(ConditionLoc,
|
|
|
|
diag::note_omp_loop_cond_requres_compatible_incr)
|
|
|
|
<< TestIsLessOp << ConditionSrcRange;
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-01 14:03:56 +08:00
|
|
|
if (TestIsLessOp == Subtract) {
|
|
|
|
NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus,
|
|
|
|
NewStep).get();
|
|
|
|
Subtract = !Subtract;
|
|
|
|
}
|
2014-06-03 18:16:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Step = NewStep;
|
|
|
|
SubtractStep = Subtract;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-30 12:23:23 +08:00
|
|
|
bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) {
|
2014-06-03 18:16:47 +08:00
|
|
|
// Check init-expr for canonical loop form and save loop counter
|
|
|
|
// variable - #Var and its initialization value - #LB.
|
|
|
|
// OpenMP [2.6] Canonical loop form. init-expr may be one of the following:
|
|
|
|
// var = lb
|
|
|
|
// integer-type var = lb
|
|
|
|
// random-access-iterator-type var = lb
|
|
|
|
// pointer-type var = lb
|
|
|
|
//
|
|
|
|
if (!S) {
|
2015-04-30 12:23:23 +08:00
|
|
|
if (EmitDiags) {
|
|
|
|
SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init);
|
|
|
|
}
|
2014-06-03 18:16:47 +08:00
|
|
|
return true;
|
|
|
|
}
|
2014-10-01 14:03:56 +08:00
|
|
|
InitSrcRange = S->getSourceRange();
|
2014-06-03 18:16:47 +08:00
|
|
|
if (Expr *E = dyn_cast<Expr>(S))
|
|
|
|
S = E->IgnoreParens();
|
|
|
|
if (auto BO = dyn_cast<BinaryOperator>(S)) {
|
|
|
|
if (BO->getOpcode() == BO_Assign)
|
|
|
|
if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens()))
|
2014-07-25 14:27:47 +08:00
|
|
|
return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE,
|
2014-10-01 14:03:56 +08:00
|
|
|
BO->getRHS());
|
2014-06-03 18:16:47 +08:00
|
|
|
} else if (auto DS = dyn_cast<DeclStmt>(S)) {
|
|
|
|
if (DS->isSingleDecl()) {
|
|
|
|
if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) {
|
2015-08-06 20:30:57 +08:00
|
|
|
if (Var->hasInit() && !Var->getType()->isReferenceType()) {
|
2014-06-03 18:16:47 +08:00
|
|
|
// Accept non-canonical init form here but emit ext. warning.
|
2015-04-30 12:23:23 +08:00
|
|
|
if (Var->getInitStyle() != VarDecl::CInit && EmitDiags)
|
2014-06-03 18:16:47 +08:00
|
|
|
SemaRef.Diag(S->getLocStart(),
|
|
|
|
diag::ext_omp_loop_not_canonical_init)
|
|
|
|
<< S->getSourceRange();
|
2014-07-25 14:27:47 +08:00
|
|
|
return SetVarAndLB(Var, nullptr, Var->getInit());
|
2014-06-03 18:16:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S))
|
|
|
|
if (CE->getOperator() == OO_Equal)
|
|
|
|
if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0)))
|
2014-07-25 14:27:47 +08:00
|
|
|
return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE,
|
|
|
|
CE->getArg(1));
|
2014-06-03 18:16:47 +08:00
|
|
|
|
2015-04-30 12:23:23 +08:00
|
|
|
if (EmitDiags) {
|
|
|
|
SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init)
|
|
|
|
<< S->getSourceRange();
|
|
|
|
}
|
2014-06-03 18:16:47 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-18 15:08:49 +08:00
|
|
|
/// \brief Ignore parenthesizes, implicit casts, copy constructor and return the
|
2014-06-03 18:16:47 +08:00
|
|
|
/// variable (which may be the loop variable) if possible.
|
|
|
|
static const VarDecl *GetInitVarDecl(const Expr *E) {
|
|
|
|
if (!E)
|
2014-06-09 10:04:02 +08:00
|
|
|
return nullptr;
|
2015-07-15 20:14:07 +08:00
|
|
|
E = getExprAsWritten(E);
|
2014-06-03 18:16:47 +08:00
|
|
|
if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E))
|
|
|
|
if (const CXXConstructorDecl *Ctor = CE->getConstructor())
|
2015-07-16 12:19:43 +08:00
|
|
|
if ((Ctor->isCopyOrMoveConstructor() ||
|
|
|
|
Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) &&
|
|
|
|
CE->getNumArgs() > 0 && CE->getArg(0) != nullptr)
|
2014-06-03 18:16:47 +08:00
|
|
|
E = CE->getArg(0)->IgnoreParenImpCasts();
|
|
|
|
auto DRE = dyn_cast_or_null<DeclRefExpr>(E);
|
|
|
|
if (!DRE)
|
|
|
|
return nullptr;
|
|
|
|
return dyn_cast<VarDecl>(DRE->getDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) {
|
|
|
|
// Check test-expr for canonical form, save upper-bound UB, flags for
|
|
|
|
// less/greater and for strict/non-strict comparison.
|
|
|
|
// OpenMP [2.6] Canonical loop form. Test-expr may be one of the following:
|
|
|
|
// var relational-op b
|
|
|
|
// b relational-op var
|
|
|
|
//
|
|
|
|
if (!S) {
|
|
|
|
SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var;
|
|
|
|
return true;
|
|
|
|
}
|
2015-07-15 20:14:07 +08:00
|
|
|
S = getExprAsWritten(S);
|
2014-06-03 18:16:47 +08:00
|
|
|
SourceLocation CondLoc = S->getLocStart();
|
|
|
|
if (auto BO = dyn_cast<BinaryOperator>(S)) {
|
|
|
|
if (BO->isRelationalOp()) {
|
|
|
|
if (GetInitVarDecl(BO->getLHS()) == Var)
|
|
|
|
return SetUB(BO->getRHS(),
|
|
|
|
(BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE),
|
|
|
|
(BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT),
|
|
|
|
BO->getSourceRange(), BO->getOperatorLoc());
|
|
|
|
if (GetInitVarDecl(BO->getRHS()) == Var)
|
|
|
|
return SetUB(BO->getLHS(),
|
|
|
|
(BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE),
|
|
|
|
(BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT),
|
|
|
|
BO->getSourceRange(), BO->getOperatorLoc());
|
|
|
|
}
|
|
|
|
} else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) {
|
|
|
|
if (CE->getNumArgs() == 2) {
|
|
|
|
auto Op = CE->getOperator();
|
|
|
|
switch (Op) {
|
|
|
|
case OO_Greater:
|
|
|
|
case OO_GreaterEqual:
|
|
|
|
case OO_Less:
|
|
|
|
case OO_LessEqual:
|
|
|
|
if (GetInitVarDecl(CE->getArg(0)) == Var)
|
|
|
|
return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual,
|
|
|
|
Op == OO_Less || Op == OO_Greater, CE->getSourceRange(),
|
|
|
|
CE->getOperatorLoc());
|
|
|
|
if (GetInitVarDecl(CE->getArg(1)) == Var)
|
|
|
|
return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual,
|
|
|
|
Op == OO_Less || Op == OO_Greater, CE->getSourceRange(),
|
|
|
|
CE->getOperatorLoc());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond)
|
|
|
|
<< S->getSourceRange() << Var;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) {
|
|
|
|
// RHS of canonical loop form increment can be:
|
|
|
|
// var + incr
|
|
|
|
// incr + var
|
|
|
|
// var - incr
|
|
|
|
//
|
|
|
|
RHS = RHS->IgnoreParenImpCasts();
|
|
|
|
if (auto BO = dyn_cast<BinaryOperator>(RHS)) {
|
|
|
|
if (BO->isAdditiveOp()) {
|
|
|
|
bool IsAdd = BO->getOpcode() == BO_Add;
|
|
|
|
if (GetInitVarDecl(BO->getLHS()) == Var)
|
|
|
|
return SetStep(BO->getRHS(), !IsAdd);
|
|
|
|
if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var)
|
|
|
|
return SetStep(BO->getLHS(), false);
|
|
|
|
}
|
|
|
|
} else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) {
|
|
|
|
bool IsAdd = CE->getOperator() == OO_Plus;
|
|
|
|
if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) {
|
|
|
|
if (GetInitVarDecl(CE->getArg(0)) == Var)
|
|
|
|
return SetStep(CE->getArg(1), !IsAdd);
|
|
|
|
if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var)
|
|
|
|
return SetStep(CE->getArg(0), false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr)
|
|
|
|
<< RHS->getSourceRange() << Var;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) {
|
|
|
|
// Check incr-expr for canonical loop form and return true if it
|
|
|
|
// does not conform.
|
|
|
|
// OpenMP [2.6] Canonical loop form. Test-expr may be one of the following:
|
|
|
|
// ++var
|
|
|
|
// var++
|
|
|
|
// --var
|
|
|
|
// var--
|
|
|
|
// var += incr
|
|
|
|
// var -= incr
|
|
|
|
// var = var + incr
|
|
|
|
// var = incr + var
|
|
|
|
// var = var - incr
|
|
|
|
//
|
|
|
|
if (!S) {
|
|
|
|
SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var;
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-01 14:03:56 +08:00
|
|
|
IncrementSrcRange = S->getSourceRange();
|
2014-06-03 18:16:47 +08:00
|
|
|
S = S->IgnoreParens();
|
|
|
|
if (auto UO = dyn_cast<UnaryOperator>(S)) {
|
|
|
|
if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var)
|
|
|
|
return SetStep(
|
|
|
|
SemaRef.ActOnIntegerConstant(UO->getLocStart(),
|
|
|
|
(UO->isDecrementOp() ? -1 : 1)).get(),
|
|
|
|
false);
|
|
|
|
} else if (auto BO = dyn_cast<BinaryOperator>(S)) {
|
|
|
|
switch (BO->getOpcode()) {
|
|
|
|
case BO_AddAssign:
|
|
|
|
case BO_SubAssign:
|
|
|
|
if (GetInitVarDecl(BO->getLHS()) == Var)
|
|
|
|
return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign);
|
|
|
|
break;
|
|
|
|
case BO_Assign:
|
|
|
|
if (GetInitVarDecl(BO->getLHS()) == Var)
|
|
|
|
return CheckIncRHS(BO->getRHS());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) {
|
|
|
|
switch (CE->getOperator()) {
|
|
|
|
case OO_PlusPlus:
|
|
|
|
case OO_MinusMinus:
|
|
|
|
if (GetInitVarDecl(CE->getArg(0)) == Var)
|
|
|
|
return SetStep(
|
|
|
|
SemaRef.ActOnIntegerConstant(
|
|
|
|
CE->getLocStart(),
|
|
|
|
((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(),
|
|
|
|
false);
|
|
|
|
break;
|
|
|
|
case OO_PlusEqual:
|
|
|
|
case OO_MinusEqual:
|
|
|
|
if (GetInitVarDecl(CE->getArg(0)) == Var)
|
|
|
|
return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual);
|
|
|
|
break;
|
|
|
|
case OO_Equal:
|
|
|
|
if (GetInitVarDecl(CE->getArg(0)) == Var)
|
|
|
|
return CheckIncRHS(CE->getArg(1));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr)
|
|
|
|
<< S->getSourceRange() << Var;
|
|
|
|
return true;
|
|
|
|
}
|
2014-10-01 14:03:56 +08:00
|
|
|
|
2015-08-14 20:25:37 +08:00
|
|
|
namespace {
|
|
|
|
// Transform variables declared in GNU statement expressions to new ones to
|
|
|
|
// avoid crash on codegen.
|
|
|
|
class TransformToNewDefs : public TreeTransform<TransformToNewDefs> {
|
|
|
|
typedef TreeTransform<TransformToNewDefs> BaseTransform;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {}
|
|
|
|
|
|
|
|
Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
|
|
|
|
if (auto *VD = cast<VarDecl>(D))
|
|
|
|
if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) &&
|
|
|
|
!isa<ImplicitParamDecl>(D)) {
|
|
|
|
auto *NewVD = VarDecl::Create(
|
|
|
|
SemaRef.Context, VD->getDeclContext(), VD->getLocStart(),
|
|
|
|
VD->getLocation(), VD->getIdentifier(), VD->getType(),
|
|
|
|
VD->getTypeSourceInfo(), VD->getStorageClass());
|
|
|
|
NewVD->setTSCSpec(VD->getTSCSpec());
|
|
|
|
NewVD->setInit(VD->getInit());
|
|
|
|
NewVD->setInitStyle(VD->getInitStyle());
|
|
|
|
NewVD->setExceptionVariable(VD->isExceptionVariable());
|
|
|
|
NewVD->setNRVOVariable(VD->isNRVOVariable());
|
|
|
|
NewVD->setCXXForRangeDecl(VD->isInExternCXXContext());
|
|
|
|
NewVD->setConstexpr(VD->isConstexpr());
|
|
|
|
NewVD->setInitCapture(VD->isInitCapture());
|
|
|
|
NewVD->setPreviousDeclInSameBlockScope(
|
|
|
|
VD->isPreviousDeclInSameBlockScope());
|
|
|
|
VD->getDeclContext()->addHiddenDecl(NewVD);
|
2015-09-10 17:48:30 +08:00
|
|
|
if (VD->hasAttrs())
|
|
|
|
NewVD->setAttrs(VD->getAttrs());
|
2015-08-14 20:25:37 +08:00
|
|
|
transformedLocalDecl(VD, NewVD);
|
|
|
|
return NewVD;
|
|
|
|
}
|
|
|
|
return BaseTransform::TransformDefinition(Loc, D);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExprResult TransformDeclRefExpr(DeclRefExpr *E) {
|
|
|
|
if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl()))
|
|
|
|
if (E->getDecl() != NewD) {
|
|
|
|
NewD->setReferenced();
|
|
|
|
NewD->markUsed(SemaRef.Context);
|
|
|
|
return DeclRefExpr::Create(
|
|
|
|
SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(),
|
|
|
|
cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(),
|
|
|
|
E->getNameInfo(), E->getType(), E->getValueKind());
|
|
|
|
}
|
|
|
|
return BaseTransform::TransformDeclRefExpr(E);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief Build the expression to calculate the number of iterations.
|
2014-10-06 19:16:29 +08:00
|
|
|
Expr *
|
|
|
|
OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S,
|
|
|
|
const bool LimitedType) const {
|
2015-08-14 20:25:37 +08:00
|
|
|
TransformToNewDefs Transform(SemaRef);
|
2014-10-01 14:03:56 +08:00
|
|
|
ExprResult Diff;
|
2015-08-14 20:25:37 +08:00
|
|
|
auto VarType = Var->getType().getNonReferenceType();
|
|
|
|
if (VarType->isIntegerType() || VarType->isPointerType() ||
|
2014-10-01 14:03:56 +08:00
|
|
|
SemaRef.getLangOpts().CPlusPlus) {
|
|
|
|
// Upper - Lower
|
2015-08-14 20:25:37 +08:00
|
|
|
auto *UBExpr = TestIsLessOp ? UB : LB;
|
|
|
|
auto *LBExpr = TestIsLessOp ? LB : UB;
|
|
|
|
Expr *Upper = Transform.TransformExpr(UBExpr).get();
|
|
|
|
Expr *Lower = Transform.TransformExpr(LBExpr).get();
|
|
|
|
if (!Upper || !Lower)
|
|
|
|
return nullptr;
|
|
|
|
Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true)
|
|
|
|
.get();
|
|
|
|
Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true)
|
|
|
|
.get();
|
|
|
|
if (!Upper || !Lower)
|
|
|
|
return nullptr;
|
2014-10-01 14:03:56 +08:00
|
|
|
|
|
|
|
Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower);
|
|
|
|
|
2015-08-14 20:25:37 +08:00
|
|
|
if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) {
|
2014-10-01 14:03:56 +08:00
|
|
|
// BuildBinOp already emitted error, this one is to point user to upper
|
|
|
|
// and lower bound, and to tell what is passed to 'operator-'.
|
|
|
|
SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx)
|
|
|
|
<< Upper->getSourceRange() << Lower->getSourceRange();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Diff.isUsable())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Upper - Lower [- 1]
|
|
|
|
if (TestIsStrictOp)
|
|
|
|
Diff = SemaRef.BuildBinOp(
|
|
|
|
S, DefaultLoc, BO_Sub, Diff.get(),
|
|
|
|
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get());
|
|
|
|
if (!Diff.isUsable())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Upper - Lower [- 1] + Step
|
2015-08-14 20:25:37 +08:00
|
|
|
auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit());
|
|
|
|
if (NewStep.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
NewStep = SemaRef.PerformImplicitConversion(
|
|
|
|
NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
if (NewStep.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get());
|
2014-10-01 14:03:56 +08:00
|
|
|
if (!Diff.isUsable())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// Parentheses (for dumping/debugging purposes only).
|
|
|
|
Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get());
|
|
|
|
if (!Diff.isUsable())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// (Upper - Lower [- 1] + Step) / Step
|
2015-08-14 20:25:37 +08:00
|
|
|
NewStep = Transform.TransformExpr(Step->IgnoreImplicit());
|
|
|
|
if (NewStep.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
NewStep = SemaRef.PerformImplicitConversion(
|
|
|
|
NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
if (NewStep.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get());
|
2014-10-01 14:03:56 +08:00
|
|
|
if (!Diff.isUsable())
|
|
|
|
return nullptr;
|
|
|
|
|
2014-10-06 19:16:29 +08:00
|
|
|
// OpenMP runtime requires 32-bit or 64-bit loop variables.
|
2015-08-14 20:25:37 +08:00
|
|
|
QualType Type = Diff.get()->getType();
|
|
|
|
auto &C = SemaRef.Context;
|
|
|
|
bool UseVarType = VarType->hasIntegerRepresentation() &&
|
|
|
|
C.getTypeSize(Type) > C.getTypeSize(VarType);
|
|
|
|
if (!Type->isIntegerType() || UseVarType) {
|
|
|
|
unsigned NewSize =
|
|
|
|
UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type);
|
|
|
|
bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation()
|
|
|
|
: Type->hasSignedIntegerRepresentation();
|
|
|
|
Type = C.getIntTypeForBitwidth(NewSize, IsSigned);
|
|
|
|
Diff = SemaRef.PerformImplicitConversion(
|
|
|
|
Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true);
|
|
|
|
if (!Diff.isUsable())
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-06 19:16:29 +08:00
|
|
|
if (LimitedType) {
|
|
|
|
unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32;
|
|
|
|
if (NewSize != C.getTypeSize(Type)) {
|
|
|
|
if (NewSize < C.getTypeSize(Type)) {
|
|
|
|
assert(NewSize == 64 && "incorrect loop var size");
|
|
|
|
SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var)
|
|
|
|
<< InitSrcRange << ConditionSrcRange;
|
|
|
|
}
|
|
|
|
QualType NewType = C.getIntTypeForBitwidth(
|
2015-08-14 20:25:37 +08:00
|
|
|
NewSize, Type->hasSignedIntegerRepresentation() ||
|
|
|
|
C.getTypeSize(Type) < NewSize);
|
2014-10-06 19:16:29 +08:00
|
|
|
Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType,
|
|
|
|
Sema::AA_Converting, true);
|
|
|
|
if (!Diff.isUsable())
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
return Diff.get();
|
|
|
|
}
|
|
|
|
|
2015-04-22 19:59:37 +08:00
|
|
|
Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const {
|
|
|
|
// Try to build LB <op> UB, where <op> is <, >, <=, or >=.
|
|
|
|
bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics();
|
|
|
|
SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true);
|
2015-08-14 20:25:37 +08:00
|
|
|
TransformToNewDefs Transform(SemaRef);
|
|
|
|
|
|
|
|
auto NewLB = Transform.TransformExpr(LB);
|
|
|
|
auto NewUB = Transform.TransformExpr(UB);
|
|
|
|
if (NewLB.isInvalid() || NewUB.isInvalid())
|
|
|
|
return Cond;
|
|
|
|
NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
if (NewLB.isInvalid() || NewUB.isInvalid())
|
|
|
|
return Cond;
|
2015-04-22 19:59:37 +08:00
|
|
|
auto CondExpr = SemaRef.BuildBinOp(
|
|
|
|
S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE)
|
|
|
|
: (TestIsStrictOp ? BO_GT : BO_GE),
|
2015-08-14 20:25:37 +08:00
|
|
|
NewLB.get(), NewUB.get());
|
2015-07-15 20:14:07 +08:00
|
|
|
if (CondExpr.isUsable()) {
|
|
|
|
CondExpr = SemaRef.PerformImplicitConversion(
|
|
|
|
CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
}
|
2015-04-22 19:59:37 +08:00
|
|
|
SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress);
|
|
|
|
// Otherwise use original loop conditon and evaluate it in runtime.
|
|
|
|
return CondExpr.isUsable() ? CondExpr.get() : Cond;
|
|
|
|
}
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief Build reference expression to the counter be used for codegen.
|
|
|
|
Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const {
|
2015-08-06 20:30:57 +08:00
|
|
|
return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(),
|
|
|
|
DefaultLoc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const {
|
|
|
|
if (Var && !Var->isInvalidDecl()) {
|
|
|
|
auto Type = Var->getType().getNonReferenceType();
|
2015-09-10 17:48:30 +08:00
|
|
|
auto *PrivateVar =
|
|
|
|
buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(),
|
|
|
|
Var->hasAttrs() ? &Var->getAttrs() : nullptr);
|
2015-08-06 20:30:57 +08:00
|
|
|
if (PrivateVar->isInvalidDecl())
|
|
|
|
return nullptr;
|
|
|
|
return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc);
|
|
|
|
}
|
|
|
|
return nullptr;
|
2014-10-01 14:03:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Build initization of the counter be used for codegen.
|
|
|
|
Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; }
|
|
|
|
|
|
|
|
/// \brief Build step of the counter be used for codegen.
|
|
|
|
Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; }
|
|
|
|
|
|
|
|
/// \brief Iteration space of a single for loop.
|
|
|
|
struct LoopIterationSpace {
|
2015-04-22 19:59:37 +08:00
|
|
|
/// \brief Condition of the loop.
|
|
|
|
Expr *PreCond;
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief This expression calculates the number of iterations in the loop.
|
|
|
|
/// It is always possible to calculate it before starting the loop.
|
|
|
|
Expr *NumIterations;
|
|
|
|
/// \brief The loop counter variable.
|
|
|
|
Expr *CounterVar;
|
2015-08-06 20:30:57 +08:00
|
|
|
/// \brief Private loop counter variable.
|
|
|
|
Expr *PrivateCounterVar;
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief This is initializer for the initial value of #CounterVar.
|
|
|
|
Expr *CounterInit;
|
|
|
|
/// \brief This is step for the #CounterVar used to generate its update:
|
|
|
|
/// #CounterVar = #CounterInit + #CounterStep * CurrentIteration.
|
|
|
|
Expr *CounterStep;
|
|
|
|
/// \brief Should step be subtracted?
|
|
|
|
bool Subtract;
|
|
|
|
/// \brief Source range of the loop init.
|
|
|
|
SourceRange InitSrcRange;
|
|
|
|
/// \brief Source range of the loop condition.
|
|
|
|
SourceRange CondSrcRange;
|
|
|
|
/// \brief Source range of the loop increment.
|
|
|
|
SourceRange IncSrcRange;
|
|
|
|
};
|
|
|
|
|
2014-06-18 15:08:49 +08:00
|
|
|
} // namespace
|
2014-06-03 18:16:47 +08:00
|
|
|
|
2015-04-30 12:23:23 +08:00
|
|
|
void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) {
|
|
|
|
assert(getLangOpts().OpenMP && "OpenMP is not active.");
|
|
|
|
assert(Init && "Expected loop in canonical form.");
|
|
|
|
unsigned CollapseIteration = DSAStack->getCollapseNumber();
|
|
|
|
if (CollapseIteration > 0 &&
|
|
|
|
isOpenMPLoopDirective(DSAStack->getCurrentDirective())) {
|
|
|
|
OpenMPIterationSpaceChecker ISC(*this, ForLoc);
|
|
|
|
if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) {
|
|
|
|
DSAStack->addLoopControlVariable(ISC.GetLoopVar());
|
|
|
|
}
|
|
|
|
DSAStack->setCollapseNumber(CollapseIteration - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-03 18:16:47 +08:00
|
|
|
/// \brief Called on a for stmt to check and extract its iteration space
|
|
|
|
/// for further processing (such as collapsing).
|
2014-07-07 21:01:15 +08:00
|
|
|
static bool CheckOpenMPIterationSpace(
|
|
|
|
OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA,
|
|
|
|
unsigned CurrentNestedLoopCount, unsigned NestedLoopCount,
|
2015-07-30 19:36:16 +08:00
|
|
|
Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr,
|
2014-10-01 14:03:56 +08:00
|
|
|
llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA,
|
|
|
|
LoopIterationSpace &ResultIterSpace) {
|
2014-06-03 18:16:47 +08:00
|
|
|
// OpenMP [2.6, Canonical Loop Form]
|
|
|
|
// for (init-expr; test-expr; incr-expr) structured-block
|
|
|
|
auto For = dyn_cast_or_null<ForStmt>(S);
|
|
|
|
if (!For) {
|
|
|
|
SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for)
|
2015-07-30 19:36:16 +08:00
|
|
|
<< (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr)
|
|
|
|
<< getOpenMPDirectiveName(DKind) << NestedLoopCount
|
|
|
|
<< (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount;
|
|
|
|
if (NestedLoopCount > 1) {
|
|
|
|
if (CollapseLoopCountExpr && OrderedLoopCountExpr)
|
|
|
|
SemaRef.Diag(DSA.getConstructLoc(),
|
|
|
|
diag::note_omp_collapse_ordered_expr)
|
|
|
|
<< 2 << CollapseLoopCountExpr->getSourceRange()
|
|
|
|
<< OrderedLoopCountExpr->getSourceRange();
|
|
|
|
else if (CollapseLoopCountExpr)
|
|
|
|
SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(),
|
|
|
|
diag::note_omp_collapse_ordered_expr)
|
|
|
|
<< 0 << CollapseLoopCountExpr->getSourceRange();
|
|
|
|
else
|
|
|
|
SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(),
|
|
|
|
diag::note_omp_collapse_ordered_expr)
|
|
|
|
<< 1 << OrderedLoopCountExpr->getSourceRange();
|
|
|
|
}
|
2014-06-03 18:16:47 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
assert(For->getBody());
|
|
|
|
|
|
|
|
OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc());
|
|
|
|
|
|
|
|
// Check init.
|
2014-06-25 12:09:13 +08:00
|
|
|
auto Init = For->getInit();
|
2014-06-03 18:16:47 +08:00
|
|
|
if (ISC.CheckInit(Init)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasErrors = false;
|
|
|
|
|
|
|
|
// Check loop variable's type.
|
2014-06-25 12:09:13 +08:00
|
|
|
auto Var = ISC.GetLoopVar();
|
2014-06-03 18:16:47 +08:00
|
|
|
|
|
|
|
// OpenMP [2.6, Canonical Loop Form]
|
|
|
|
// Var is one of the following:
|
|
|
|
// A variable of signed or unsigned integer type.
|
|
|
|
// For C++, a variable of a random access iterator type.
|
|
|
|
// For C, a variable of a pointer type.
|
2015-08-06 20:30:57 +08:00
|
|
|
auto VarType = Var->getType().getNonReferenceType();
|
2014-06-03 18:16:47 +08:00
|
|
|
if (!VarType->isDependentType() && !VarType->isIntegerType() &&
|
|
|
|
!VarType->isPointerType() &&
|
|
|
|
!(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) {
|
|
|
|
SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type)
|
|
|
|
<< SemaRef.getLangOpts().CPlusPlus;
|
|
|
|
HasErrors = true;
|
|
|
|
}
|
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
// OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a
|
|
|
|
// Construct
|
|
|
|
// The loop iteration variable(s) in the associated for-loop(s) of a for or
|
|
|
|
// parallel for construct is (are) private.
|
|
|
|
// The loop iteration variable in the associated for-loop of a simd construct
|
|
|
|
// with just one associated for-loop is linear with a constant-linear-step
|
|
|
|
// that is the increment of the associated for-loop.
|
|
|
|
// Exclude loop var from the list of variables with implicitly defined data
|
|
|
|
// sharing attributes.
|
2014-10-10 23:32:48 +08:00
|
|
|
VarsWithImplicitDSA.erase(Var);
|
2014-07-07 21:01:15 +08:00
|
|
|
|
2014-06-03 18:16:47 +08:00
|
|
|
// OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in
|
|
|
|
// a Construct, C/C++].
|
2014-06-23 16:21:53 +08:00
|
|
|
// The loop iteration variable in the associated for-loop of a simd construct
|
|
|
|
// with just one associated for-loop may be listed in a linear clause with a
|
|
|
|
// constant-linear-step that is the increment of the associated for-loop.
|
2014-06-18 12:14:57 +08:00
|
|
|
// The loop iteration variable(s) in the associated for-loop(s) of a for or
|
|
|
|
// parallel for construct may be listed in a private or lastprivate clause.
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false);
|
2014-07-25 14:27:47 +08:00
|
|
|
auto LoopVarRefExpr = ISC.GetLoopVarRefExpr();
|
|
|
|
// If LoopVarRefExpr is nullptr it means the corresponding loop variable is
|
|
|
|
// declared in the loop and it is predetermined as a private.
|
2014-07-07 21:01:15 +08:00
|
|
|
auto PredeterminedCKind =
|
|
|
|
isOpenMPSimdDirective(DKind)
|
|
|
|
? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate)
|
|
|
|
: OMPC_private;
|
2014-06-18 12:14:57 +08:00
|
|
|
if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown &&
|
2015-05-12 17:02:07 +08:00
|
|
|
DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) ||
|
2014-09-18 13:12:34 +08:00
|
|
|
(isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) &&
|
|
|
|
DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private &&
|
2015-05-12 17:02:07 +08:00
|
|
|
DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) &&
|
|
|
|
((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) ||
|
|
|
|
DVar.RefExpr != nullptr)) {
|
2014-06-03 18:16:47 +08:00
|
|
|
SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa)
|
2014-07-07 21:01:15 +08:00
|
|
|
<< getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind)
|
|
|
|
<< getOpenMPClauseName(PredeterminedCKind);
|
2015-05-06 15:25:08 +08:00
|
|
|
if (DVar.RefExpr == nullptr)
|
|
|
|
DVar.CKind = PredeterminedCKind;
|
|
|
|
ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true);
|
2014-06-03 18:16:47 +08:00
|
|
|
HasErrors = true;
|
2014-07-25 14:27:47 +08:00
|
|
|
} else if (LoopVarRefExpr != nullptr) {
|
2014-07-07 21:01:15 +08:00
|
|
|
// Make the loop iteration variable private (for worksharing constructs),
|
|
|
|
// linear (for simd directives with the only one associated loop) or
|
2015-07-30 19:36:16 +08:00
|
|
|
// lastprivate (for simd directives with several collapsed or ordered
|
|
|
|
// loops).
|
2014-11-14 12:08:45 +08:00
|
|
|
if (DVar.CKind == OMPC_unknown)
|
|
|
|
DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(),
|
|
|
|
/*FromParent=*/false);
|
2015-04-30 12:23:23 +08:00
|
|
|
DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind);
|
2014-06-03 18:16:47 +08:00
|
|
|
}
|
|
|
|
|
2014-06-19 17:13:45 +08:00
|
|
|
assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars");
|
2014-06-04 21:06:39 +08:00
|
|
|
|
2014-06-03 18:16:47 +08:00
|
|
|
// Check test-expr.
|
|
|
|
HasErrors |= ISC.CheckCond(For->getCond());
|
|
|
|
|
|
|
|
// Check incr-expr.
|
|
|
|
HasErrors |= ISC.CheckInc(For->getInc());
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors)
|
2014-06-03 18:16:47 +08:00
|
|
|
return HasErrors;
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
// Build the loop's iteration space representation.
|
2015-04-22 19:59:37 +08:00
|
|
|
ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond());
|
2014-10-06 19:16:29 +08:00
|
|
|
ResultIterSpace.NumIterations = ISC.BuildNumIterations(
|
|
|
|
DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind));
|
2014-10-01 14:03:56 +08:00
|
|
|
ResultIterSpace.CounterVar = ISC.BuildCounterVar();
|
2015-08-06 20:30:57 +08:00
|
|
|
ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar();
|
2014-10-01 14:03:56 +08:00
|
|
|
ResultIterSpace.CounterInit = ISC.BuildCounterInit();
|
|
|
|
ResultIterSpace.CounterStep = ISC.BuildCounterStep();
|
|
|
|
ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange();
|
|
|
|
ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange();
|
|
|
|
ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange();
|
|
|
|
ResultIterSpace.Subtract = ISC.ShouldSubtractStep();
|
|
|
|
|
2015-04-22 19:59:37 +08:00
|
|
|
HasErrors |= (ResultIterSpace.PreCond == nullptr ||
|
|
|
|
ResultIterSpace.NumIterations == nullptr ||
|
2014-10-01 14:03:56 +08:00
|
|
|
ResultIterSpace.CounterVar == nullptr ||
|
2015-08-06 20:30:57 +08:00
|
|
|
ResultIterSpace.PrivateCounterVar == nullptr ||
|
2014-10-01 14:03:56 +08:00
|
|
|
ResultIterSpace.CounterInit == nullptr ||
|
|
|
|
ResultIterSpace.CounterStep == nullptr);
|
|
|
|
|
2014-06-03 18:16:47 +08:00
|
|
|
return HasErrors;
|
|
|
|
}
|
|
|
|
|
2015-08-14 20:25:37 +08:00
|
|
|
/// \brief Build 'VarRef = Start.
|
|
|
|
static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc,
|
|
|
|
ExprResult VarRef, ExprResult Start) {
|
|
|
|
TransformToNewDefs Transform(SemaRef);
|
|
|
|
// Build 'VarRef = Start.
|
|
|
|
auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit());
|
|
|
|
if (NewStart.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
NewStart = SemaRef.PerformImplicitConversion(
|
|
|
|
NewStart.get(), Start.get()->IgnoreImplicit()->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
if (NewStart.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
NewStart = SemaRef.PerformImplicitConversion(
|
|
|
|
NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
if (!NewStart.isUsable())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
auto Init =
|
|
|
|
SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get());
|
|
|
|
return Init;
|
|
|
|
}
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
/// \brief Build 'VarRef = Start + Iter * Step'.
|
|
|
|
static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S,
|
|
|
|
SourceLocation Loc, ExprResult VarRef,
|
|
|
|
ExprResult Start, ExprResult Iter,
|
|
|
|
ExprResult Step, bool Subtract) {
|
|
|
|
// Add parentheses (for debugging purposes only).
|
|
|
|
Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get());
|
|
|
|
if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() ||
|
|
|
|
!Step.isUsable())
|
|
|
|
return ExprError();
|
|
|
|
|
2015-08-14 20:25:37 +08:00
|
|
|
TransformToNewDefs Transform(SemaRef);
|
|
|
|
auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit());
|
|
|
|
if (NewStep.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
NewStep = SemaRef.PerformImplicitConversion(
|
|
|
|
NewStep.get(), Step.get()->IgnoreImplicit()->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
if (NewStep.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
ExprResult Update =
|
|
|
|
SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get());
|
2014-10-01 14:03:56 +08:00
|
|
|
if (!Update.isUsable())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
// Build 'VarRef = Start + Iter * Step'.
|
2015-08-14 20:25:37 +08:00
|
|
|
auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit());
|
|
|
|
if (NewStart.isInvalid())
|
|
|
|
return ExprError();
|
|
|
|
NewStart = SemaRef.PerformImplicitConversion(
|
|
|
|
NewStart.get(), Start.get()->IgnoreImplicit()->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true);
|
|
|
|
if (NewStart.isInvalid())
|
|
|
|
return ExprError();
|
2014-10-01 14:03:56 +08:00
|
|
|
Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add),
|
2015-08-14 20:25:37 +08:00
|
|
|
NewStart.get(), Update.get());
|
2014-10-01 14:03:56 +08:00
|
|
|
if (!Update.isUsable())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
Update = SemaRef.PerformImplicitConversion(
|
|
|
|
Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true);
|
|
|
|
if (!Update.isUsable())
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get());
|
|
|
|
return Update;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Convert integer expression \a E to make it have at least \a Bits
|
|
|
|
/// bits.
|
|
|
|
static ExprResult WidenIterationCount(unsigned Bits, Expr *E,
|
|
|
|
Sema &SemaRef) {
|
|
|
|
if (E == nullptr)
|
|
|
|
return ExprError();
|
|
|
|
auto &C = SemaRef.Context;
|
|
|
|
QualType OldType = E->getType();
|
|
|
|
unsigned HasBits = C.getTypeSize(OldType);
|
|
|
|
if (HasBits >= Bits)
|
|
|
|
return ExprResult(E);
|
|
|
|
// OK to convert to signed, because new type has more bits than old.
|
|
|
|
QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true);
|
|
|
|
return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting,
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Check if the given expression \a E is a constant integer that fits
|
|
|
|
/// into \a Bits bits.
|
|
|
|
static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) {
|
|
|
|
if (E == nullptr)
|
|
|
|
return false;
|
|
|
|
llvm::APSInt Result;
|
|
|
|
if (E->isIntegerConstantExpr(Result, SemaRef.Context))
|
|
|
|
return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits);
|
|
|
|
return false;
|
2014-06-03 18:16:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Called on a for stmt to check itself and nested loops (if any).
|
2014-06-25 14:52:00 +08:00
|
|
|
/// \return Returns 0 if one of the collapsed stmts is not canonical for loop,
|
|
|
|
/// number of collapsed loops otherwise.
|
2014-07-07 21:01:15 +08:00
|
|
|
static unsigned
|
2015-07-30 19:36:16 +08:00
|
|
|
CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
|
|
|
|
Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef,
|
|
|
|
DSAStackTy &DSA,
|
2014-10-01 14:03:56 +08:00
|
|
|
llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA,
|
2014-12-15 15:07:06 +08:00
|
|
|
OMPLoopDirective::HelperExprs &Built) {
|
2014-06-24 20:55:56 +08:00
|
|
|
unsigned NestedLoopCount = 1;
|
2015-07-30 19:36:16 +08:00
|
|
|
if (CollapseLoopCountExpr) {
|
2014-06-24 20:55:56 +08:00
|
|
|
// Found 'collapse' clause - calculate collapse number.
|
|
|
|
llvm::APSInt Result;
|
2015-07-30 19:36:16 +08:00
|
|
|
if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))
|
|
|
|
NestedLoopCount += Result.getLimitedValue() - 1;
|
|
|
|
}
|
|
|
|
if (OrderedLoopCountExpr) {
|
|
|
|
// Found 'ordered' clause - calculate collapse number.
|
|
|
|
llvm::APSInt Result;
|
|
|
|
if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext()))
|
|
|
|
NestedLoopCount += Result.getLimitedValue() - 1;
|
2014-06-24 20:55:56 +08:00
|
|
|
}
|
2014-06-03 18:16:47 +08:00
|
|
|
// This is helper routine for loop directives (e.g., 'for', 'simd',
|
|
|
|
// 'for simd', etc.).
|
2014-10-01 14:03:56 +08:00
|
|
|
SmallVector<LoopIterationSpace, 4> IterSpaces;
|
|
|
|
IterSpaces.resize(NestedLoopCount);
|
|
|
|
Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true);
|
2014-06-03 18:16:47 +08:00
|
|
|
for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) {
|
2014-06-24 20:55:56 +08:00
|
|
|
if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt,
|
2015-07-30 19:36:16 +08:00
|
|
|
NestedLoopCount, CollapseLoopCountExpr,
|
|
|
|
OrderedLoopCountExpr, VarsWithImplicitDSA,
|
|
|
|
IterSpaces[Cnt]))
|
2014-06-25 14:52:00 +08:00
|
|
|
return 0;
|
2014-06-03 18:16:47 +08:00
|
|
|
// Move on to the next nested for loop, or to the loop body.
|
2014-10-01 14:03:56 +08:00
|
|
|
// OpenMP [2.8.1, simd construct, Restrictions]
|
|
|
|
// All loops associated with the construct must be perfectly nested; that
|
|
|
|
// is, there must be no intervening code nor any OpenMP directive between
|
|
|
|
// any two loops.
|
|
|
|
CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers();
|
|
|
|
}
|
|
|
|
|
|
|
|
Built.clear(/* size */ NestedLoopCount);
|
|
|
|
|
|
|
|
if (SemaRef.CurContext->isDependentContext())
|
|
|
|
return NestedLoopCount;
|
|
|
|
|
|
|
|
// An example of what is generated for the following code:
|
|
|
|
//
|
2015-07-30 19:36:16 +08:00
|
|
|
// #pragma omp simd collapse(2) ordered(2)
|
2014-10-01 14:03:56 +08:00
|
|
|
// for (i = 0; i < NI; ++i)
|
2015-07-30 19:36:16 +08:00
|
|
|
// for (k = 0; k < NK; ++k)
|
|
|
|
// for (j = J0; j < NJ; j+=2) {
|
|
|
|
// <loop body>
|
|
|
|
// }
|
2014-10-01 14:03:56 +08:00
|
|
|
//
|
|
|
|
// We generate the code below.
|
|
|
|
// Note: the loop body may be outlined in CodeGen.
|
|
|
|
// Note: some counters may be C++ classes, operator- is used to find number of
|
|
|
|
// iterations and operator+= to calculate counter value.
|
|
|
|
// Note: decltype(NumIterations) must be integer type (in 'omp for', only i32
|
|
|
|
// or i64 is currently supported).
|
|
|
|
//
|
|
|
|
// #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2))
|
|
|
|
// for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) {
|
|
|
|
// .local.i = IV / ((NJ - J0 - 1 + 2) / 2);
|
|
|
|
// .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2;
|
|
|
|
// // similar updates for vars in clauses (e.g. 'linear')
|
|
|
|
// <loop body (using local i and j)>
|
|
|
|
// }
|
|
|
|
// i = NI; // assign final values of counters
|
|
|
|
// j = NJ;
|
|
|
|
//
|
|
|
|
|
|
|
|
// Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are
|
|
|
|
// the iteration counts of the collapsed for loops.
|
2015-04-22 19:59:37 +08:00
|
|
|
// Precondition tests if there is at least one iteration (all conditions are
|
|
|
|
// true).
|
|
|
|
auto PreCond = ExprResult(IterSpaces[0].PreCond);
|
2014-10-01 14:03:56 +08:00
|
|
|
auto N0 = IterSpaces[0].NumIterations;
|
2015-08-14 20:25:37 +08:00
|
|
|
ExprResult LastIteration32 = WidenIterationCount(
|
|
|
|
32 /* Bits */, SemaRef.PerformImplicitConversion(
|
|
|
|
N0->IgnoreImpCasts(), N0->getType(),
|
|
|
|
Sema::AA_Converting, /*AllowExplicit=*/true)
|
|
|
|
.get(),
|
|
|
|
SemaRef);
|
|
|
|
ExprResult LastIteration64 = WidenIterationCount(
|
|
|
|
64 /* Bits */, SemaRef.PerformImplicitConversion(
|
|
|
|
N0->IgnoreImpCasts(), N0->getType(),
|
|
|
|
Sema::AA_Converting, /*AllowExplicit=*/true)
|
|
|
|
.get(),
|
|
|
|
SemaRef);
|
2014-10-01 14:03:56 +08:00
|
|
|
|
|
|
|
if (!LastIteration32.isUsable() || !LastIteration64.isUsable())
|
|
|
|
return NestedLoopCount;
|
|
|
|
|
|
|
|
auto &C = SemaRef.Context;
|
|
|
|
bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32;
|
|
|
|
|
|
|
|
Scope *CurScope = DSA.getCurScope();
|
|
|
|
for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) {
|
2015-04-22 19:59:37 +08:00
|
|
|
if (PreCond.isUsable()) {
|
|
|
|
PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd,
|
|
|
|
PreCond.get(), IterSpaces[Cnt].PreCond);
|
|
|
|
}
|
2014-10-01 14:03:56 +08:00
|
|
|
auto N = IterSpaces[Cnt].NumIterations;
|
|
|
|
AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32;
|
|
|
|
if (LastIteration32.isUsable())
|
2015-08-14 20:25:37 +08:00
|
|
|
LastIteration32 = SemaRef.BuildBinOp(
|
|
|
|
CurScope, SourceLocation(), BO_Mul, LastIteration32.get(),
|
|
|
|
SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true)
|
|
|
|
.get());
|
2014-10-01 14:03:56 +08:00
|
|
|
if (LastIteration64.isUsable())
|
2015-08-14 20:25:37 +08:00
|
|
|
LastIteration64 = SemaRef.BuildBinOp(
|
|
|
|
CurScope, SourceLocation(), BO_Mul, LastIteration64.get(),
|
|
|
|
SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(),
|
|
|
|
Sema::AA_Converting,
|
|
|
|
/*AllowExplicit=*/true)
|
|
|
|
.get());
|
2014-10-01 14:03:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Choose either the 32-bit or 64-bit version.
|
|
|
|
ExprResult LastIteration = LastIteration64;
|
|
|
|
if (LastIteration32.isUsable() &&
|
|
|
|
C.getTypeSize(LastIteration32.get()->getType()) == 32 &&
|
|
|
|
(AllCountsNeedLessThan32Bits || NestedLoopCount == 1 ||
|
|
|
|
FitsInto(
|
|
|
|
32 /* Bits */,
|
|
|
|
LastIteration32.get()->getType()->hasSignedIntegerRepresentation(),
|
|
|
|
LastIteration64.get(), SemaRef)))
|
|
|
|
LastIteration = LastIteration32;
|
|
|
|
|
|
|
|
if (!LastIteration.isUsable())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Save the number of iterations.
|
|
|
|
ExprResult NumIterations = LastIteration;
|
|
|
|
{
|
|
|
|
LastIteration = SemaRef.BuildBinOp(
|
|
|
|
CurScope, SourceLocation(), BO_Sub, LastIteration.get(),
|
|
|
|
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get());
|
|
|
|
if (!LastIteration.isUsable())
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the last iteration number beforehand instead of doing this on
|
|
|
|
// each iteration. Do not do this if the number of iterations may be kfold-ed.
|
|
|
|
llvm::APSInt Result;
|
|
|
|
bool IsConstant =
|
|
|
|
LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context);
|
|
|
|
ExprResult CalcLastIteration;
|
|
|
|
if (!IsConstant) {
|
|
|
|
SourceLocation SaveLoc;
|
|
|
|
VarDecl *SaveVar =
|
2015-05-08 18:41:21 +08:00
|
|
|
buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(),
|
2014-10-01 14:03:56 +08:00
|
|
|
".omp.last.iteration");
|
2015-05-08 18:41:21 +08:00
|
|
|
ExprResult SaveRef = buildDeclRefExpr(
|
|
|
|
SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc);
|
2014-10-01 14:03:56 +08:00
|
|
|
CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign,
|
|
|
|
SaveRef.get(), LastIteration.get());
|
|
|
|
LastIteration = SaveRef;
|
|
|
|
|
|
|
|
// Prepare SaveRef + 1.
|
|
|
|
NumIterations = SemaRef.BuildBinOp(
|
|
|
|
CurScope, SaveLoc, BO_Add, SaveRef.get(),
|
|
|
|
SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get());
|
|
|
|
if (!NumIterations.isUsable())
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin();
|
|
|
|
|
2014-12-15 15:07:06 +08:00
|
|
|
QualType VType = LastIteration.get()->getType();
|
|
|
|
// Build variables passed into runtime, nesessary for worksharing directives.
|
|
|
|
ExprResult LB, UB, IL, ST, EUB;
|
|
|
|
if (isOpenMPWorksharingDirective(DKind)) {
|
|
|
|
// Lower bound variable, initialized with zero.
|
2015-05-08 18:41:21 +08:00
|
|
|
VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb");
|
|
|
|
LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc);
|
2014-12-15 15:07:06 +08:00
|
|
|
SemaRef.AddInitializerToDecl(
|
|
|
|
LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(),
|
|
|
|
/*DirectInit*/ false, /*TypeMayContainAuto*/ false);
|
|
|
|
|
|
|
|
// Upper bound variable, initialized with last iteration number.
|
2015-05-08 18:41:21 +08:00
|
|
|
VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub");
|
|
|
|
UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc);
|
2014-12-15 15:07:06 +08:00
|
|
|
SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(),
|
|
|
|
/*DirectInit*/ false,
|
|
|
|
/*TypeMayContainAuto*/ false);
|
|
|
|
|
|
|
|
// A 32-bit variable-flag where runtime returns 1 for the last iteration.
|
|
|
|
// This will be used to implement clause 'lastprivate'.
|
|
|
|
QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true);
|
2015-05-08 18:41:21 +08:00
|
|
|
VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last");
|
|
|
|
IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc);
|
2014-12-15 15:07:06 +08:00
|
|
|
SemaRef.AddInitializerToDecl(
|
|
|
|
ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(),
|
|
|
|
/*DirectInit*/ false, /*TypeMayContainAuto*/ false);
|
|
|
|
|
|
|
|
// Stride variable returned by runtime (we initialize it to 1 by default).
|
2015-05-08 18:41:21 +08:00
|
|
|
VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride");
|
|
|
|
ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc);
|
2014-12-15 15:07:06 +08:00
|
|
|
SemaRef.AddInitializerToDecl(
|
|
|
|
STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(),
|
|
|
|
/*DirectInit*/ false, /*TypeMayContainAuto*/ false);
|
|
|
|
|
|
|
|
// Build expression: UB = min(UB, LastIteration)
|
|
|
|
// It is nesessary for CodeGen of directives with static scheduling.
|
|
|
|
ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT,
|
|
|
|
UB.get(), LastIteration.get());
|
|
|
|
ExprResult CondOp = SemaRef.ActOnConditionalOp(
|
|
|
|
InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get());
|
|
|
|
EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(),
|
|
|
|
CondOp.get());
|
|
|
|
EUB = SemaRef.ActOnFinishFullExpr(EUB.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the iteration variable and its initialization before loop.
|
2014-10-01 14:03:56 +08:00
|
|
|
ExprResult IV;
|
|
|
|
ExprResult Init;
|
|
|
|
{
|
2015-05-08 18:41:21 +08:00
|
|
|
VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv");
|
|
|
|
IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc);
|
2014-12-15 15:07:06 +08:00
|
|
|
Expr *RHS = isOpenMPWorksharingDirective(DKind)
|
|
|
|
? LB.get()
|
|
|
|
: SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get();
|
|
|
|
Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS);
|
|
|
|
Init = SemaRef.ActOnFinishFullExpr(Init.get());
|
2014-10-01 14:03:56 +08:00
|
|
|
}
|
|
|
|
|
2014-12-15 15:07:06 +08:00
|
|
|
// Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops.
|
2014-10-01 14:03:56 +08:00
|
|
|
SourceLocation CondLoc;
|
2014-12-15 15:07:06 +08:00
|
|
|
ExprResult Cond =
|
|
|
|
isOpenMPWorksharingDirective(DKind)
|
|
|
|
? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get())
|
|
|
|
: SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(),
|
|
|
|
NumIterations.get());
|
2014-10-01 14:03:56 +08:00
|
|
|
|
|
|
|
// Loop increment (IV = IV + 1)
|
|
|
|
SourceLocation IncLoc;
|
|
|
|
ExprResult Inc =
|
|
|
|
SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(),
|
|
|
|
SemaRef.ActOnIntegerConstant(IncLoc, 1).get());
|
|
|
|
if (!Inc.isUsable())
|
|
|
|
return 0;
|
|
|
|
Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get());
|
2014-12-15 15:07:06 +08:00
|
|
|
Inc = SemaRef.ActOnFinishFullExpr(Inc.get());
|
|
|
|
if (!Inc.isUsable())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Increments for worksharing loops (LB = LB + ST; UB = UB + ST).
|
|
|
|
// Used for directives with static scheduling.
|
|
|
|
ExprResult NextLB, NextUB;
|
|
|
|
if (isOpenMPWorksharingDirective(DKind)) {
|
|
|
|
// LB + ST
|
|
|
|
NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get());
|
|
|
|
if (!NextLB.isUsable())
|
|
|
|
return 0;
|
|
|
|
// LB = LB + ST
|
|
|
|
NextLB =
|
|
|
|
SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get());
|
|
|
|
NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get());
|
|
|
|
if (!NextLB.isUsable())
|
|
|
|
return 0;
|
|
|
|
// UB + ST
|
|
|
|
NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get());
|
|
|
|
if (!NextUB.isUsable())
|
|
|
|
return 0;
|
|
|
|
// UB = UB + ST
|
|
|
|
NextUB =
|
|
|
|
SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get());
|
|
|
|
NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get());
|
|
|
|
if (!NextUB.isUsable())
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-01 14:03:56 +08:00
|
|
|
|
|
|
|
// Build updates and final values of the loop counters.
|
|
|
|
bool HasErrors = false;
|
|
|
|
Built.Counters.resize(NestedLoopCount);
|
2015-08-14 20:25:37 +08:00
|
|
|
Built.Inits.resize(NestedLoopCount);
|
2014-10-01 14:03:56 +08:00
|
|
|
Built.Updates.resize(NestedLoopCount);
|
|
|
|
Built.Finals.resize(NestedLoopCount);
|
|
|
|
{
|
|
|
|
ExprResult Div;
|
|
|
|
// Go from inner nested loop to outer.
|
|
|
|
for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) {
|
|
|
|
LoopIterationSpace &IS = IterSpaces[Cnt];
|
|
|
|
SourceLocation UpdLoc = IS.IncSrcRange.getBegin();
|
|
|
|
// Build: Iter = (IV / Div) % IS.NumIters
|
|
|
|
// where Div is product of previous iterations' IS.NumIters.
|
|
|
|
ExprResult Iter;
|
|
|
|
if (Div.isUsable()) {
|
|
|
|
Iter =
|
|
|
|
SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get());
|
|
|
|
} else {
|
|
|
|
Iter = IV;
|
|
|
|
assert((Cnt == (int)NestedLoopCount - 1) &&
|
|
|
|
"unusable div expected on first iteration only");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Cnt != 0 && Iter.isUsable())
|
|
|
|
Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(),
|
|
|
|
IS.NumIterations);
|
|
|
|
if (!Iter.isUsable()) {
|
|
|
|
HasErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-08 18:41:21 +08:00
|
|
|
// Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step
|
|
|
|
auto *CounterVar = buildDeclRefExpr(
|
|
|
|
SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()),
|
|
|
|
IS.CounterVar->getType(), IS.CounterVar->getExprLoc(),
|
|
|
|
/*RefersToCapture=*/true);
|
2015-08-14 20:25:37 +08:00
|
|
|
ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar,
|
|
|
|
IS.CounterInit);
|
|
|
|
if (!Init.isUsable()) {
|
|
|
|
HasErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
2014-10-01 14:03:56 +08:00
|
|
|
ExprResult Update =
|
2015-05-08 18:41:21 +08:00
|
|
|
BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar,
|
2014-10-01 14:03:56 +08:00
|
|
|
IS.CounterInit, Iter, IS.CounterStep, IS.Subtract);
|
|
|
|
if (!Update.isUsable()) {
|
|
|
|
HasErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step
|
|
|
|
ExprResult Final = BuildCounterUpdate(
|
2015-05-08 18:41:21 +08:00
|
|
|
SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit,
|
2014-10-01 14:03:56 +08:00
|
|
|
IS.NumIterations, IS.CounterStep, IS.Subtract);
|
|
|
|
if (!Final.isUsable()) {
|
|
|
|
HasErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build Div for the next iteration: Div <- Div * IS.NumIters
|
|
|
|
if (Cnt != 0) {
|
|
|
|
if (Div.isUnset())
|
|
|
|
Div = IS.NumIterations;
|
|
|
|
else
|
|
|
|
Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(),
|
|
|
|
IS.NumIterations);
|
|
|
|
|
|
|
|
// Add parentheses (for debugging purposes only).
|
|
|
|
if (Div.isUsable())
|
|
|
|
Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get());
|
|
|
|
if (!Div.isUsable()) {
|
|
|
|
HasErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!Update.isUsable() || !Final.isUsable()) {
|
|
|
|
HasErrors = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Save results
|
|
|
|
Built.Counters[Cnt] = IS.CounterVar;
|
2015-08-06 20:30:57 +08:00
|
|
|
Built.PrivateCounters[Cnt] = IS.PrivateCounterVar;
|
2015-08-14 20:25:37 +08:00
|
|
|
Built.Inits[Cnt] = Init.get();
|
2014-10-01 14:03:56 +08:00
|
|
|
Built.Updates[Cnt] = Update.get();
|
|
|
|
Built.Finals[Cnt] = Final.get();
|
|
|
|
}
|
2014-06-03 18:16:47 +08:00
|
|
|
}
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
if (HasErrors)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Save results
|
|
|
|
Built.IterationVarRef = IV.get();
|
|
|
|
Built.LastIteration = LastIteration.get();
|
2015-03-21 18:12:56 +08:00
|
|
|
Built.NumIterations = NumIterations.get();
|
2015-07-15 20:14:07 +08:00
|
|
|
Built.CalcLastIteration =
|
|
|
|
SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get();
|
2014-10-01 14:03:56 +08:00
|
|
|
Built.PreCond = PreCond.get();
|
|
|
|
Built.Cond = Cond.get();
|
|
|
|
Built.Init = Init.get();
|
|
|
|
Built.Inc = Inc.get();
|
2014-12-15 15:07:06 +08:00
|
|
|
Built.LB = LB.get();
|
|
|
|
Built.UB = UB.get();
|
|
|
|
Built.IL = IL.get();
|
|
|
|
Built.ST = ST.get();
|
|
|
|
Built.EUB = EUB.get();
|
|
|
|
Built.NLB = NextLB.get();
|
|
|
|
Built.NUB = NextUB.get();
|
2014-10-01 14:03:56 +08:00
|
|
|
|
2014-06-25 14:52:00 +08:00
|
|
|
return NestedLoopCount;
|
2014-06-03 18:16:47 +08:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:36:16 +08:00
|
|
|
static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) {
|
2015-08-30 23:12:28 +08:00
|
|
|
auto CollapseClauses =
|
|
|
|
OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses);
|
|
|
|
if (CollapseClauses.begin() != CollapseClauses.end())
|
|
|
|
return (*CollapseClauses.begin())->getNumForLoops();
|
2014-06-24 20:55:56 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:36:16 +08:00
|
|
|
static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) {
|
2015-08-30 23:12:28 +08:00
|
|
|
auto OrderedClauses =
|
|
|
|
OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses);
|
|
|
|
if (OrderedClauses.begin() != OrderedClauses.end())
|
|
|
|
return (*OrderedClauses.begin())->getNumForLoops();
|
2015-07-30 19:36:16 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:14:16 +08:00
|
|
|
static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen,
|
|
|
|
const Expr *Safelen) {
|
|
|
|
llvm::APSInt SimdlenRes, SafelenRes;
|
|
|
|
if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() ||
|
|
|
|
Simdlen->isInstantiationDependent() ||
|
|
|
|
Simdlen->containsUnexpandedParameterPack())
|
|
|
|
return false;
|
|
|
|
if (Safelen->isValueDependent() || Safelen->isTypeDependent() ||
|
|
|
|
Safelen->isInstantiationDependent() ||
|
|
|
|
Safelen->containsUnexpandedParameterPack())
|
|
|
|
return false;
|
|
|
|
Simdlen->EvaluateAsInt(SimdlenRes, S.Context);
|
|
|
|
Safelen->EvaluateAsInt(SafelenRes, S.Context);
|
|
|
|
// OpenMP 4.1 [2.8.1, simd Construct, Restrictions]
|
|
|
|
// If both simdlen and safelen clauses are specified, the value of the simdlen
|
|
|
|
// parameter must be less than or equal to the value of the safelen parameter.
|
|
|
|
if (SimdlenRes > SafelenRes) {
|
|
|
|
S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values)
|
|
|
|
<< Simdlen->getSourceRange() << Safelen->getSourceRange();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPSimdDirective(
|
|
|
|
ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-12-15 15:07:06 +08:00
|
|
|
OMPLoopDirective::HelperExprs B;
|
2015-07-30 19:36:16 +08:00
|
|
|
// In presence of clause 'collapse' or 'ordered' with number of loops, it will
|
|
|
|
// define the nested loops number.
|
|
|
|
unsigned NestedLoopCount = CheckOpenMPLoop(
|
|
|
|
OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses),
|
|
|
|
AStmt, *this, *DSAStack, VarsWithImplicitDSA, B);
|
2014-06-25 14:52:00 +08:00
|
|
|
if (NestedLoopCount == 0)
|
2014-02-27 16:29:12 +08:00
|
|
|
return StmtError();
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
assert((CurContext->isDependentContext() || B.builtAll()) &&
|
|
|
|
"omp simd loop exprs were not built");
|
|
|
|
|
2015-03-21 18:12:56 +08:00
|
|
|
if (!CurContext->isDependentContext()) {
|
|
|
|
// Finalize the clauses that need pre-built expressions for CodeGen.
|
|
|
|
for (auto C : Clauses) {
|
|
|
|
if (auto LC = dyn_cast<OMPLinearClause>(C))
|
|
|
|
if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef),
|
|
|
|
B.NumIterations, *this, CurScope))
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:14:16 +08:00
|
|
|
// OpenMP 4.1 [2.8.1, simd Construct, Restrictions]
|
|
|
|
// If both simdlen and safelen clauses are specified, the value of the simdlen
|
|
|
|
// parameter must be less than or equal to the value of the safelen parameter.
|
|
|
|
OMPSafelenClause *Safelen = nullptr;
|
|
|
|
OMPSimdlenClause *Simdlen = nullptr;
|
|
|
|
for (auto *Clause : Clauses) {
|
|
|
|
if (Clause->getClauseKind() == OMPC_safelen)
|
|
|
|
Safelen = cast<OMPSafelenClause>(Clause);
|
|
|
|
else if (Clause->getClauseKind() == OMPC_simdlen)
|
|
|
|
Simdlen = cast<OMPSimdlenClause>(Clause);
|
|
|
|
if (Safelen && Simdlen)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Simdlen && Safelen &&
|
|
|
|
checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(),
|
|
|
|
Safelen->getSafelen()))
|
|
|
|
return StmtError();
|
|
|
|
|
2014-02-27 16:29:12 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
2014-12-15 15:07:06 +08:00
|
|
|
return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount,
|
|
|
|
Clauses, AStmt, B);
|
2014-02-27 16:29:12 +08:00
|
|
|
}
|
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPForDirective(
|
|
|
|
ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-12-15 15:07:06 +08:00
|
|
|
OMPLoopDirective::HelperExprs B;
|
2015-07-30 19:36:16 +08:00
|
|
|
// In presence of clause 'collapse' or 'ordered' with number of loops, it will
|
|
|
|
// define the nested loops number.
|
|
|
|
unsigned NestedLoopCount = CheckOpenMPLoop(
|
|
|
|
OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses),
|
|
|
|
AStmt, *this, *DSAStack, VarsWithImplicitDSA, B);
|
2014-06-25 14:52:00 +08:00
|
|
|
if (NestedLoopCount == 0)
|
2014-06-18 12:14:57 +08:00
|
|
|
return StmtError();
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
assert((CurContext->isDependentContext() || B.builtAll()) &&
|
|
|
|
"omp for loop exprs were not built");
|
|
|
|
|
2015-08-04 19:18:19 +08:00
|
|
|
if (!CurContext->isDependentContext()) {
|
|
|
|
// Finalize the clauses that need pre-built expressions for CodeGen.
|
|
|
|
for (auto C : Clauses) {
|
|
|
|
if (auto LC = dyn_cast<OMPLinearClause>(C))
|
|
|
|
if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef),
|
|
|
|
B.NumIterations, *this, CurScope))
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
2014-12-15 15:07:06 +08:00
|
|
|
return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount,
|
2015-09-15 20:52:43 +08:00
|
|
|
Clauses, AStmt, B, DSAStack->isCancelRegion());
|
2014-09-18 13:12:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
StmtResult Sema::ActOnOpenMPForSimdDirective(
|
|
|
|
ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-12-15 15:07:06 +08:00
|
|
|
OMPLoopDirective::HelperExprs B;
|
2015-07-30 19:36:16 +08:00
|
|
|
// In presence of clause 'collapse' or 'ordered' with number of loops, it will
|
|
|
|
// define the nested loops number.
|
2014-09-18 13:12:34 +08:00
|
|
|
unsigned NestedLoopCount =
|
2015-07-30 19:36:16 +08:00
|
|
|
CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses),
|
|
|
|
getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack,
|
|
|
|
VarsWithImplicitDSA, B);
|
2014-09-18 13:12:34 +08:00
|
|
|
if (NestedLoopCount == 0)
|
|
|
|
return StmtError();
|
|
|
|
|
2014-12-15 15:07:06 +08:00
|
|
|
assert((CurContext->isDependentContext() || B.builtAll()) &&
|
|
|
|
"omp for simd loop exprs were not built");
|
|
|
|
|
2015-06-18 12:45:29 +08:00
|
|
|
if (!CurContext->isDependentContext()) {
|
|
|
|
// Finalize the clauses that need pre-built expressions for CodeGen.
|
|
|
|
for (auto C : Clauses) {
|
|
|
|
if (auto LC = dyn_cast<OMPLinearClause>(C))
|
|
|
|
if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef),
|
|
|
|
B.NumIterations, *this, CurScope))
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:14:16 +08:00
|
|
|
// OpenMP 4.1 [2.8.1, simd Construct, Restrictions]
|
|
|
|
// If both simdlen and safelen clauses are specified, the value of the simdlen
|
|
|
|
// parameter must be less than or equal to the value of the safelen parameter.
|
|
|
|
OMPSafelenClause *Safelen = nullptr;
|
|
|
|
OMPSimdlenClause *Simdlen = nullptr;
|
|
|
|
for (auto *Clause : Clauses) {
|
|
|
|
if (Clause->getClauseKind() == OMPC_safelen)
|
|
|
|
Safelen = cast<OMPSafelenClause>(Clause);
|
|
|
|
else if (Clause->getClauseKind() == OMPC_simdlen)
|
|
|
|
Simdlen = cast<OMPSimdlenClause>(Clause);
|
|
|
|
if (Safelen && Simdlen)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Simdlen && Safelen &&
|
|
|
|
checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(),
|
|
|
|
Safelen->getSafelen()))
|
|
|
|
return StmtError();
|
|
|
|
|
2014-09-18 13:12:34 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
2014-12-15 15:07:06 +08:00
|
|
|
return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount,
|
|
|
|
Clauses, AStmt, B);
|
2014-06-18 12:14:57 +08:00
|
|
|
}
|
|
|
|
|
2014-06-25 19:44:49 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-06-25 19:44:49 +08:00
|
|
|
auto BaseStmt = AStmt;
|
|
|
|
while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
|
|
|
|
BaseStmt = CS->getCapturedStmt();
|
|
|
|
if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
|
|
|
|
auto S = C->children();
|
2015-07-19 01:09:36 +08:00
|
|
|
if (S.begin() == S.end())
|
2014-06-25 19:44:49 +08:00
|
|
|
return StmtError();
|
|
|
|
// All associated statements must be '#pragma omp section' except for
|
|
|
|
// the first one.
|
2015-07-19 01:09:36 +08:00
|
|
|
for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) {
|
2014-06-26 16:21:58 +08:00
|
|
|
if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
|
|
|
|
if (SectionStmt)
|
|
|
|
Diag(SectionStmt->getLocStart(),
|
|
|
|
diag::err_omp_sections_substmt_not_section);
|
|
|
|
return StmtError();
|
|
|
|
}
|
2015-09-15 20:52:43 +08:00
|
|
|
cast<OMPSectionDirective>(SectionStmt)
|
|
|
|
->setHasCancel(DSAStack->isCancelRegion());
|
2014-06-26 16:21:58 +08:00
|
|
|
}
|
2014-06-25 19:44:49 +08:00
|
|
|
} else {
|
|
|
|
Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt);
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
2015-09-15 20:52:43 +08:00
|
|
|
return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt,
|
|
|
|
DSAStack->isCancelRegion());
|
2014-06-25 19:44:49 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 16:21:58 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-06-26 16:21:58 +08:00
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
2015-09-15 20:52:43 +08:00
|
|
|
DSAStack->setParentCancelRegion(DSAStack->isCancelRegion());
|
2014-06-26 16:21:58 +08:00
|
|
|
|
2015-09-15 20:52:43 +08:00
|
|
|
return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt,
|
|
|
|
DSAStack->isCancelRegion());
|
2014-06-26 16:21:58 +08:00
|
|
|
}
|
|
|
|
|
2014-06-26 20:05:45 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-07-15 10:55:09 +08:00
|
|
|
|
2014-06-26 20:05:45 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
2014-07-15 10:55:09 +08:00
|
|
|
|
2015-01-19 13:20:46 +08:00
|
|
|
// OpenMP [2.7.3, single Construct, Restrictions]
|
|
|
|
// The copyprivate clause must not be used with the nowait clause.
|
|
|
|
OMPClause *Nowait = nullptr;
|
|
|
|
OMPClause *Copyprivate = nullptr;
|
|
|
|
for (auto *Clause : Clauses) {
|
|
|
|
if (Clause->getClauseKind() == OMPC_nowait)
|
|
|
|
Nowait = Clause;
|
|
|
|
else if (Clause->getClauseKind() == OMPC_copyprivate)
|
|
|
|
Copyprivate = Clause;
|
|
|
|
if (Copyprivate && Nowait) {
|
|
|
|
Diag(Copyprivate->getLocStart(),
|
|
|
|
diag::err_omp_single_copyprivate_with_nowait);
|
|
|
|
Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here);
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-26 20:05:45 +08:00
|
|
|
return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt);
|
|
|
|
}
|
|
|
|
|
2014-07-17 16:54:58 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-07-17 16:54:58 +08:00
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
|
|
|
return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt);
|
|
|
|
}
|
|
|
|
|
2014-07-21 17:42:05 +08:00
|
|
|
StmtResult
|
|
|
|
Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName,
|
|
|
|
Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-07-21 17:42:05 +08:00
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
|
|
|
return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc,
|
|
|
|
AStmt);
|
|
|
|
}
|
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPParallelForDirective(
|
|
|
|
ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
CapturedStmt *CS = cast<CapturedStmt>(AStmt);
|
|
|
|
// 1.2.2 OpenMP Language Terminology
|
|
|
|
// Structured block - An executable statement with a single entry at the
|
|
|
|
// top and a single exit at the bottom.
|
|
|
|
// The point of exit cannot be a branch out of the structured block.
|
|
|
|
// longjmp() and throw() must not violate the entry/exit criteria.
|
|
|
|
CS->getCapturedDecl()->setNothrow();
|
|
|
|
|
2014-12-15 15:07:06 +08:00
|
|
|
OMPLoopDirective::HelperExprs B;
|
2015-07-30 19:36:16 +08:00
|
|
|
// In presence of clause 'collapse' or 'ordered' with number of loops, it will
|
|
|
|
// define the nested loops number.
|
2014-07-07 21:01:15 +08:00
|
|
|
unsigned NestedLoopCount =
|
2015-07-30 19:36:16 +08:00
|
|
|
CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses),
|
|
|
|
getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack,
|
|
|
|
VarsWithImplicitDSA, B);
|
2014-07-07 21:01:15 +08:00
|
|
|
if (NestedLoopCount == 0)
|
|
|
|
return StmtError();
|
|
|
|
|
2014-10-01 14:03:56 +08:00
|
|
|
assert((CurContext->isDependentContext() || B.builtAll()) &&
|
|
|
|
"omp parallel for loop exprs were not built");
|
|
|
|
|
2015-08-04 19:18:19 +08:00
|
|
|
if (!CurContext->isDependentContext()) {
|
|
|
|
// Finalize the clauses that need pre-built expressions for CodeGen.
|
|
|
|
for (auto C : Clauses) {
|
|
|
|
if (auto LC = dyn_cast<OMPLinearClause>(C))
|
|
|
|
if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef),
|
|
|
|
B.NumIterations, *this, CurScope))
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-07 21:01:15 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
2014-12-15 15:07:06 +08:00
|
|
|
return OMPParallelForDirective::Create(Context, StartLoc, EndLoc,
|
2015-09-15 20:52:43 +08:00
|
|
|
NestedLoopCount, Clauses, AStmt, B,
|
|
|
|
DSAStack->isCancelRegion());
|
2014-07-07 21:01:15 +08:00
|
|
|
}
|
|
|
|
|
2014-09-23 17:33:00 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPParallelForSimdDirective(
|
|
|
|
ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
2014-09-23 17:33:00 +08:00
|
|
|
CapturedStmt *CS = cast<CapturedStmt>(AStmt);
|
|
|
|
// 1.2.2 OpenMP Language Terminology
|
|
|
|
// Structured block - An executable statement with a single entry at the
|
|
|
|
// top and a single exit at the bottom.
|
|
|
|
// The point of exit cannot be a branch out of the structured block.
|
|
|
|
// longjmp() and throw() must not violate the entry/exit criteria.
|
|
|
|
CS->getCapturedDecl()->setNothrow();
|
|
|
|
|
2014-12-15 15:07:06 +08:00
|
|
|
OMPLoopDirective::HelperExprs B;
|
2015-07-30 19:36:16 +08:00
|
|
|
// In presence of clause 'collapse' or 'ordered' with number of loops, it will
|
|
|
|
// define the nested loops number.
|
2014-09-23 17:33:00 +08:00
|
|
|
unsigned NestedLoopCount =
|
2015-07-30 19:36:16 +08:00
|
|
|
CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses),
|
|
|
|
getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack,
|
|
|
|
VarsWithImplicitDSA, B);
|
2014-09-23 17:33:00 +08:00
|
|
|
if (NestedLoopCount == 0)
|
|
|
|
return StmtError();
|
|
|
|
|
2015-06-18 18:10:12 +08:00
|
|
|
if (!CurContext->isDependentContext()) {
|
|
|
|
// Finalize the clauses that need pre-built expressions for CodeGen.
|
|
|
|
for (auto C : Clauses) {
|
|
|
|
if (auto LC = dyn_cast<OMPLinearClause>(C))
|
|
|
|
if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef),
|
|
|
|
B.NumIterations, *this, CurScope))
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-21 19:14:16 +08:00
|
|
|
// OpenMP 4.1 [2.8.1, simd Construct, Restrictions]
|
|
|
|
// If both simdlen and safelen clauses are specified, the value of the simdlen
|
|
|
|
// parameter must be less than or equal to the value of the safelen parameter.
|
|
|
|
OMPSafelenClause *Safelen = nullptr;
|
|
|
|
OMPSimdlenClause *Simdlen = nullptr;
|
|
|
|
for (auto *Clause : Clauses) {
|
|
|
|
if (Clause->getClauseKind() == OMPC_safelen)
|
|
|
|
Safelen = cast<OMPSafelenClause>(Clause);
|
|
|
|
else if (Clause->getClauseKind() == OMPC_simdlen)
|
|
|
|
Simdlen = cast<OMPSimdlenClause>(Clause);
|
|
|
|
if (Safelen && Simdlen)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Simdlen && Safelen &&
|
|
|
|
checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(),
|
|
|
|
Safelen->getSafelen()))
|
|
|
|
return StmtError();
|
|
|
|
|
2014-09-23 17:33:00 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
2014-10-01 14:03:56 +08:00
|
|
|
return OMPParallelForSimdDirective::Create(
|
2014-12-15 15:07:06 +08:00
|
|
|
Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B);
|
2014-09-23 17:33:00 +08:00
|
|
|
}
|
|
|
|
|
2014-07-08 16:12:03 +08:00
|
|
|
StmtResult
|
|
|
|
Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-07-08 16:12:03 +08:00
|
|
|
auto BaseStmt = AStmt;
|
|
|
|
while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt))
|
|
|
|
BaseStmt = CS->getCapturedStmt();
|
|
|
|
if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) {
|
|
|
|
auto S = C->children();
|
2015-07-19 01:09:36 +08:00
|
|
|
if (S.begin() == S.end())
|
2014-07-08 16:12:03 +08:00
|
|
|
return StmtError();
|
|
|
|
// All associated statements must be '#pragma omp section' except for
|
|
|
|
// the first one.
|
2015-07-19 01:09:36 +08:00
|
|
|
for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) {
|
2014-07-08 16:12:03 +08:00
|
|
|
if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) {
|
|
|
|
if (SectionStmt)
|
|
|
|
Diag(SectionStmt->getLocStart(),
|
|
|
|
diag::err_omp_parallel_sections_substmt_not_section);
|
|
|
|
return StmtError();
|
|
|
|
}
|
2015-09-15 20:52:43 +08:00
|
|
|
cast<OMPSectionDirective>(SectionStmt)
|
|
|
|
->setHasCancel(DSAStack->isCancelRegion());
|
2014-07-08 16:12:03 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Diag(AStmt->getLocStart(),
|
|
|
|
diag::err_omp_parallel_sections_not_compound_stmt);
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
2015-09-15 20:52:43 +08:00
|
|
|
return OMPParallelSectionsDirective::Create(
|
|
|
|
Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion());
|
2014-07-08 16:12:03 +08:00
|
|
|
}
|
|
|
|
|
2014-07-11 19:25:16 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
2014-07-11 19:25:16 +08:00
|
|
|
CapturedStmt *CS = cast<CapturedStmt>(AStmt);
|
|
|
|
// 1.2.2 OpenMP Language Terminology
|
|
|
|
// Structured block - An executable statement with a single entry at the
|
|
|
|
// top and a single exit at the bottom.
|
|
|
|
// The point of exit cannot be a branch out of the structured block.
|
|
|
|
// longjmp() and throw() must not violate the entry/exit criteria.
|
|
|
|
CS->getCapturedDecl()->setNothrow();
|
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
2015-09-15 20:52:43 +08:00
|
|
|
return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt,
|
|
|
|
DSAStack->isCancelRegion());
|
2014-07-11 19:25:16 +08:00
|
|
|
}
|
|
|
|
|
2014-07-18 15:47:19 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-18 17:11:51 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return OMPBarrierDirective::Create(Context, StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-18 18:17:07 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2015-06-18 20:14:09 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2015-06-18 20:14:09 +08:00
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
|
|
|
return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt);
|
|
|
|
}
|
|
|
|
|
2014-07-21 19:26:11 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
assert(Clauses.size() <= 1 && "Extra clauses in flush directive");
|
|
|
|
return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses);
|
|
|
|
}
|
|
|
|
|
2015-09-25 18:37:12 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
2014-07-22 14:45:04 +08:00
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-07-22 14:45:04 +08:00
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
2015-09-25 18:37:12 +08:00
|
|
|
OMPThreadsClause *TC = nullptr;
|
2015-09-28 14:39:35 +08:00
|
|
|
OMPSIMDClause *SC = nullptr;
|
2015-09-25 18:37:12 +08:00
|
|
|
for (auto *C: Clauses) {
|
|
|
|
if (C->getClauseKind() == OMPC_threads)
|
|
|
|
TC = cast<OMPThreadsClause>(C);
|
2015-09-28 14:39:35 +08:00
|
|
|
else if (C->getClauseKind() == OMPC_simd)
|
|
|
|
SC = cast<OMPSIMDClause>(C);
|
2015-09-25 18:37:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: this must happen only if 'threads' clause specified or if no clauses
|
|
|
|
// is specified.
|
|
|
|
if (auto *Param = DSAStack->getParentOrderedRegionParam()) {
|
|
|
|
SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc;
|
|
|
|
Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) << (TC != nullptr);
|
|
|
|
Diag(Param->getLocStart(), diag::note_omp_ordered_param);
|
|
|
|
return StmtError();
|
|
|
|
}
|
2015-09-28 14:39:35 +08:00
|
|
|
if (!SC && isOpenMPSimdDirective(DSAStack->getParentDirective())) {
|
|
|
|
// OpenMP [2.8.1,simd Construct, Restrictions]
|
|
|
|
// An ordered construct with the simd clause is the only OpenMP construct
|
|
|
|
// that can appear in the simd region.
|
|
|
|
Diag(StartLoc, diag::err_omp_prohibited_region_simd);
|
|
|
|
return StmtError();
|
|
|
|
}
|
2015-09-25 18:37:12 +08:00
|
|
|
|
|
|
|
return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt);
|
2014-07-22 14:45:04 +08:00
|
|
|
}
|
|
|
|
|
2015-03-13 20:27:31 +08:00
|
|
|
namespace {
|
|
|
|
/// \brief Helper class for checking expression in 'omp atomic [update]'
|
|
|
|
/// construct.
|
|
|
|
class OpenMPAtomicUpdateChecker {
|
|
|
|
/// \brief Error results for atomic update expressions.
|
|
|
|
enum ExprAnalysisErrorCode {
|
|
|
|
/// \brief A statement is not an expression statement.
|
|
|
|
NotAnExpression,
|
|
|
|
/// \brief Expression is not builtin binary or unary operation.
|
|
|
|
NotABinaryOrUnaryExpression,
|
|
|
|
/// \brief Unary operation is not post-/pre- increment/decrement operation.
|
|
|
|
NotAnUnaryIncDecExpression,
|
|
|
|
/// \brief An expression is not of scalar type.
|
|
|
|
NotAScalarType,
|
|
|
|
/// \brief A binary operation is not an assignment operation.
|
|
|
|
NotAnAssignmentOp,
|
|
|
|
/// \brief RHS part of the binary operation is not a binary expression.
|
|
|
|
NotABinaryExpression,
|
|
|
|
/// \brief RHS part is not additive/multiplicative/shift/biwise binary
|
|
|
|
/// expression.
|
|
|
|
NotABinaryOperator,
|
|
|
|
/// \brief RHS binary operation does not have reference to the updated LHS
|
|
|
|
/// part.
|
|
|
|
NotAnUpdateExpression,
|
|
|
|
/// \brief No errors is found.
|
|
|
|
NoError
|
|
|
|
};
|
|
|
|
/// \brief Reference to Sema.
|
|
|
|
Sema &SemaRef;
|
|
|
|
/// \brief A location for note diagnostics (when error is found).
|
|
|
|
SourceLocation NoteLoc;
|
|
|
|
/// \brief 'x' lvalue part of the source atomic expression.
|
|
|
|
Expr *X;
|
|
|
|
/// \brief 'expr' rvalue part of the source atomic expression.
|
|
|
|
Expr *E;
|
2015-03-30 13:20:59 +08:00
|
|
|
/// \brief Helper expression of the form
|
|
|
|
/// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or
|
|
|
|
/// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
|
|
|
|
Expr *UpdateExpr;
|
|
|
|
/// \brief Is 'x' a LHS in a RHS part of full update expression. It is
|
|
|
|
/// important for non-associative operations.
|
|
|
|
bool IsXLHSInRHSPart;
|
|
|
|
BinaryOperatorKind Op;
|
|
|
|
SourceLocation OpLoc;
|
2015-04-01 11:33:17 +08:00
|
|
|
/// \brief true if the source expression is a postfix unary operation, false
|
|
|
|
/// if it is a prefix unary operation.
|
|
|
|
bool IsPostfixUpdate;
|
2015-03-13 20:27:31 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
OpenMPAtomicUpdateChecker(Sema &SemaRef)
|
2015-03-30 13:20:59 +08:00
|
|
|
: SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr),
|
2015-04-01 11:33:17 +08:00
|
|
|
IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {}
|
2015-03-13 20:27:31 +08:00
|
|
|
/// \brief Check specified statement that it is suitable for 'atomic update'
|
|
|
|
/// constructs and extract 'x', 'expr' and Operation from the original
|
2015-04-01 11:33:17 +08:00
|
|
|
/// expression. If DiagId and NoteId == 0, then only check is performed
|
|
|
|
/// without error notification.
|
2015-03-13 20:27:31 +08:00
|
|
|
/// \param DiagId Diagnostic which should be emitted if error is found.
|
|
|
|
/// \param NoteId Diagnostic note for the main error message.
|
|
|
|
/// \return true if statement is not an update expression, false otherwise.
|
2015-04-01 11:33:17 +08:00
|
|
|
bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0);
|
2015-03-13 20:27:31 +08:00
|
|
|
/// \brief Return the 'x' lvalue part of the source atomic expression.
|
|
|
|
Expr *getX() const { return X; }
|
|
|
|
/// \brief Return the 'expr' rvalue part of the source atomic expression.
|
|
|
|
Expr *getExpr() const { return E; }
|
2015-03-30 13:20:59 +08:00
|
|
|
/// \brief Return the update expression used in calculation of the updated
|
|
|
|
/// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or
|
|
|
|
/// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
|
|
|
|
Expr *getUpdateExpr() const { return UpdateExpr; }
|
|
|
|
/// \brief Return true if 'x' is LHS in RHS part of full update expression,
|
|
|
|
/// false otherwise.
|
|
|
|
bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; }
|
|
|
|
|
2015-04-01 11:33:17 +08:00
|
|
|
/// \brief true if the source expression is a postfix unary operation, false
|
|
|
|
/// if it is a prefix unary operation.
|
|
|
|
bool isPostfixUpdate() const { return IsPostfixUpdate; }
|
|
|
|
|
2015-03-13 20:27:31 +08:00
|
|
|
private:
|
2015-04-01 11:33:17 +08:00
|
|
|
bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0,
|
|
|
|
unsigned NoteId = 0);
|
2015-03-13 20:27:31 +08:00
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
bool OpenMPAtomicUpdateChecker::checkBinaryOperation(
|
|
|
|
BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) {
|
|
|
|
ExprAnalysisErrorCode ErrorFound = NoError;
|
|
|
|
SourceLocation ErrorLoc, NoteLoc;
|
|
|
|
SourceRange ErrorRange, NoteRange;
|
|
|
|
// Allowed constructs are:
|
|
|
|
// x = x binop expr;
|
|
|
|
// x = expr binop x;
|
|
|
|
if (AtomicBinOp->getOpcode() == BO_Assign) {
|
|
|
|
X = AtomicBinOp->getLHS();
|
|
|
|
if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>(
|
|
|
|
AtomicBinOp->getRHS()->IgnoreParenImpCasts())) {
|
|
|
|
if (AtomicInnerBinOp->isMultiplicativeOp() ||
|
|
|
|
AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() ||
|
|
|
|
AtomicInnerBinOp->isBitwiseOp()) {
|
2015-03-30 13:20:59 +08:00
|
|
|
Op = AtomicInnerBinOp->getOpcode();
|
|
|
|
OpLoc = AtomicInnerBinOp->getOperatorLoc();
|
2015-03-13 20:27:31 +08:00
|
|
|
auto *LHS = AtomicInnerBinOp->getLHS();
|
|
|
|
auto *RHS = AtomicInnerBinOp->getRHS();
|
|
|
|
llvm::FoldingSetNodeID XId, LHSId, RHSId;
|
|
|
|
X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(),
|
|
|
|
/*Canonical=*/true);
|
|
|
|
LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(),
|
|
|
|
/*Canonical=*/true);
|
|
|
|
RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(),
|
|
|
|
/*Canonical=*/true);
|
|
|
|
if (XId == LHSId) {
|
|
|
|
E = RHS;
|
2015-03-30 13:20:59 +08:00
|
|
|
IsXLHSInRHSPart = true;
|
2015-03-13 20:27:31 +08:00
|
|
|
} else if (XId == RHSId) {
|
|
|
|
E = LHS;
|
2015-03-30 13:20:59 +08:00
|
|
|
IsXLHSInRHSPart = false;
|
2015-03-13 20:27:31 +08:00
|
|
|
} else {
|
|
|
|
ErrorLoc = AtomicInnerBinOp->getExprLoc();
|
|
|
|
ErrorRange = AtomicInnerBinOp->getSourceRange();
|
|
|
|
NoteLoc = X->getExprLoc();
|
|
|
|
NoteRange = X->getSourceRange();
|
|
|
|
ErrorFound = NotAnUpdateExpression;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ErrorLoc = AtomicInnerBinOp->getExprLoc();
|
|
|
|
ErrorRange = AtomicInnerBinOp->getSourceRange();
|
|
|
|
NoteLoc = AtomicInnerBinOp->getOperatorLoc();
|
|
|
|
NoteRange = SourceRange(NoteLoc, NoteLoc);
|
|
|
|
ErrorFound = NotABinaryOperator;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc();
|
|
|
|
NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange();
|
|
|
|
ErrorFound = NotABinaryExpression;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ErrorLoc = AtomicBinOp->getExprLoc();
|
|
|
|
ErrorRange = AtomicBinOp->getSourceRange();
|
|
|
|
NoteLoc = AtomicBinOp->getOperatorLoc();
|
|
|
|
NoteRange = SourceRange(NoteLoc, NoteLoc);
|
|
|
|
ErrorFound = NotAnAssignmentOp;
|
|
|
|
}
|
2015-04-01 11:33:17 +08:00
|
|
|
if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) {
|
2015-03-13 20:27:31 +08:00
|
|
|
SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange;
|
|
|
|
SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange;
|
|
|
|
return true;
|
|
|
|
} else if (SemaRef.CurContext->isDependentContext())
|
2015-03-30 13:20:59 +08:00
|
|
|
E = X = UpdateExpr = nullptr;
|
2015-04-23 14:35:10 +08:00
|
|
|
return ErrorFound != NoError;
|
2015-03-13 20:27:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId,
|
|
|
|
unsigned NoteId) {
|
|
|
|
ExprAnalysisErrorCode ErrorFound = NoError;
|
|
|
|
SourceLocation ErrorLoc, NoteLoc;
|
|
|
|
SourceRange ErrorRange, NoteRange;
|
|
|
|
// Allowed constructs are:
|
|
|
|
// x++;
|
|
|
|
// x--;
|
|
|
|
// ++x;
|
|
|
|
// --x;
|
|
|
|
// x binop= expr;
|
|
|
|
// x = x binop expr;
|
|
|
|
// x = expr binop x;
|
|
|
|
if (auto *AtomicBody = dyn_cast<Expr>(S)) {
|
|
|
|
AtomicBody = AtomicBody->IgnoreParenImpCasts();
|
|
|
|
if (AtomicBody->getType()->isScalarType() ||
|
|
|
|
AtomicBody->isInstantiationDependent()) {
|
|
|
|
if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>(
|
|
|
|
AtomicBody->IgnoreParenImpCasts())) {
|
|
|
|
// Check for Compound Assignment Operation
|
2015-03-30 13:20:59 +08:00
|
|
|
Op = BinaryOperator::getOpForCompoundAssignment(
|
2015-03-13 20:27:31 +08:00
|
|
|
AtomicCompAssignOp->getOpcode());
|
2015-03-30 13:20:59 +08:00
|
|
|
OpLoc = AtomicCompAssignOp->getOperatorLoc();
|
2015-03-13 20:27:31 +08:00
|
|
|
E = AtomicCompAssignOp->getRHS();
|
2015-03-30 13:20:59 +08:00
|
|
|
X = AtomicCompAssignOp->getLHS();
|
|
|
|
IsXLHSInRHSPart = true;
|
2015-03-13 20:27:31 +08:00
|
|
|
} else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>(
|
|
|
|
AtomicBody->IgnoreParenImpCasts())) {
|
|
|
|
// Check for Binary Operation
|
2015-03-30 13:20:59 +08:00
|
|
|
if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId))
|
|
|
|
return true;
|
2015-03-13 20:27:31 +08:00
|
|
|
} else if (auto *AtomicUnaryOp =
|
|
|
|
dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) {
|
|
|
|
// Check for Unary Operation
|
|
|
|
if (AtomicUnaryOp->isIncrementDecrementOp()) {
|
2015-04-01 11:33:17 +08:00
|
|
|
IsPostfixUpdate = AtomicUnaryOp->isPostfix();
|
2015-03-30 13:20:59 +08:00
|
|
|
Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub;
|
|
|
|
OpLoc = AtomicUnaryOp->getOperatorLoc();
|
|
|
|
X = AtomicUnaryOp->getSubExpr();
|
|
|
|
E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get();
|
|
|
|
IsXLHSInRHSPart = true;
|
2015-03-13 20:27:31 +08:00
|
|
|
} else {
|
|
|
|
ErrorFound = NotAnUnaryIncDecExpression;
|
|
|
|
ErrorLoc = AtomicUnaryOp->getExprLoc();
|
|
|
|
ErrorRange = AtomicUnaryOp->getSourceRange();
|
|
|
|
NoteLoc = AtomicUnaryOp->getOperatorLoc();
|
|
|
|
NoteRange = SourceRange(NoteLoc, NoteLoc);
|
|
|
|
}
|
2015-09-04 20:55:50 +08:00
|
|
|
} else if (!AtomicBody->isInstantiationDependent()) {
|
2015-03-13 20:27:31 +08:00
|
|
|
ErrorFound = NotABinaryOrUnaryExpression;
|
|
|
|
NoteLoc = ErrorLoc = AtomicBody->getExprLoc();
|
|
|
|
NoteRange = ErrorRange = AtomicBody->getSourceRange();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ErrorFound = NotAScalarType;
|
|
|
|
NoteLoc = ErrorLoc = AtomicBody->getLocStart();
|
|
|
|
NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ErrorFound = NotAnExpression;
|
|
|
|
NoteLoc = ErrorLoc = S->getLocStart();
|
|
|
|
NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc);
|
|
|
|
}
|
2015-04-01 11:33:17 +08:00
|
|
|
if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) {
|
2015-03-13 20:27:31 +08:00
|
|
|
SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange;
|
|
|
|
SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange;
|
|
|
|
return true;
|
|
|
|
} else if (SemaRef.CurContext->isDependentContext())
|
2015-03-30 13:20:59 +08:00
|
|
|
E = X = UpdateExpr = nullptr;
|
2015-04-23 14:35:10 +08:00
|
|
|
if (ErrorFound == NoError && E && X) {
|
2015-03-30 13:20:59 +08:00
|
|
|
// Build an update expression of form 'OpaqueValueExpr(x) binop
|
|
|
|
// OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop
|
|
|
|
// OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression.
|
|
|
|
auto *OVEX = new (SemaRef.getASTContext())
|
|
|
|
OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue);
|
|
|
|
auto *OVEExpr = new (SemaRef.getASTContext())
|
|
|
|
OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue);
|
|
|
|
auto Update =
|
|
|
|
SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr,
|
|
|
|
IsXLHSInRHSPart ? OVEExpr : OVEX);
|
|
|
|
if (Update.isInvalid())
|
|
|
|
return true;
|
|
|
|
Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(),
|
|
|
|
Sema::AA_Casting);
|
|
|
|
if (Update.isInvalid())
|
|
|
|
return true;
|
|
|
|
UpdateExpr = Update.get();
|
|
|
|
}
|
2015-04-23 14:35:10 +08:00
|
|
|
return ErrorFound != NoError;
|
2015-03-13 20:27:31 +08:00
|
|
|
}
|
|
|
|
|
2014-07-22 18:10:35 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
2014-07-23 10:27:21 +08:00
|
|
|
auto CS = cast<CapturedStmt>(AStmt);
|
2014-07-22 18:10:35 +08:00
|
|
|
// 1.2.2 OpenMP Language Terminology
|
|
|
|
// Structured block - An executable statement with a single entry at the
|
|
|
|
// top and a single exit at the bottom.
|
|
|
|
// The point of exit cannot be a branch out of the structured block.
|
|
|
|
// longjmp() and throw() must not violate the entry/exit criteria.
|
2014-07-23 15:46:59 +08:00
|
|
|
OpenMPClauseKind AtomicKind = OMPC_unknown;
|
|
|
|
SourceLocation AtomicKindLoc;
|
2014-07-23 10:27:21 +08:00
|
|
|
for (auto *C : Clauses) {
|
2014-07-23 18:25:33 +08:00
|
|
|
if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write ||
|
2014-07-24 14:46:57 +08:00
|
|
|
C->getClauseKind() == OMPC_update ||
|
|
|
|
C->getClauseKind() == OMPC_capture) {
|
2014-07-23 15:46:59 +08:00
|
|
|
if (AtomicKind != OMPC_unknown) {
|
|
|
|
Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses)
|
|
|
|
<< SourceRange(C->getLocStart(), C->getLocEnd());
|
|
|
|
Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause)
|
|
|
|
<< getOpenMPClauseName(AtomicKind);
|
|
|
|
} else {
|
|
|
|
AtomicKind = C->getClauseKind();
|
|
|
|
AtomicKindLoc = C->getLocStart();
|
2014-07-23 10:27:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-18 18:14:22 +08:00
|
|
|
|
2014-07-24 14:46:57 +08:00
|
|
|
auto Body = CS->getCapturedStmt();
|
2015-03-11 12:48:56 +08:00
|
|
|
if (auto *EWC = dyn_cast<ExprWithCleanups>(Body))
|
|
|
|
Body = EWC->getSubExpr();
|
|
|
|
|
2014-11-18 18:14:22 +08:00
|
|
|
Expr *X = nullptr;
|
|
|
|
Expr *V = nullptr;
|
|
|
|
Expr *E = nullptr;
|
2015-03-30 13:20:59 +08:00
|
|
|
Expr *UE = nullptr;
|
|
|
|
bool IsXLHSInRHSPart = false;
|
2015-04-01 11:33:17 +08:00
|
|
|
bool IsPostfixUpdate = false;
|
2014-11-18 18:14:22 +08:00
|
|
|
// OpenMP [2.12.6, atomic Construct]
|
|
|
|
// In the next expressions:
|
|
|
|
// * x and v (as applicable) are both l-value expressions with scalar type.
|
|
|
|
// * During the execution of an atomic region, multiple syntactic
|
|
|
|
// occurrences of x must designate the same storage location.
|
|
|
|
// * Neither of v and expr (as applicable) may access the storage location
|
|
|
|
// designated by x.
|
|
|
|
// * Neither of x and expr (as applicable) may access the storage location
|
|
|
|
// designated by v.
|
|
|
|
// * expr is an expression with scalar type.
|
|
|
|
// * binop is one of +, *, -, /, &, ^, |, <<, or >>.
|
|
|
|
// * binop, binop=, ++, and -- are not overloaded operators.
|
|
|
|
// * The expression x binop expr must be numerically equivalent to x binop
|
|
|
|
// (expr). This requirement is satisfied if the operators in expr have
|
|
|
|
// precedence greater than binop, or by using parentheses around expr or
|
|
|
|
// subexpressions of expr.
|
|
|
|
// * The expression expr binop x must be numerically equivalent to (expr)
|
|
|
|
// binop x. This requirement is satisfied if the operators in expr have
|
|
|
|
// precedence equal to or greater than binop, or by using parentheses around
|
|
|
|
// expr or subexpressions of expr.
|
|
|
|
// * For forms that allow multiple occurrences of x, the number of times
|
|
|
|
// that x is evaluated is unspecified.
|
2014-07-23 15:46:59 +08:00
|
|
|
if (AtomicKind == OMPC_read) {
|
2015-04-01 11:33:17 +08:00
|
|
|
enum {
|
|
|
|
NotAnExpression,
|
|
|
|
NotAnAssignmentOp,
|
|
|
|
NotAScalarType,
|
|
|
|
NotAnLValue,
|
|
|
|
NoError
|
|
|
|
} ErrorFound = NoError;
|
2014-11-18 18:14:22 +08:00
|
|
|
SourceLocation ErrorLoc, NoteLoc;
|
|
|
|
SourceRange ErrorRange, NoteRange;
|
|
|
|
// If clause is read:
|
|
|
|
// v = x;
|
|
|
|
if (auto AtomicBody = dyn_cast<Expr>(Body)) {
|
|
|
|
auto AtomicBinOp =
|
|
|
|
dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts());
|
|
|
|
if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) {
|
|
|
|
X = AtomicBinOp->getRHS()->IgnoreParenImpCasts();
|
|
|
|
V = AtomicBinOp->getLHS()->IgnoreParenImpCasts();
|
|
|
|
if ((X->isInstantiationDependent() || X->getType()->isScalarType()) &&
|
|
|
|
(V->isInstantiationDependent() || V->getType()->isScalarType())) {
|
|
|
|
if (!X->isLValue() || !V->isLValue()) {
|
|
|
|
auto NotLValueExpr = X->isLValue() ? V : X;
|
|
|
|
ErrorFound = NotAnLValue;
|
|
|
|
ErrorLoc = AtomicBinOp->getExprLoc();
|
|
|
|
ErrorRange = AtomicBinOp->getSourceRange();
|
|
|
|
NoteLoc = NotLValueExpr->getExprLoc();
|
|
|
|
NoteRange = NotLValueExpr->getSourceRange();
|
|
|
|
}
|
|
|
|
} else if (!X->isInstantiationDependent() ||
|
|
|
|
!V->isInstantiationDependent()) {
|
|
|
|
auto NotScalarExpr =
|
|
|
|
(X->isInstantiationDependent() || X->getType()->isScalarType())
|
|
|
|
? V
|
|
|
|
: X;
|
|
|
|
ErrorFound = NotAScalarType;
|
|
|
|
ErrorLoc = AtomicBinOp->getExprLoc();
|
|
|
|
ErrorRange = AtomicBinOp->getSourceRange();
|
|
|
|
NoteLoc = NotScalarExpr->getExprLoc();
|
|
|
|
NoteRange = NotScalarExpr->getSourceRange();
|
|
|
|
}
|
2015-09-04 20:55:50 +08:00
|
|
|
} else if (!AtomicBody->isInstantiationDependent()) {
|
2014-11-18 18:14:22 +08:00
|
|
|
ErrorFound = NotAnAssignmentOp;
|
|
|
|
ErrorLoc = AtomicBody->getExprLoc();
|
|
|
|
ErrorRange = AtomicBody->getSourceRange();
|
|
|
|
NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc()
|
|
|
|
: AtomicBody->getExprLoc();
|
|
|
|
NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange()
|
|
|
|
: AtomicBody->getSourceRange();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ErrorFound = NotAnExpression;
|
|
|
|
NoteLoc = ErrorLoc = Body->getLocStart();
|
|
|
|
NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc);
|
2014-07-23 15:46:59 +08:00
|
|
|
}
|
2014-11-18 18:14:22 +08:00
|
|
|
if (ErrorFound != NoError) {
|
|
|
|
Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement)
|
|
|
|
<< ErrorRange;
|
2014-11-28 15:21:40 +08:00
|
|
|
Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound
|
|
|
|
<< NoteRange;
|
2014-11-18 18:14:22 +08:00
|
|
|
return StmtError();
|
|
|
|
} else if (CurContext->isDependentContext())
|
|
|
|
V = X = nullptr;
|
2014-07-23 15:46:59 +08:00
|
|
|
} else if (AtomicKind == OMPC_write) {
|
2015-04-01 11:33:17 +08:00
|
|
|
enum {
|
|
|
|
NotAnExpression,
|
|
|
|
NotAnAssignmentOp,
|
|
|
|
NotAScalarType,
|
|
|
|
NotAnLValue,
|
|
|
|
NoError
|
|
|
|
} ErrorFound = NoError;
|
2014-11-28 15:21:40 +08:00
|
|
|
SourceLocation ErrorLoc, NoteLoc;
|
|
|
|
SourceRange ErrorRange, NoteRange;
|
|
|
|
// If clause is write:
|
|
|
|
// x = expr;
|
|
|
|
if (auto AtomicBody = dyn_cast<Expr>(Body)) {
|
|
|
|
auto AtomicBinOp =
|
|
|
|
dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts());
|
|
|
|
if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) {
|
2015-02-27 14:33:30 +08:00
|
|
|
X = AtomicBinOp->getLHS();
|
|
|
|
E = AtomicBinOp->getRHS();
|
2014-11-28 15:21:40 +08:00
|
|
|
if ((X->isInstantiationDependent() || X->getType()->isScalarType()) &&
|
|
|
|
(E->isInstantiationDependent() || E->getType()->isScalarType())) {
|
|
|
|
if (!X->isLValue()) {
|
|
|
|
ErrorFound = NotAnLValue;
|
|
|
|
ErrorLoc = AtomicBinOp->getExprLoc();
|
|
|
|
ErrorRange = AtomicBinOp->getSourceRange();
|
|
|
|
NoteLoc = X->getExprLoc();
|
|
|
|
NoteRange = X->getSourceRange();
|
|
|
|
}
|
|
|
|
} else if (!X->isInstantiationDependent() ||
|
|
|
|
!E->isInstantiationDependent()) {
|
|
|
|
auto NotScalarExpr =
|
|
|
|
(X->isInstantiationDependent() || X->getType()->isScalarType())
|
|
|
|
? E
|
|
|
|
: X;
|
|
|
|
ErrorFound = NotAScalarType;
|
|
|
|
ErrorLoc = AtomicBinOp->getExprLoc();
|
|
|
|
ErrorRange = AtomicBinOp->getSourceRange();
|
|
|
|
NoteLoc = NotScalarExpr->getExprLoc();
|
|
|
|
NoteRange = NotScalarExpr->getSourceRange();
|
|
|
|
}
|
2015-09-04 20:55:50 +08:00
|
|
|
} else if (!AtomicBody->isInstantiationDependent()) {
|
2014-11-28 15:21:40 +08:00
|
|
|
ErrorFound = NotAnAssignmentOp;
|
|
|
|
ErrorLoc = AtomicBody->getExprLoc();
|
|
|
|
ErrorRange = AtomicBody->getSourceRange();
|
|
|
|
NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc()
|
|
|
|
: AtomicBody->getExprLoc();
|
|
|
|
NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange()
|
|
|
|
: AtomicBody->getSourceRange();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ErrorFound = NotAnExpression;
|
|
|
|
NoteLoc = ErrorLoc = Body->getLocStart();
|
|
|
|
NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc);
|
2014-07-23 15:46:59 +08:00
|
|
|
}
|
2014-11-28 15:21:40 +08:00
|
|
|
if (ErrorFound != NoError) {
|
|
|
|
Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement)
|
|
|
|
<< ErrorRange;
|
|
|
|
Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound
|
|
|
|
<< NoteRange;
|
|
|
|
return StmtError();
|
|
|
|
} else if (CurContext->isDependentContext())
|
|
|
|
E = X = nullptr;
|
2014-07-23 18:25:33 +08:00
|
|
|
} else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) {
|
2015-03-13 20:27:31 +08:00
|
|
|
// If clause is update:
|
|
|
|
// x++;
|
|
|
|
// x--;
|
|
|
|
// ++x;
|
|
|
|
// --x;
|
|
|
|
// x binop= expr;
|
|
|
|
// x = x binop expr;
|
|
|
|
// x = expr binop x;
|
|
|
|
OpenMPAtomicUpdateChecker Checker(*this);
|
|
|
|
if (Checker.checkStatement(
|
|
|
|
Body, (AtomicKind == OMPC_update)
|
|
|
|
? diag::err_omp_atomic_update_not_expression_statement
|
|
|
|
: diag::err_omp_atomic_not_expression_statement,
|
|
|
|
diag::note_omp_atomic_update))
|
2014-07-23 18:25:33 +08:00
|
|
|
return StmtError();
|
2015-03-13 20:27:31 +08:00
|
|
|
if (!CurContext->isDependentContext()) {
|
|
|
|
E = Checker.getExpr();
|
|
|
|
X = Checker.getX();
|
2015-03-30 13:20:59 +08:00
|
|
|
UE = Checker.getUpdateExpr();
|
|
|
|
IsXLHSInRHSPart = Checker.isXLHSInRHSPart();
|
2014-07-23 18:25:33 +08:00
|
|
|
}
|
2014-07-24 14:46:57 +08:00
|
|
|
} else if (AtomicKind == OMPC_capture) {
|
2015-04-01 11:33:17 +08:00
|
|
|
enum {
|
|
|
|
NotAnAssignmentOp,
|
|
|
|
NotACompoundStatement,
|
|
|
|
NotTwoSubstatements,
|
|
|
|
NotASpecificExpression,
|
|
|
|
NoError
|
|
|
|
} ErrorFound = NoError;
|
|
|
|
SourceLocation ErrorLoc, NoteLoc;
|
|
|
|
SourceRange ErrorRange, NoteRange;
|
|
|
|
if (auto *AtomicBody = dyn_cast<Expr>(Body)) {
|
|
|
|
// If clause is a capture:
|
|
|
|
// v = x++;
|
|
|
|
// v = x--;
|
|
|
|
// v = ++x;
|
|
|
|
// v = --x;
|
|
|
|
// v = x binop= expr;
|
|
|
|
// v = x = x binop expr;
|
|
|
|
// v = x = expr binop x;
|
|
|
|
auto *AtomicBinOp =
|
|
|
|
dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts());
|
|
|
|
if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) {
|
|
|
|
V = AtomicBinOp->getLHS();
|
|
|
|
Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts();
|
|
|
|
OpenMPAtomicUpdateChecker Checker(*this);
|
|
|
|
if (Checker.checkStatement(
|
|
|
|
Body, diag::err_omp_atomic_capture_not_expression_statement,
|
|
|
|
diag::note_omp_atomic_update))
|
|
|
|
return StmtError();
|
|
|
|
E = Checker.getExpr();
|
|
|
|
X = Checker.getX();
|
|
|
|
UE = Checker.getUpdateExpr();
|
|
|
|
IsXLHSInRHSPart = Checker.isXLHSInRHSPart();
|
|
|
|
IsPostfixUpdate = Checker.isPostfixUpdate();
|
2015-09-04 20:55:50 +08:00
|
|
|
} else if (!AtomicBody->isInstantiationDependent()) {
|
2015-04-01 11:33:17 +08:00
|
|
|
ErrorLoc = AtomicBody->getExprLoc();
|
|
|
|
ErrorRange = AtomicBody->getSourceRange();
|
|
|
|
NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc()
|
|
|
|
: AtomicBody->getExprLoc();
|
|
|
|
NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange()
|
|
|
|
: AtomicBody->getSourceRange();
|
|
|
|
ErrorFound = NotAnAssignmentOp;
|
|
|
|
}
|
|
|
|
if (ErrorFound != NoError) {
|
|
|
|
Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement)
|
|
|
|
<< ErrorRange;
|
|
|
|
Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange;
|
|
|
|
return StmtError();
|
|
|
|
} else if (CurContext->isDependentContext()) {
|
|
|
|
UE = V = E = X = nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If clause is a capture:
|
|
|
|
// { v = x; x = expr; }
|
|
|
|
// { v = x; x++; }
|
|
|
|
// { v = x; x--; }
|
|
|
|
// { v = x; ++x; }
|
|
|
|
// { v = x; --x; }
|
|
|
|
// { v = x; x binop= expr; }
|
|
|
|
// { v = x; x = x binop expr; }
|
|
|
|
// { v = x; x = expr binop x; }
|
|
|
|
// { x++; v = x; }
|
|
|
|
// { x--; v = x; }
|
|
|
|
// { ++x; v = x; }
|
|
|
|
// { --x; v = x; }
|
|
|
|
// { x binop= expr; v = x; }
|
|
|
|
// { x = x binop expr; v = x; }
|
|
|
|
// { x = expr binop x; v = x; }
|
|
|
|
if (auto *CS = dyn_cast<CompoundStmt>(Body)) {
|
|
|
|
// Check that this is { expr1; expr2; }
|
|
|
|
if (CS->size() == 2) {
|
|
|
|
auto *First = CS->body_front();
|
|
|
|
auto *Second = CS->body_back();
|
|
|
|
if (auto *EWC = dyn_cast<ExprWithCleanups>(First))
|
|
|
|
First = EWC->getSubExpr()->IgnoreParenImpCasts();
|
|
|
|
if (auto *EWC = dyn_cast<ExprWithCleanups>(Second))
|
|
|
|
Second = EWC->getSubExpr()->IgnoreParenImpCasts();
|
|
|
|
// Need to find what subexpression is 'v' and what is 'x'.
|
|
|
|
OpenMPAtomicUpdateChecker Checker(*this);
|
|
|
|
bool IsUpdateExprFound = !Checker.checkStatement(Second);
|
|
|
|
BinaryOperator *BinOp = nullptr;
|
|
|
|
if (IsUpdateExprFound) {
|
|
|
|
BinOp = dyn_cast<BinaryOperator>(First);
|
|
|
|
IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign;
|
|
|
|
}
|
|
|
|
if (IsUpdateExprFound && !CurContext->isDependentContext()) {
|
|
|
|
// { v = x; x++; }
|
|
|
|
// { v = x; x--; }
|
|
|
|
// { v = x; ++x; }
|
|
|
|
// { v = x; --x; }
|
|
|
|
// { v = x; x binop= expr; }
|
|
|
|
// { v = x; x = x binop expr; }
|
|
|
|
// { v = x; x = expr binop x; }
|
|
|
|
// Check that the first expression has form v = x.
|
|
|
|
auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts();
|
|
|
|
llvm::FoldingSetNodeID XId, PossibleXId;
|
|
|
|
Checker.getX()->Profile(XId, Context, /*Canonical=*/true);
|
|
|
|
PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true);
|
|
|
|
IsUpdateExprFound = XId == PossibleXId;
|
|
|
|
if (IsUpdateExprFound) {
|
|
|
|
V = BinOp->getLHS();
|
|
|
|
X = Checker.getX();
|
|
|
|
E = Checker.getExpr();
|
|
|
|
UE = Checker.getUpdateExpr();
|
|
|
|
IsXLHSInRHSPart = Checker.isXLHSInRHSPart();
|
2015-04-23 14:35:10 +08:00
|
|
|
IsPostfixUpdate = true;
|
2015-04-01 11:33:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!IsUpdateExprFound) {
|
|
|
|
IsUpdateExprFound = !Checker.checkStatement(First);
|
|
|
|
BinOp = nullptr;
|
|
|
|
if (IsUpdateExprFound) {
|
|
|
|
BinOp = dyn_cast<BinaryOperator>(Second);
|
|
|
|
IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign;
|
|
|
|
}
|
|
|
|
if (IsUpdateExprFound && !CurContext->isDependentContext()) {
|
|
|
|
// { x++; v = x; }
|
|
|
|
// { x--; v = x; }
|
|
|
|
// { ++x; v = x; }
|
|
|
|
// { --x; v = x; }
|
|
|
|
// { x binop= expr; v = x; }
|
|
|
|
// { x = x binop expr; v = x; }
|
|
|
|
// { x = expr binop x; v = x; }
|
|
|
|
// Check that the second expression has form v = x.
|
|
|
|
auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts();
|
|
|
|
llvm::FoldingSetNodeID XId, PossibleXId;
|
|
|
|
Checker.getX()->Profile(XId, Context, /*Canonical=*/true);
|
|
|
|
PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true);
|
|
|
|
IsUpdateExprFound = XId == PossibleXId;
|
|
|
|
if (IsUpdateExprFound) {
|
|
|
|
V = BinOp->getLHS();
|
|
|
|
X = Checker.getX();
|
|
|
|
E = Checker.getExpr();
|
|
|
|
UE = Checker.getUpdateExpr();
|
|
|
|
IsXLHSInRHSPart = Checker.isXLHSInRHSPart();
|
2015-04-23 14:35:10 +08:00
|
|
|
IsPostfixUpdate = false;
|
2015-04-01 11:33:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!IsUpdateExprFound) {
|
|
|
|
// { v = x; x = expr; }
|
2015-09-04 20:55:50 +08:00
|
|
|
auto *FirstExpr = dyn_cast<Expr>(First);
|
|
|
|
auto *SecondExpr = dyn_cast<Expr>(Second);
|
|
|
|
if (!FirstExpr || !SecondExpr ||
|
|
|
|
!(FirstExpr->isInstantiationDependent() ||
|
|
|
|
SecondExpr->isInstantiationDependent())) {
|
|
|
|
auto *FirstBinOp = dyn_cast<BinaryOperator>(First);
|
|
|
|
if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) {
|
2015-04-01 11:33:17 +08:00
|
|
|
ErrorFound = NotAnAssignmentOp;
|
2015-09-04 20:55:50 +08:00
|
|
|
NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc()
|
|
|
|
: First->getLocStart();
|
|
|
|
NoteRange = ErrorRange = FirstBinOp
|
|
|
|
? FirstBinOp->getSourceRange()
|
2015-04-01 11:33:17 +08:00
|
|
|
: SourceRange(ErrorLoc, ErrorLoc);
|
|
|
|
} else {
|
2015-09-04 20:55:50 +08:00
|
|
|
auto *SecondBinOp = dyn_cast<BinaryOperator>(Second);
|
|
|
|
if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) {
|
|
|
|
ErrorFound = NotAnAssignmentOp;
|
|
|
|
NoteLoc = ErrorLoc = SecondBinOp
|
|
|
|
? SecondBinOp->getOperatorLoc()
|
|
|
|
: Second->getLocStart();
|
|
|
|
NoteRange = ErrorRange =
|
|
|
|
SecondBinOp ? SecondBinOp->getSourceRange()
|
|
|
|
: SourceRange(ErrorLoc, ErrorLoc);
|
2015-04-01 11:33:17 +08:00
|
|
|
} else {
|
2015-09-04 20:55:50 +08:00
|
|
|
auto *PossibleXRHSInFirst =
|
|
|
|
FirstBinOp->getRHS()->IgnoreParenImpCasts();
|
|
|
|
auto *PossibleXLHSInSecond =
|
|
|
|
SecondBinOp->getLHS()->IgnoreParenImpCasts();
|
|
|
|
llvm::FoldingSetNodeID X1Id, X2Id;
|
|
|
|
PossibleXRHSInFirst->Profile(X1Id, Context,
|
|
|
|
/*Canonical=*/true);
|
|
|
|
PossibleXLHSInSecond->Profile(X2Id, Context,
|
|
|
|
/*Canonical=*/true);
|
|
|
|
IsUpdateExprFound = X1Id == X2Id;
|
|
|
|
if (IsUpdateExprFound) {
|
|
|
|
V = FirstBinOp->getLHS();
|
|
|
|
X = SecondBinOp->getLHS();
|
|
|
|
E = SecondBinOp->getRHS();
|
|
|
|
UE = nullptr;
|
|
|
|
IsXLHSInRHSPart = false;
|
|
|
|
IsPostfixUpdate = true;
|
|
|
|
} else {
|
|
|
|
ErrorFound = NotASpecificExpression;
|
|
|
|
ErrorLoc = FirstBinOp->getExprLoc();
|
|
|
|
ErrorRange = FirstBinOp->getSourceRange();
|
|
|
|
NoteLoc = SecondBinOp->getLHS()->getExprLoc();
|
|
|
|
NoteRange = SecondBinOp->getRHS()->getSourceRange();
|
|
|
|
}
|
2015-04-01 11:33:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NoteLoc = ErrorLoc = Body->getLocStart();
|
|
|
|
NoteRange = ErrorRange =
|
|
|
|
SourceRange(Body->getLocStart(), Body->getLocStart());
|
|
|
|
ErrorFound = NotTwoSubstatements;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NoteLoc = ErrorLoc = Body->getLocStart();
|
|
|
|
NoteRange = ErrorRange =
|
|
|
|
SourceRange(Body->getLocStart(), Body->getLocStart());
|
|
|
|
ErrorFound = NotACompoundStatement;
|
|
|
|
}
|
|
|
|
if (ErrorFound != NoError) {
|
|
|
|
Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement)
|
|
|
|
<< ErrorRange;
|
|
|
|
Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange;
|
|
|
|
return StmtError();
|
|
|
|
} else if (CurContext->isDependentContext()) {
|
|
|
|
UE = V = E = X = nullptr;
|
|
|
|
}
|
2014-07-24 14:46:57 +08:00
|
|
|
}
|
2014-07-23 15:46:59 +08:00
|
|
|
}
|
2014-07-22 18:10:35 +08:00
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
2014-11-18 18:14:22 +08:00
|
|
|
return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt,
|
2015-04-01 11:33:17 +08:00
|
|
|
X, V, E, UE, IsXLHSInRHSPart,
|
|
|
|
IsPostfixUpdate);
|
2014-07-22 18:10:35 +08:00
|
|
|
}
|
|
|
|
|
2014-09-19 16:19:49 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
2014-09-19 16:19:49 +08:00
|
|
|
|
2014-10-09 12:18:56 +08:00
|
|
|
// OpenMP [2.16, Nesting of Regions]
|
|
|
|
// If specified, a teams construct must be contained within a target
|
|
|
|
// construct. That target construct must contain no statements or directives
|
|
|
|
// outside of the teams construct.
|
|
|
|
if (DSAStack->hasInnerTeamsRegion()) {
|
|
|
|
auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true);
|
|
|
|
bool OMPTeamsFound = true;
|
|
|
|
if (auto *CS = dyn_cast<CompoundStmt>(S)) {
|
|
|
|
auto I = CS->body_begin();
|
|
|
|
while (I != CS->body_end()) {
|
|
|
|
auto OED = dyn_cast<OMPExecutableDirective>(*I);
|
|
|
|
if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) {
|
|
|
|
OMPTeamsFound = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++I;
|
|
|
|
}
|
|
|
|
assert(I != CS->body_end() && "Not found statement");
|
|
|
|
S = *I;
|
|
|
|
}
|
|
|
|
if (!OMPTeamsFound) {
|
|
|
|
Diag(StartLoc, diag::err_omp_target_contains_not_only_teams);
|
|
|
|
Diag(DSAStack->getInnerTeamsRegionLoc(),
|
|
|
|
diag::note_omp_nested_teams_construct_here);
|
|
|
|
Diag(S->getLocStart(), diag::note_omp_nested_statement_here)
|
|
|
|
<< isa<OMPExecutableDirective>(S);
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-19 16:19:49 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
|
|
|
return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt);
|
2014-10-09 12:18:56 +08:00
|
|
|
}
|
|
|
|
|
2015-07-21 21:44:28 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
|
|
|
assert(isa<CapturedStmt>(AStmt) && "Captured statement expected");
|
|
|
|
|
2015-07-21 21:44:28 +08:00
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
|
|
|
return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses,
|
|
|
|
AStmt);
|
|
|
|
}
|
|
|
|
|
2014-10-09 12:18:56 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
Stmt *AStmt, SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-09-03 15:23:48 +08:00
|
|
|
if (!AStmt)
|
|
|
|
return StmtError();
|
|
|
|
|
2014-10-09 12:18:56 +08:00
|
|
|
CapturedStmt *CS = cast<CapturedStmt>(AStmt);
|
|
|
|
// 1.2.2 OpenMP Language Terminology
|
|
|
|
// Structured block - An executable statement with a single entry at the
|
|
|
|
// top and a single exit at the bottom.
|
|
|
|
// The point of exit cannot be a branch out of the structured block.
|
|
|
|
// longjmp() and throw() must not violate the entry/exit criteria.
|
|
|
|
CS->getCapturedDecl()->setNothrow();
|
|
|
|
|
|
|
|
getCurFunction()->setHasBranchProtectedScope();
|
|
|
|
|
|
|
|
return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt);
|
2014-09-19 16:19:49 +08:00
|
|
|
}
|
|
|
|
|
2015-07-01 14:57:41 +08:00
|
|
|
StmtResult
|
|
|
|
Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
OpenMPDirectiveKind CancelRegion) {
|
|
|
|
if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for &&
|
|
|
|
CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) {
|
|
|
|
Diag(StartLoc, diag::err_omp_wrong_cancel_region)
|
|
|
|
<< getOpenMPDirectiveName(CancelRegion);
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
if (DSAStack->isParentNowaitRegion()) {
|
|
|
|
Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0;
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
if (DSAStack->isParentOrderedRegion()) {
|
|
|
|
Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0;
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc,
|
|
|
|
CancelRegion);
|
|
|
|
}
|
|
|
|
|
2015-09-18 16:07:34 +08:00
|
|
|
StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses,
|
|
|
|
SourceLocation StartLoc,
|
2015-07-02 19:25:17 +08:00
|
|
|
SourceLocation EndLoc,
|
|
|
|
OpenMPDirectiveKind CancelRegion) {
|
|
|
|
if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for &&
|
|
|
|
CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) {
|
|
|
|
Diag(StartLoc, diag::err_omp_wrong_cancel_region)
|
|
|
|
<< getOpenMPDirectiveName(CancelRegion);
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
if (DSAStack->isParentNowaitRegion()) {
|
|
|
|
Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1;
|
|
|
|
return StmtError();
|
|
|
|
}
|
|
|
|
if (DSAStack->isParentOrderedRegion()) {
|
|
|
|
Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1;
|
|
|
|
return StmtError();
|
|
|
|
}
|
2015-09-15 20:52:43 +08:00
|
|
|
DSAStack->setParentCancelRegion(/*Cancel=*/true);
|
2015-09-18 16:07:34 +08:00
|
|
|
return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses,
|
|
|
|
CancelRegion);
|
2015-07-02 19:25:17 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr,
|
2014-02-13 13:29:23 +08:00
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2014-05-15 21:04:49 +08:00
|
|
|
OMPClause *Res = nullptr;
|
2014-02-13 13:29:23 +08:00
|
|
|
switch (Kind) {
|
2014-07-17 15:32:53 +08:00
|
|
|
case OMPC_final:
|
|
|
|
Res = ActOnOpenMPFinalClause(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;
|
2015-08-21 19:14:16 +08:00
|
|
|
case OMPC_simdlen:
|
|
|
|
Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-05-27 23:12:19 +08:00
|
|
|
case OMPC_collapse:
|
|
|
|
Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2015-07-30 19:36:16 +08:00
|
|
|
case OMPC_ordered:
|
|
|
|
Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr);
|
|
|
|
break;
|
2015-08-08 00:16:36 +08:00
|
|
|
case OMPC_device:
|
|
|
|
Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2015-09-03 15:23:48 +08:00
|
|
|
case OMPC_if:
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_default:
|
2014-05-06 14:04:14 +08:00
|
|
|
case OMPC_proc_bind:
|
2014-06-20 15:16:17 +08:00
|
|
|
case OMPC_schedule:
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_private:
|
|
|
|
case OMPC_firstprivate:
|
2014-06-04 21:06:39 +08:00
|
|
|
case OMPC_lastprivate:
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_shared:
|
2014-06-16 15:08:35 +08:00
|
|
|
case OMPC_reduction:
|
2014-04-22 21:09:42 +08:00
|
|
|
case OMPC_linear:
|
2014-05-29 22:36:25 +08:00
|
|
|
case OMPC_aligned:
|
2014-03-31 11:36:38 +08:00
|
|
|
case OMPC_copyin:
|
2014-06-27 18:37:06 +08:00
|
|
|
case OMPC_copyprivate:
|
2014-06-20 19:19:47 +08:00
|
|
|
case OMPC_nowait:
|
2014-07-17 20:19:31 +08:00
|
|
|
case OMPC_untied:
|
2014-07-17 20:47:03 +08:00
|
|
|
case OMPC_mergeable:
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_threadprivate:
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPC_flush:
|
2014-07-23 10:27:21 +08:00
|
|
|
case OMPC_read:
|
2014-07-23 15:46:59 +08:00
|
|
|
case OMPC_write:
|
2014-07-23 18:25:33 +08:00
|
|
|
case OMPC_update:
|
2014-07-24 14:46:57 +08:00
|
|
|
case OMPC_capture:
|
2014-07-24 16:55:34 +08:00
|
|
|
case OMPC_seq_cst:
|
2015-06-23 22:25:19 +08:00
|
|
|
case OMPC_depend:
|
2015-09-25 18:37:12 +08:00
|
|
|
case OMPC_threads:
|
2015-09-28 14:39:35 +08:00
|
|
|
case OMPC_simd:
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_unknown:
|
|
|
|
llvm_unreachable("Clause is not allowed.");
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2015-09-03 15:23:48 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier,
|
|
|
|
Expr *Condition, SourceLocation StartLoc,
|
2014-02-13 13:29:23 +08:00
|
|
|
SourceLocation LParenLoc,
|
2015-09-03 15:23:48 +08:00
|
|
|
SourceLocation NameModifierLoc,
|
|
|
|
SourceLocation ColonLoc,
|
2014-02-13 13:29:23 +08:00
|
|
|
SourceLocation EndLoc) {
|
|
|
|
Expr *ValExpr = Condition;
|
|
|
|
if (!Condition->isValueDependent() && !Condition->isTypeDependent() &&
|
|
|
|
!Condition->isInstantiationDependent() &&
|
|
|
|
!Condition->containsUnexpandedParameterPack()) {
|
|
|
|
ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(),
|
2014-05-28 13:53:51 +08:00
|
|
|
Condition->getExprLoc(), Condition);
|
2014-02-13 13:29:23 +08:00
|
|
|
if (Val.isInvalid())
|
2014-05-15 21:04:49 +08:00
|
|
|
return nullptr;
|
2014-02-13 13:29:23 +08:00
|
|
|
|
2014-05-29 18:55:11 +08:00
|
|
|
ValExpr = Val.get();
|
2014-02-13 13:29:23 +08:00
|
|
|
}
|
|
|
|
|
2015-09-03 15:23:48 +08:00
|
|
|
return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc,
|
|
|
|
NameModifierLoc, ColonLoc, EndLoc);
|
2014-02-13 13:29:23 +08:00
|
|
|
}
|
|
|
|
|
2014-07-17 15:32:53 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPFinalClause(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 nullptr;
|
|
|
|
|
|
|
|
ValExpr = Val.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
}
|
2014-06-03 18:16:47 +08:00
|
|
|
ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc,
|
|
|
|
Expr *Op) {
|
2014-03-06 14:15:19 +08:00
|
|
|
if (!Op)
|
|
|
|
return ExprError();
|
|
|
|
|
|
|
|
class IntConvertDiagnoser : public ICEConvertDiagnoser {
|
|
|
|
public:
|
|
|
|
IntConvertDiagnoser()
|
2014-05-28 13:53:51 +08:00
|
|
|
: 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-05-28 13:53:51 +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-05-28 13:53:51 +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-05-28 13:53:51 +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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< ConvTy->isEnumeralType() << ConvTy;
|
2014-03-06 14:15:19 +08:00
|
|
|
}
|
2014-05-28 13:53:51 +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-05-28 13:53:51 +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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< ConvTy->isEnumeralType() << ConvTy;
|
2014-03-06 14:15:19 +08:00
|
|
|
}
|
2014-05-28 13:53:51 +08:00
|
|
|
SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType,
|
|
|
|
QualType) 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->containsUnexpandedParameterPack()) {
|
|
|
|
SourceLocation NumThreadsLoc = NumThreads->getLocStart();
|
|
|
|
ExprResult Val =
|
2014-06-03 18:16:47 +08:00
|
|
|
PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads);
|
2014-03-06 14:15:19 +08:00
|
|
|
if (Val.isInvalid())
|
2014-05-15 21:04:49 +08:00
|
|
|
return nullptr;
|
2014-03-06 14:15:19 +08:00
|
|
|
|
2014-05-29 18:55:11 +08:00
|
|
|
ValExpr = Val.get();
|
2014-03-06 14:15:19 +08:00
|
|
|
|
|
|
|
// OpenMP [2.5, Restrictions]
|
|
|
|
// The num_threads expression must evaluate to a positive integer value.
|
|
|
|
llvm::APSInt Result;
|
2014-05-28 13:53:51 +08:00
|
|
|
if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() &&
|
|
|
|
!Result.isStrictlyPositive()) {
|
2014-03-06 14:15:19 +08:00
|
|
|
Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause)
|
|
|
|
<< "num_threads" << NumThreads->getSourceRange();
|
2014-05-15 21:04:49 +08:00
|
|
|
return nullptr;
|
2014-03-06 14:15:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
return new (Context)
|
|
|
|
OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc);
|
2014-03-06 14:15:19 +08:00
|
|
|
}
|
|
|
|
|
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())
|
2014-05-29 22:05:12 +08:00
|
|
|
return E;
|
2014-03-21 12:51:18 +08:00
|
|
|
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();
|
|
|
|
}
|
2014-09-30 13:29:28 +08:00
|
|
|
if (CKind == OMPC_aligned && !Result.isPowerOf2()) {
|
|
|
|
Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two)
|
|
|
|
<< E->getSourceRange();
|
|
|
|
return ExprError();
|
|
|
|
}
|
2015-04-30 12:23:23 +08:00
|
|
|
if (CKind == OMPC_collapse) {
|
2015-07-30 19:36:16 +08:00
|
|
|
DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 +
|
|
|
|
Result.getExtValue());
|
|
|
|
} else if (CKind == OMPC_ordered) {
|
|
|
|
DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 +
|
|
|
|
Result.getExtValue());
|
2015-04-30 12:23:23 +08:00
|
|
|
}
|
2014-03-21 12:51:18 +08:00
|
|
|
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())
|
2014-05-15 21:04:49 +08:00
|
|
|
return nullptr;
|
2014-03-21 12:51:18 +08:00
|
|
|
return new (Context)
|
2014-05-29 18:55:11 +08:00
|
|
|
OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc);
|
2014-03-21 12:51:18 +08:00
|
|
|
}
|
|
|
|
|
2015-08-21 19:14:16 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
// OpenMP [2.8.1, simd construct, Description]
|
|
|
|
// The parameter of the simdlen clause must be a constant
|
|
|
|
// positive integer expression.
|
|
|
|
ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen);
|
|
|
|
if (Simdlen.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
return new (Context)
|
|
|
|
OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-06-04 15:53:32 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops,
|
|
|
|
SourceLocation StartLoc,
|
2014-05-27 23:12:19 +08:00
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2014-06-04 15:53:32 +08:00
|
|
|
// OpenMP [2.7.1, loop construct, Description]
|
2014-05-27 23:12:19 +08:00
|
|
|
// OpenMP [2.8.1, simd construct, Description]
|
2014-06-04 15:53:32 +08:00
|
|
|
// OpenMP [2.9.6, distribute construct, Description]
|
2014-05-27 23:12:19 +08:00
|
|
|
// The parameter of the collapse clause must be a constant
|
|
|
|
// positive integer expression.
|
2014-06-04 15:53:32 +08:00
|
|
|
ExprResult NumForLoopsResult =
|
|
|
|
VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse);
|
|
|
|
if (NumForLoopsResult.isInvalid())
|
2014-05-27 23:12:19 +08:00
|
|
|
return nullptr;
|
|
|
|
return new (Context)
|
2014-06-04 15:53:32 +08:00
|
|
|
OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc);
|
2014-05-27 23:12:19 +08:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:36:16 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
Expr *NumForLoops) {
|
|
|
|
// OpenMP [2.7.1, loop construct, Description]
|
|
|
|
// OpenMP [2.8.1, simd construct, Description]
|
|
|
|
// OpenMP [2.9.6, distribute construct, Description]
|
|
|
|
// The parameter of the ordered clause must be a constant
|
|
|
|
// positive integer expression if any.
|
|
|
|
if (NumForLoops && LParenLoc.isValid()) {
|
|
|
|
ExprResult NumForLoopsResult =
|
|
|
|
VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered);
|
|
|
|
if (NumForLoopsResult.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
NumForLoops = NumForLoopsResult.get();
|
2015-09-25 18:37:12 +08:00
|
|
|
} else
|
|
|
|
NumForLoops = nullptr;
|
|
|
|
DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops);
|
2015-07-30 19:36:16 +08:00
|
|
|
return new (Context)
|
|
|
|
OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSimpleClause(
|
|
|
|
OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc,
|
|
|
|
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) {
|
2014-05-15 21:04:49 +08:00
|
|
|
OMPClause *Res = nullptr;
|
2013-07-19 11:13:43 +08:00
|
|
|
switch (Kind) {
|
|
|
|
case OMPC_default:
|
2013-09-07 02:03:48 +08:00
|
|
|
Res =
|
2014-05-28 13:53:51 +08:00
|
|
|
ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument),
|
|
|
|
ArgumentLoc, StartLoc, LParenLoc, EndLoc);
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
2014-05-06 14:04:14 +08:00
|
|
|
case OMPC_proc_bind:
|
2014-05-28 13:53:51 +08:00
|
|
|
Res = ActOnOpenMPProcBindClause(
|
|
|
|
static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc,
|
|
|
|
LParenLoc, EndLoc);
|
2014-05-06 14:04:14 +08:00
|
|
|
break;
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_if:
|
2014-07-17 15:32:53 +08:00
|
|
|
case OMPC_final:
|
2014-03-06 14:15:19 +08:00
|
|
|
case OMPC_num_threads:
|
2014-03-21 12:51:18 +08:00
|
|
|
case OMPC_safelen:
|
2015-08-21 19:14:16 +08:00
|
|
|
case OMPC_simdlen:
|
2014-05-27 23:12:19 +08:00
|
|
|
case OMPC_collapse:
|
2014-06-20 15:16:17 +08:00
|
|
|
case OMPC_schedule:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_private:
|
2013-10-01 13:32:34 +08:00
|
|
|
case OMPC_firstprivate:
|
2014-06-04 21:06:39 +08:00
|
|
|
case OMPC_lastprivate:
|
2013-09-07 02:03:48 +08:00
|
|
|
case OMPC_shared:
|
2014-06-16 15:08:35 +08:00
|
|
|
case OMPC_reduction:
|
2014-04-22 21:09:42 +08:00
|
|
|
case OMPC_linear:
|
2014-05-29 22:36:25 +08:00
|
|
|
case OMPC_aligned:
|
2014-03-31 11:36:38 +08:00
|
|
|
case OMPC_copyin:
|
2014-06-27 18:37:06 +08:00
|
|
|
case OMPC_copyprivate:
|
2014-06-20 17:44:06 +08:00
|
|
|
case OMPC_ordered:
|
2014-06-20 19:19:47 +08:00
|
|
|
case OMPC_nowait:
|
2014-07-17 20:19:31 +08:00
|
|
|
case OMPC_untied:
|
2014-07-17 20:47:03 +08:00
|
|
|
case OMPC_mergeable:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_threadprivate:
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPC_flush:
|
2014-07-23 10:27:21 +08:00
|
|
|
case OMPC_read:
|
2014-07-23 15:46:59 +08:00
|
|
|
case OMPC_write:
|
2014-07-23 18:25:33 +08:00
|
|
|
case OMPC_update:
|
2014-07-24 14:46:57 +08:00
|
|
|
case OMPC_capture:
|
2014-07-24 16:55:34 +08:00
|
|
|
case OMPC_seq_cst:
|
2015-06-23 22:25:19 +08:00
|
|
|
case OMPC_depend:
|
2015-08-08 00:16:36 +08:00
|
|
|
case OMPC_device:
|
2015-09-25 18:37:12 +08:00
|
|
|
case OMPC_threads:
|
2015-09-28 14:39:35 +08:00
|
|
|
case OMPC_simd:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_unknown:
|
|
|
|
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-05-12 12:23:46 +08:00
|
|
|
static_assert(OMPC_DEFAULT_unknown > 0,
|
|
|
|
"OMPC_DEFAULT_unknown not greater than 0");
|
2014-03-22 01:34:28 +08:00
|
|
|
std::string Sep(", ");
|
2014-05-12 12:23:46 +08:00
|
|
|
for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) {
|
2013-07-19 11:13:43 +08:00
|
|
|
Values += "'";
|
|
|
|
Values += getOpenMPSimpleClauseTypeName(OMPC_default, i);
|
|
|
|
Values += "'";
|
|
|
|
switch (i) {
|
2014-05-12 12:23:46 +08:00
|
|
|
case OMPC_DEFAULT_unknown - 2:
|
2013-07-19 11:13:43 +08:00
|
|
|
Values += " or ";
|
|
|
|
break;
|
2014-05-12 12:23:46 +08:00
|
|
|
case OMPC_DEFAULT_unknown - 1:
|
2013-07-19 11:13:43 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Values += Sep;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Diag(KindKwLoc, diag::err_omp_unexpected_clause_value)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< Values << getOpenMPClauseName(OMPC_default);
|
2014-05-15 21:04:49 +08:00
|
|
|
return nullptr;
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
2013-09-07 02:03:48 +08:00
|
|
|
switch (Kind) {
|
|
|
|
case OMPC_DEFAULT_none:
|
2014-06-27 18:37:06 +08:00
|
|
|
DSAStack->setDefaultDSANone(KindKwLoc);
|
2013-09-07 02:03:48 +08:00
|
|
|
break;
|
|
|
|
case OMPC_DEFAULT_shared:
|
2014-06-27 18:37:06 +08:00
|
|
|
DSAStack->setDefaultDSAShared(KindKwLoc);
|
2013-09-07 02:03:48 +08:00
|
|
|
break;
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_DEFAULT_unknown:
|
|
|
|
llvm_unreachable("Clause kind is not allowed.");
|
2013-09-07 02:03:48 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-05-28 13:53:51 +08:00
|
|
|
return new (Context)
|
|
|
|
OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
2014-05-06 14:04:14 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind,
|
|
|
|
SourceLocation KindKwLoc,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
if (Kind == OMPC_PROC_BIND_unknown) {
|
|
|
|
std::string Values;
|
|
|
|
std::string Sep(", ");
|
|
|
|
for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) {
|
|
|
|
Values += "'";
|
|
|
|
Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i);
|
|
|
|
Values += "'";
|
|
|
|
switch (i) {
|
|
|
|
case OMPC_PROC_BIND_unknown - 2:
|
|
|
|
Values += " or ";
|
|
|
|
break;
|
|
|
|
case OMPC_PROC_BIND_unknown - 1:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Values += Sep;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Diag(KindKwLoc, diag::err_omp_unexpected_clause_value)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< Values << getOpenMPClauseName(OMPC_proc_bind);
|
2014-05-15 21:04:49 +08:00
|
|
|
return nullptr;
|
2014-05-06 14:04:14 +08:00
|
|
|
}
|
2014-05-28 13:53:51 +08:00
|
|
|
return new (Context)
|
|
|
|
OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
|
2014-05-06 14:04:14 +08:00
|
|
|
}
|
|
|
|
|
2014-06-20 15:16:17 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause(
|
|
|
|
OpenMPClauseKind Kind, unsigned Argument, Expr *Expr,
|
|
|
|
SourceLocation StartLoc, SourceLocation LParenLoc,
|
2015-09-03 15:23:48 +08:00
|
|
|
SourceLocation ArgumentLoc, SourceLocation DelimLoc,
|
2014-06-20 15:16:17 +08:00
|
|
|
SourceLocation EndLoc) {
|
|
|
|
OMPClause *Res = nullptr;
|
|
|
|
switch (Kind) {
|
|
|
|
case OMPC_schedule:
|
|
|
|
Res = ActOnOpenMPScheduleClause(
|
|
|
|
static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc,
|
2015-09-03 15:23:48 +08:00
|
|
|
LParenLoc, ArgumentLoc, DelimLoc, EndLoc);
|
2014-06-20 15:16:17 +08:00
|
|
|
break;
|
|
|
|
case OMPC_if:
|
2015-09-03 15:23:48 +08:00
|
|
|
Res =
|
|
|
|
ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr,
|
|
|
|
StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc);
|
|
|
|
break;
|
2014-07-17 15:32:53 +08:00
|
|
|
case OMPC_final:
|
2014-06-20 15:16:17 +08:00
|
|
|
case OMPC_num_threads:
|
|
|
|
case OMPC_safelen:
|
2015-08-21 19:14:16 +08:00
|
|
|
case OMPC_simdlen:
|
2014-06-20 15:16:17 +08:00
|
|
|
case OMPC_collapse:
|
|
|
|
case OMPC_default:
|
|
|
|
case OMPC_proc_bind:
|
|
|
|
case OMPC_private:
|
|
|
|
case OMPC_firstprivate:
|
|
|
|
case OMPC_lastprivate:
|
|
|
|
case OMPC_shared:
|
|
|
|
case OMPC_reduction:
|
|
|
|
case OMPC_linear:
|
|
|
|
case OMPC_aligned:
|
|
|
|
case OMPC_copyin:
|
2014-06-27 18:37:06 +08:00
|
|
|
case OMPC_copyprivate:
|
2014-06-20 17:44:06 +08:00
|
|
|
case OMPC_ordered:
|
2014-06-20 19:19:47 +08:00
|
|
|
case OMPC_nowait:
|
2014-07-17 20:19:31 +08:00
|
|
|
case OMPC_untied:
|
2014-07-17 20:47:03 +08:00
|
|
|
case OMPC_mergeable:
|
2014-06-20 15:16:17 +08:00
|
|
|
case OMPC_threadprivate:
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPC_flush:
|
2014-07-23 10:27:21 +08:00
|
|
|
case OMPC_read:
|
2014-07-23 15:46:59 +08:00
|
|
|
case OMPC_write:
|
2014-07-23 18:25:33 +08:00
|
|
|
case OMPC_update:
|
2014-07-24 14:46:57 +08:00
|
|
|
case OMPC_capture:
|
2014-07-24 16:55:34 +08:00
|
|
|
case OMPC_seq_cst:
|
2015-06-23 22:25:19 +08:00
|
|
|
case OMPC_depend:
|
2015-08-08 00:16:36 +08:00
|
|
|
case OMPC_device:
|
2015-09-25 18:37:12 +08:00
|
|
|
case OMPC_threads:
|
2015-09-28 14:39:35 +08:00
|
|
|
case OMPC_simd:
|
2014-06-20 15:16:17 +08:00
|
|
|
case OMPC_unknown:
|
|
|
|
llvm_unreachable("Clause is not allowed.");
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPScheduleClause(
|
|
|
|
OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
if (Kind == OMPC_SCHEDULE_unknown) {
|
|
|
|
std::string Values;
|
|
|
|
std::string Sep(", ");
|
|
|
|
for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) {
|
|
|
|
Values += "'";
|
|
|
|
Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i);
|
|
|
|
Values += "'";
|
|
|
|
switch (i) {
|
|
|
|
case OMPC_SCHEDULE_unknown - 2:
|
|
|
|
Values += " or ";
|
|
|
|
break;
|
|
|
|
case OMPC_SCHEDULE_unknown - 1:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Values += Sep;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Diag(KindLoc, diag::err_omp_unexpected_clause_value)
|
|
|
|
<< Values << getOpenMPClauseName(OMPC_schedule);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
Expr *ValExpr = ChunkSize;
|
2015-05-12 16:35:28 +08:00
|
|
|
Expr *HelperValExpr = nullptr;
|
2014-06-20 15:16:17 +08:00
|
|
|
if (ChunkSize) {
|
|
|
|
if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() &&
|
|
|
|
!ChunkSize->isInstantiationDependent() &&
|
|
|
|
!ChunkSize->containsUnexpandedParameterPack()) {
|
|
|
|
SourceLocation ChunkSizeLoc = ChunkSize->getLocStart();
|
|
|
|
ExprResult Val =
|
|
|
|
PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize);
|
|
|
|
if (Val.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
ValExpr = Val.get();
|
|
|
|
|
|
|
|
// OpenMP [2.7.1, Restrictions]
|
|
|
|
// chunk_size must be a loop invariant integer expression with a positive
|
|
|
|
// value.
|
|
|
|
llvm::APSInt Result;
|
2015-05-12 16:35:28 +08:00
|
|
|
if (ValExpr->isIntegerConstantExpr(Result, Context)) {
|
|
|
|
if (Result.isSigned() && !Result.isStrictlyPositive()) {
|
|
|
|
Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause)
|
|
|
|
<< "schedule" << ChunkSize->getSourceRange();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) {
|
|
|
|
auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(),
|
|
|
|
ChunkSize->getType(), ".chunk.");
|
|
|
|
auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(),
|
|
|
|
ChunkSize->getExprLoc(),
|
|
|
|
/*RefersToCapture=*/true);
|
|
|
|
HelperValExpr = ImpVarRef;
|
2014-06-20 15:16:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc,
|
2015-05-12 16:35:28 +08:00
|
|
|
EndLoc, Kind, ValExpr, HelperValExpr);
|
2014-06-20 15:16:17 +08:00
|
|
|
}
|
|
|
|
|
2014-06-20 17:44:06 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
OMPClause *Res = nullptr;
|
|
|
|
switch (Kind) {
|
|
|
|
case OMPC_ordered:
|
|
|
|
Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-06-20 19:19:47 +08:00
|
|
|
case OMPC_nowait:
|
|
|
|
Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-17 20:19:31 +08:00
|
|
|
case OMPC_untied:
|
|
|
|
Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-17 20:47:03 +08:00
|
|
|
case OMPC_mergeable:
|
|
|
|
Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-23 10:27:21 +08:00
|
|
|
case OMPC_read:
|
|
|
|
Res = ActOnOpenMPReadClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-23 15:46:59 +08:00
|
|
|
case OMPC_write:
|
|
|
|
Res = ActOnOpenMPWriteClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-23 18:25:33 +08:00
|
|
|
case OMPC_update:
|
|
|
|
Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-24 14:46:57 +08:00
|
|
|
case OMPC_capture:
|
|
|
|
Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-07-24 16:55:34 +08:00
|
|
|
case OMPC_seq_cst:
|
|
|
|
Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2015-09-25 18:37:12 +08:00
|
|
|
case OMPC_threads:
|
|
|
|
Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2015-09-28 14:39:35 +08:00
|
|
|
case OMPC_simd:
|
|
|
|
Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc);
|
|
|
|
break;
|
2014-06-20 17:44:06 +08:00
|
|
|
case OMPC_if:
|
2014-07-17 15:32:53 +08:00
|
|
|
case OMPC_final:
|
2014-06-20 17:44:06 +08:00
|
|
|
case OMPC_num_threads:
|
|
|
|
case OMPC_safelen:
|
2015-08-21 19:14:16 +08:00
|
|
|
case OMPC_simdlen:
|
2014-06-20 17:44:06 +08:00
|
|
|
case OMPC_collapse:
|
|
|
|
case OMPC_schedule:
|
|
|
|
case OMPC_private:
|
|
|
|
case OMPC_firstprivate:
|
|
|
|
case OMPC_lastprivate:
|
|
|
|
case OMPC_shared:
|
|
|
|
case OMPC_reduction:
|
|
|
|
case OMPC_linear:
|
|
|
|
case OMPC_aligned:
|
|
|
|
case OMPC_copyin:
|
2014-06-27 18:37:06 +08:00
|
|
|
case OMPC_copyprivate:
|
2014-06-20 17:44:06 +08:00
|
|
|
case OMPC_default:
|
|
|
|
case OMPC_proc_bind:
|
|
|
|
case OMPC_threadprivate:
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPC_flush:
|
2015-06-23 22:25:19 +08:00
|
|
|
case OMPC_depend:
|
2015-08-08 00:16:36 +08:00
|
|
|
case OMPC_device:
|
2014-06-20 17:44:06 +08:00
|
|
|
case OMPC_unknown:
|
|
|
|
llvm_unreachable("Clause is not allowed.");
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2014-06-20 19:19:47 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
2015-07-01 14:57:41 +08:00
|
|
|
DSAStack->setNowaitRegion();
|
2014-06-20 19:19:47 +08:00
|
|
|
return new (Context) OMPNowaitClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-17 20:19:31 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPUntiedClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-17 20:47:03 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPMergeableClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-23 10:27:21 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPReadClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-23 15:46:59 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPWriteClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-23 18:25:33 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPUpdateClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-24 14:46:57 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPCaptureClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-07-24 16:55:34 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPSeqCstClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2015-09-25 18:37:12 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPThreadsClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2015-09-28 14:39:35 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
return new (Context) OMPSIMDClause(StartLoc, EndLoc);
|
|
|
|
}
|
|
|
|
|
2014-06-16 15:08:35 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPVarListClause(
|
|
|
|
OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr,
|
|
|
|
SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc,
|
|
|
|
SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
|
2015-06-23 22:25:19 +08:00
|
|
|
const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind,
|
2015-08-20 18:54:39 +08:00
|
|
|
OpenMPLinearClauseKind LinKind, SourceLocation DepLinLoc) {
|
2014-05-15 21:04:49 +08:00
|
|
|
OMPClause *Res = nullptr;
|
2013-07-19 11:13:43 +08:00
|
|
|
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;
|
2014-06-04 21:06:39 +08:00
|
|
|
case OMPC_lastprivate:
|
|
|
|
Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2013-09-07 02:03:48 +08:00
|
|
|
case OMPC_shared:
|
|
|
|
Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-06-16 15:08:35 +08:00
|
|
|
case OMPC_reduction:
|
2014-06-18 15:08:49 +08:00
|
|
|
Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc,
|
|
|
|
EndLoc, ReductionIdScopeSpec, ReductionId);
|
2014-06-16 15:08:35 +08:00
|
|
|
break;
|
2014-04-22 21:09:42 +08:00
|
|
|
case OMPC_linear:
|
|
|
|
Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc,
|
2015-08-20 18:54:39 +08:00
|
|
|
LinKind, DepLinLoc, ColonLoc, EndLoc);
|
2014-04-22 21:09:42 +08:00
|
|
|
break;
|
2014-05-29 22:36:25 +08:00
|
|
|
case OMPC_aligned:
|
|
|
|
Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc,
|
|
|
|
ColonLoc, EndLoc);
|
|
|
|
break;
|
2014-03-31 11:36:38 +08:00
|
|
|
case OMPC_copyin:
|
|
|
|
Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-06-27 18:37:06 +08:00
|
|
|
case OMPC_copyprivate:
|
|
|
|
Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-07-21 19:26:11 +08:00
|
|
|
case OMPC_flush:
|
|
|
|
Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc);
|
|
|
|
break;
|
2015-06-23 22:25:19 +08:00
|
|
|
case OMPC_depend:
|
2015-08-20 18:54:39 +08:00
|
|
|
Res = ActOnOpenMPDependClause(DepKind, DepLinLoc, ColonLoc, VarList, StartLoc,
|
2015-06-23 22:25:19 +08:00
|
|
|
LParenLoc, EndLoc);
|
|
|
|
break;
|
2014-02-13 13:29:23 +08:00
|
|
|
case OMPC_if:
|
2014-07-17 15:32:53 +08:00
|
|
|
case OMPC_final:
|
2014-03-06 14:15:19 +08:00
|
|
|
case OMPC_num_threads:
|
2014-03-21 12:51:18 +08:00
|
|
|
case OMPC_safelen:
|
2015-08-21 19:14:16 +08:00
|
|
|
case OMPC_simdlen:
|
2014-05-27 23:12:19 +08:00
|
|
|
case OMPC_collapse:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_default:
|
2014-05-06 14:04:14 +08:00
|
|
|
case OMPC_proc_bind:
|
2014-06-20 15:16:17 +08:00
|
|
|
case OMPC_schedule:
|
2014-06-20 17:44:06 +08:00
|
|
|
case OMPC_ordered:
|
2014-06-20 19:19:47 +08:00
|
|
|
case OMPC_nowait:
|
2014-07-17 20:19:31 +08:00
|
|
|
case OMPC_untied:
|
2014-07-17 20:47:03 +08:00
|
|
|
case OMPC_mergeable:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_threadprivate:
|
2014-07-23 10:27:21 +08:00
|
|
|
case OMPC_read:
|
2014-07-23 15:46:59 +08:00
|
|
|
case OMPC_write:
|
2014-07-23 18:25:33 +08:00
|
|
|
case OMPC_update:
|
2014-07-24 14:46:57 +08:00
|
|
|
case OMPC_capture:
|
2014-07-24 16:55:34 +08:00
|
|
|
case OMPC_seq_cst:
|
2015-08-08 00:16:36 +08:00
|
|
|
case OMPC_device:
|
2015-09-25 18:37:12 +08:00
|
|
|
case OMPC_threads:
|
2015-09-28 14:39:35 +08:00
|
|
|
case OMPC_simd:
|
2013-07-19 11:13:43 +08:00
|
|
|
case OMPC_unknown:
|
|
|
|
llvm_unreachable("Clause is not allowed.");
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
2014-10-21 11:16:40 +08:00
|
|
|
SmallVector<Expr *, 8> PrivateCopies;
|
2014-05-28 13:53:51 +08:00
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP private clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
2013-07-19 11:13:43 +08:00
|
|
|
// It will be analyzed later.
|
2014-05-28 13:53:51 +08:00
|
|
|
Vars.push_back(RefExpr);
|
2014-10-21 11:16:40 +08:00
|
|
|
PrivateCopies.push_back(nullptr);
|
2013-07-19 11:13:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
SourceLocation ELoc = RefExpr->getExprLoc();
|
2013-07-19 11:13:43 +08:00
|
|
|
// 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.
|
2014-05-28 13:53:51 +08:00
|
|
|
DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr);
|
2013-07-19 11:13:43 +08:00
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
2014-05-28 13:53:51 +08:00
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange();
|
2013-07-19 11:13:43 +08:00
|
|
|
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);
|
2014-10-21 11:16:40 +08:00
|
|
|
PrivateCopies.push_back(nullptr);
|
2013-07-19 11:13:43 +08:00
|
|
|
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;
|
|
|
|
}
|
2015-08-18 14:47:21 +08:00
|
|
|
Type = Type.getNonReferenceType();
|
2013-07-19 11:13:43 +08:00
|
|
|
|
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.
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false);
|
2013-09-07 02:03:48 +08:00
|
|
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) {
|
2014-05-28 13:53:51 +08:00
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_private);
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
2013-09-07 02:03:48 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-05-19 16:44:56 +08:00
|
|
|
// Variably modified types are not supported for tasks.
|
2015-05-21 17:47:46 +08:00
|
|
|
if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() &&
|
2015-05-19 16:44:56 +08:00
|
|
|
DSAStack->getCurrentDirective() == OMPD_task) {
|
|
|
|
Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
|
|
|
|
<< getOpenMPClauseName(OMPC_private) << Type
|
|
|
|
<< getOpenMPDirectiveName(DSAStack->getCurrentDirective());
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-05-19 15:46:42 +08:00
|
|
|
// 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 accessible, unambiguous default constructor for the
|
|
|
|
// class type.
|
2014-10-21 11:16:40 +08:00
|
|
|
// Generate helper private variable and initialize it with the default
|
|
|
|
// value. The address of the original variable is replaced by the address of
|
|
|
|
// the new private variable in CodeGen. This new variable is not added to
|
|
|
|
// IdResolver, so the code in the OpenMP region uses original variable for
|
|
|
|
// proper diagnostics.
|
2015-05-19 15:46:42 +08:00
|
|
|
Type = Type.getUnqualifiedType();
|
2015-09-10 17:48:30 +08:00
|
|
|
auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(),
|
|
|
|
VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-05-08 18:41:21 +08:00
|
|
|
ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false);
|
2014-10-21 11:16:40 +08:00
|
|
|
if (VDPrivate->isInvalidDecl())
|
|
|
|
continue;
|
2015-05-19 15:46:42 +08:00
|
|
|
auto VDPrivateRefExpr = buildDeclRefExpr(
|
|
|
|
*this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc());
|
2014-10-21 11:16:40 +08:00
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
DSAStack->addDSA(VD, DE, OMPC_private);
|
2013-07-19 11:13:43 +08:00
|
|
|
Vars.push_back(DE);
|
2014-10-21 11:16:40 +08:00
|
|
|
PrivateCopies.push_back(VDPrivateRefExpr);
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
2013-07-19 11:13:43 +08:00
|
|
|
|
2014-10-21 11:16:40 +08:00
|
|
|
return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars,
|
|
|
|
PrivateCopies);
|
2013-07-19 11:13:43 +08:00
|
|
|
}
|
|
|
|
|
2014-10-08 22:01:46 +08:00
|
|
|
namespace {
|
|
|
|
class DiagsUninitializedSeveretyRAII {
|
|
|
|
private:
|
|
|
|
DiagnosticsEngine &Diags;
|
|
|
|
SourceLocation SavedLoc;
|
|
|
|
bool IsIgnored;
|
|
|
|
|
|
|
|
public:
|
|
|
|
DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc,
|
|
|
|
bool IsIgnored)
|
|
|
|
: Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) {
|
|
|
|
if (!IsIgnored) {
|
|
|
|
Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init,
|
|
|
|
/*Map*/ diag::Severity::Ignored, Loc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
~DiagsUninitializedSeveretyRAII() {
|
|
|
|
if (!IsIgnored)
|
|
|
|
Diags.popMappings(SavedLoc);
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2014-10-08 22:01:46 +08:00
|
|
|
|
2013-10-01 13:32:34 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
2014-10-08 22:01:46 +08:00
|
|
|
SmallVector<Expr *, 8> PrivateCopies;
|
|
|
|
SmallVector<Expr *, 8> Inits;
|
2014-07-11 19:25:16 +08:00
|
|
|
bool IsImplicitClause =
|
|
|
|
StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid();
|
|
|
|
auto ImplicitClauseLoc = DSAStack->getConstructLoc();
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP firstprivate clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
2013-10-01 13:32:34 +08:00
|
|
|
// It will be analyzed later.
|
2014-05-28 13:53:51 +08:00
|
|
|
Vars.push_back(RefExpr);
|
2014-10-08 22:01:46 +08:00
|
|
|
PrivateCopies.push_back(nullptr);
|
|
|
|
Inits.push_back(nullptr);
|
2013-10-01 13:32:34 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-10-08 22:01:46 +08:00
|
|
|
SourceLocation ELoc =
|
|
|
|
IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc();
|
2013-10-01 13:32:34 +08:00
|
|
|
// 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.
|
2014-05-28 13:53:51 +08:00
|
|
|
DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr);
|
2013-10-01 13:32:34 +08:00
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
2014-05-28 13:53:51 +08:00
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange();
|
2013-10-01 13:32:34 +08:00
|
|
|
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);
|
2014-10-08 22:01:46 +08:00
|
|
|
PrivateCopies.push_back(nullptr);
|
|
|
|
Inits.push_back(nullptr);
|
2013-10-01 13:32:34 +08:00
|
|
|
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;
|
|
|
|
}
|
2015-08-18 14:47:21 +08:00
|
|
|
Type = Type.getNonReferenceType();
|
2013-10-01 13:32:34 +08:00
|
|
|
|
|
|
|
// OpenMP [2.9.3.4, Restrictions, C/C++, p.1]
|
|
|
|
// A variable of class type (or array thereof) that appears in a private
|
2014-06-18 15:08:49 +08:00
|
|
|
// clause requires an accessible, unambiguous copy constructor for the
|
2013-10-01 13:32:34 +08:00
|
|
|
// class type.
|
2015-05-19 15:46:42 +08:00
|
|
|
auto ElemType = Context.getBaseElementType(Type).getNonReferenceType();
|
2013-10-01 13:32:34 +08:00
|
|
|
|
2014-07-11 19:25:16 +08:00
|
|
|
// If an implicit firstprivate variable found it was checked already.
|
|
|
|
if (!IsImplicitClause) {
|
|
|
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false);
|
2015-05-19 15:46:42 +08:00
|
|
|
bool IsConstant = ElemType.isConstant(Context);
|
2013-10-01 13:32:34 +08:00
|
|
|
// 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.
|
|
|
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate &&
|
2014-06-18 12:14:57 +08:00
|
|
|
DVar.CKind != OMPC_lastprivate && DVar.RefExpr) {
|
2013-10-01 13:32:34 +08:00
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate);
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
2013-10-01 13:32:34 +08:00
|
|
|
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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate);
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
2013-10-01 13:32:34 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective();
|
2013-10-01 13:32:34 +08:00
|
|
|
// 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.
|
2014-06-24 12:39:47 +08:00
|
|
|
if (isOpenMPWorksharingDirective(CurrDir) &&
|
|
|
|
!isOpenMPParallelDirective(CurrDir)) {
|
2014-07-11 19:25:16 +08:00
|
|
|
DVar = DSAStack->getImplicitDSA(VD, true);
|
|
|
|
if (DVar.CKind != OMPC_shared &&
|
|
|
|
(isOpenMPParallelDirective(DVar.DKind) ||
|
|
|
|
DVar.DKind == OMPD_unknown)) {
|
2014-06-18 12:14:57 +08:00
|
|
|
Diag(ELoc, diag::err_omp_required_access)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate)
|
|
|
|
<< getOpenMPClauseName(OMPC_shared);
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
2014-06-18 12:14:57 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-10-01 13:32:34 +08:00
|
|
|
// 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.
|
2014-07-11 19:25:16 +08:00
|
|
|
if (CurrDir == OMPD_task) {
|
|
|
|
DVar =
|
|
|
|
DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction),
|
|
|
|
[](OpenMPDirectiveKind K) -> bool {
|
|
|
|
return isOpenMPParallelDirective(K) ||
|
|
|
|
isOpenMPWorksharingDirective(K);
|
|
|
|
},
|
|
|
|
false);
|
|
|
|
if (DVar.CKind == OMPC_reduction &&
|
|
|
|
(isOpenMPParallelDirective(DVar.DKind) ||
|
|
|
|
isOpenMPWorksharingDirective(DVar.DKind))) {
|
|
|
|
Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate)
|
|
|
|
<< getOpenMPDirectiveName(DVar.DKind);
|
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2013-10-01 13:32:34 +08:00
|
|
|
}
|
|
|
|
|
2015-05-19 16:44:56 +08:00
|
|
|
// Variably modified types are not supported for tasks.
|
2015-05-21 17:47:46 +08:00
|
|
|
if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() &&
|
2015-05-19 16:44:56 +08:00
|
|
|
DSAStack->getCurrentDirective() == OMPD_task) {
|
|
|
|
Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
|
|
|
|
<< getOpenMPClauseName(OMPC_firstprivate) << Type
|
|
|
|
<< getOpenMPDirectiveName(DSAStack->getCurrentDirective());
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-05-19 15:46:42 +08:00
|
|
|
Type = Type.getUnqualifiedType();
|
2015-09-10 17:48:30 +08:00
|
|
|
auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(),
|
|
|
|
VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2014-10-08 22:01:46 +08:00
|
|
|
// Generate helper private variable and initialize it with the value of the
|
|
|
|
// original variable. The address of the original variable is replaced by
|
|
|
|
// the address of the new private variable in the CodeGen. This new variable
|
|
|
|
// is not added to IdResolver, so the code in the OpenMP region uses
|
|
|
|
// original variable for proper diagnostics and variable capturing.
|
|
|
|
Expr *VDInitRefExpr = nullptr;
|
|
|
|
// For arrays generate initializer for single element and replace it by the
|
|
|
|
// original array element in CodeGen.
|
2015-05-19 15:46:42 +08:00
|
|
|
if (Type->isArrayType()) {
|
|
|
|
auto VDInit =
|
|
|
|
buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName());
|
|
|
|
VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc);
|
2014-10-08 22:01:46 +08:00
|
|
|
auto Init = DefaultLvalueConversion(VDInitRefExpr).get();
|
2015-05-19 15:46:42 +08:00
|
|
|
ElemType = ElemType.getUnqualifiedType();
|
|
|
|
auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType,
|
|
|
|
".firstprivate.temp");
|
2015-04-15 12:52:20 +08:00
|
|
|
InitializedEntity Entity =
|
|
|
|
InitializedEntity::InitializeVariable(VDInitTemp);
|
2014-10-08 22:01:46 +08:00
|
|
|
InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc);
|
|
|
|
|
|
|
|
InitializationSequence InitSeq(*this, Entity, Kind, Init);
|
|
|
|
ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init);
|
|
|
|
if (Result.isInvalid())
|
|
|
|
VDPrivate->setInvalidDecl();
|
|
|
|
else
|
|
|
|
VDPrivate->setInit(Result.getAs<Expr>());
|
|
|
|
} else {
|
2015-04-15 12:52:20 +08:00
|
|
|
auto *VDInit =
|
2015-05-08 18:41:21 +08:00
|
|
|
buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp");
|
2015-05-19 15:46:42 +08:00
|
|
|
VDInitRefExpr =
|
|
|
|
buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc());
|
2015-04-15 12:52:20 +08:00
|
|
|
AddInitializerToDecl(VDPrivate,
|
|
|
|
DefaultLvalueConversion(VDInitRefExpr).get(),
|
|
|
|
/*DirectInit=*/false, /*TypeMayContainAuto=*/false);
|
2014-10-08 22:01:46 +08:00
|
|
|
}
|
|
|
|
if (VDPrivate->isInvalidDecl()) {
|
|
|
|
if (IsImplicitClause) {
|
|
|
|
Diag(DE->getExprLoc(),
|
|
|
|
diag::note_omp_task_predetermined_firstprivate_here);
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CurContext->addDecl(VDPrivate);
|
2015-05-08 18:41:21 +08:00
|
|
|
auto VDPrivateRefExpr = buildDeclRefExpr(
|
|
|
|
*this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc());
|
2013-10-01 13:32:34 +08:00
|
|
|
DSAStack->addDSA(VD, DE, OMPC_firstprivate);
|
|
|
|
Vars.push_back(DE);
|
2014-10-08 22:01:46 +08:00
|
|
|
PrivateCopies.push_back(VDPrivateRefExpr);
|
|
|
|
Inits.push_back(VDInitRefExpr);
|
2013-10-01 13:32:34 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
2013-10-01 13:32:34 +08:00
|
|
|
|
|
|
|
return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc,
|
2014-10-08 22:01:46 +08:00
|
|
|
Vars, PrivateCopies, Inits);
|
2014-06-04 21:06:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
2015-04-16 12:54:05 +08:00
|
|
|
SmallVector<Expr *, 8> SrcExprs;
|
|
|
|
SmallVector<Expr *, 8> DstExprs;
|
|
|
|
SmallVector<Expr *, 8> AssignmentOps;
|
2014-06-04 21:06:39 +08:00
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP lastprivate clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(RefExpr);
|
2015-04-16 12:54:05 +08:00
|
|
|
SrcExprs.push_back(nullptr);
|
|
|
|
DstExprs.push_back(nullptr);
|
|
|
|
AssignmentOps.push_back(nullptr);
|
2014-06-04 21:06:39 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation ELoc = RefExpr->getExprLoc();
|
|
|
|
// OpenMP [2.1, C/C++]
|
|
|
|
// A list item is a variable name.
|
|
|
|
// OpenMP [2.14.3.5, Restrictions, p.1]
|
|
|
|
// A variable that is part of another variable (as an array or structure
|
|
|
|
// element) cannot appear in a lastprivate clause.
|
|
|
|
DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr);
|
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->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);
|
2015-04-16 12:54:05 +08:00
|
|
|
SrcExprs.push_back(nullptr);
|
|
|
|
DstExprs.push_back(nullptr);
|
|
|
|
AssignmentOps.push_back(nullptr);
|
2014-06-04 21:06:39 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.14.3.5, Restrictions, C/C++, p.2]
|
|
|
|
// A variable that appears in a lastprivate clause must not have an
|
|
|
|
// incomplete type or a reference type.
|
|
|
|
if (RequireCompleteType(ELoc, Type,
|
|
|
|
diag::err_omp_lastprivate_incomplete_type)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-18 14:47:21 +08:00
|
|
|
Type = Type.getNonReferenceType();
|
2014-06-04 21:06:39 +08:00
|
|
|
|
|
|
|
// OpenMP [2.14.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.
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false);
|
2014-06-04 21:06:39 +08:00
|
|
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate &&
|
|
|
|
DVar.CKind != OMPC_firstprivate &&
|
|
|
|
(DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_lastprivate);
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
2014-06-04 21:06:39 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-18 12:14:57 +08:00
|
|
|
OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective();
|
|
|
|
// OpenMP [2.14.3.5, Restrictions, p.2]
|
|
|
|
// A list item that is private within a parallel region, or that appears in
|
|
|
|
// the reduction clause of a parallel construct, must not appear in a
|
|
|
|
// lastprivate clause on a worksharing construct if any of the corresponding
|
|
|
|
// worksharing regions ever binds to any of the corresponding parallel
|
|
|
|
// regions.
|
2015-05-08 18:41:21 +08:00
|
|
|
DSAStackTy::DSAVarData TopDVar = DVar;
|
2014-06-24 12:39:47 +08:00
|
|
|
if (isOpenMPWorksharingDirective(CurrDir) &&
|
|
|
|
!isOpenMPParallelDirective(CurrDir)) {
|
2014-07-11 19:25:16 +08:00
|
|
|
DVar = DSAStack->getImplicitDSA(VD, true);
|
2014-06-18 12:14:57 +08:00
|
|
|
if (DVar.CKind != OMPC_shared) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_access)
|
|
|
|
<< getOpenMPClauseName(OMPC_lastprivate)
|
|
|
|
<< getOpenMPClauseName(OMPC_shared);
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
2014-06-18 12:14:57 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-06-04 21:06:39 +08:00
|
|
|
// OpenMP [2.14.3.5, Restrictions, C++, p.1,2]
|
2014-06-18 12:14:57 +08:00
|
|
|
// A variable of class type (or array thereof) that appears in a
|
|
|
|
// lastprivate clause requires an accessible, unambiguous default
|
|
|
|
// constructor for the class type, unless the list item is also specified
|
|
|
|
// in a firstprivate clause.
|
2014-06-04 21:06:39 +08:00
|
|
|
// A variable of class type (or array thereof) that appears in a
|
|
|
|
// lastprivate clause requires an accessible, unambiguous copy assignment
|
|
|
|
// operator for the class type.
|
2015-04-16 12:54:05 +08:00
|
|
|
Type = Context.getBaseElementType(Type).getNonReferenceType();
|
2015-05-08 18:41:21 +08:00
|
|
|
auto *SrcVD = buildVarDecl(*this, DE->getLocStart(),
|
2015-09-10 17:48:30 +08:00
|
|
|
Type.getUnqualifiedType(), ".lastprivate.src",
|
|
|
|
VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-05-08 18:41:21 +08:00
|
|
|
auto *PseudoSrcExpr = buildDeclRefExpr(
|
|
|
|
*this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc());
|
2015-04-16 12:54:05 +08:00
|
|
|
auto *DstVD =
|
2015-09-10 17:48:30 +08:00
|
|
|
buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst",
|
|
|
|
VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-04-16 12:54:05 +08:00
|
|
|
auto *PseudoDstExpr =
|
2015-05-08 18:41:21 +08:00
|
|
|
buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc());
|
2015-04-16 12:54:05 +08:00
|
|
|
// For arrays generate assignment operation for single element and replace
|
|
|
|
// it by the original array element in CodeGen.
|
|
|
|
auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign,
|
|
|
|
PseudoDstExpr, PseudoSrcExpr);
|
|
|
|
if (AssignmentOp.isInvalid())
|
|
|
|
continue;
|
|
|
|
AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(),
|
|
|
|
/*DiscardedValue=*/true);
|
|
|
|
if (AssignmentOp.isInvalid())
|
|
|
|
continue;
|
2014-06-04 21:06:39 +08:00
|
|
|
|
2015-05-08 18:41:21 +08:00
|
|
|
if (TopDVar.CKind != OMPC_firstprivate)
|
2014-06-18 12:14:57 +08:00
|
|
|
DSAStack->addDSA(VD, DE, OMPC_lastprivate);
|
2014-06-04 21:06:39 +08:00
|
|
|
Vars.push_back(DE);
|
2015-04-16 12:54:05 +08:00
|
|
|
SrcExprs.push_back(PseudoSrcExpr);
|
|
|
|
DstExprs.push_back(PseudoDstExpr);
|
|
|
|
AssignmentOps.push_back(AssignmentOp.get());
|
2014-06-04 21:06:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc,
|
2015-04-16 12:54:05 +08:00
|
|
|
Vars, SrcExprs, DstExprs, AssignmentOps);
|
2013-10-01 13:32:34 +08:00
|
|
|
}
|
|
|
|
|
2013-09-07 02:03:48 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
2014-05-28 13:53:51 +08:00
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP shared clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
2013-09-07 02:03:48 +08:00
|
|
|
// It will be analyzed later.
|
2014-05-28 13:53:51 +08:00
|
|
|
Vars.push_back(RefExpr);
|
2013-09-07 02:03:48 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
SourceLocation ELoc = RefExpr->getExprLoc();
|
2013-09-07 02:03:48 +08:00
|
|
|
// 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.
|
2014-05-28 13:53:51 +08:00
|
|
|
DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr);
|
2013-09-07 02:03:48 +08:00
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
2014-05-28 13:53:51 +08:00
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange();
|
2013-09-07 02:03:48 +08:00
|
|
|
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.
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false);
|
2014-05-28 13:53:51 +08:00
|
|
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared &&
|
|
|
|
DVar.RefExpr) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_shared);
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
2013-09-07 02:03:48 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DSAStack->addDSA(VD, DE, OMPC_shared);
|
|
|
|
Vars.push_back(DE);
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
2013-09-07 02:03:48 +08:00
|
|
|
|
|
|
|
return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars);
|
|
|
|
}
|
|
|
|
|
2014-06-16 15:08:35 +08:00
|
|
|
namespace {
|
|
|
|
class DSARefChecker : public StmtVisitor<DSARefChecker, bool> {
|
|
|
|
DSAStackTy *Stack;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool VisitDeclRefExpr(DeclRefExpr *E) {
|
|
|
|
if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) {
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false);
|
2014-06-16 15:08:35 +08:00
|
|
|
if (DVar.CKind == OMPC_shared && !DVar.RefExpr)
|
|
|
|
return false;
|
|
|
|
if (DVar.CKind != OMPC_unknown)
|
|
|
|
return true;
|
2014-06-18 12:14:57 +08:00
|
|
|
DSAStackTy::DSAVarData DVarPrivate =
|
2014-07-11 19:25:16 +08:00
|
|
|
Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false);
|
2014-06-18 12:14:57 +08:00
|
|
|
if (DVarPrivate.CKind != OMPC_unknown)
|
2014-06-16 15:08:35 +08:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool VisitStmt(Stmt *S) {
|
|
|
|
for (auto Child : S->children()) {
|
|
|
|
if (Child && Visit(Child))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-18 15:08:49 +08:00
|
|
|
explicit DSARefChecker(DSAStackTy *S) : Stack(S) {}
|
2014-06-16 15:08:35 +08:00
|
|
|
};
|
2014-06-18 15:08:49 +08:00
|
|
|
} // namespace
|
2014-06-16 15:08:35 +08:00
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPReductionClause(
|
|
|
|
ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc,
|
|
|
|
SourceLocation ColonLoc, SourceLocation EndLoc,
|
|
|
|
CXXScopeSpec &ReductionIdScopeSpec,
|
|
|
|
const DeclarationNameInfo &ReductionId) {
|
|
|
|
// TODO: Allow scope specification search when 'declare reduction' is
|
|
|
|
// supported.
|
|
|
|
assert(ReductionIdScopeSpec.isEmpty() &&
|
|
|
|
"No support for scoped reduction identifiers yet.");
|
|
|
|
|
|
|
|
auto DN = ReductionId.getName();
|
|
|
|
auto OOK = DN.getCXXOverloadedOperator();
|
|
|
|
BinaryOperatorKind BOK = BO_Comma;
|
|
|
|
|
|
|
|
// OpenMP [2.14.3.6, reduction clause]
|
|
|
|
// C
|
|
|
|
// reduction-identifier is either an identifier or one of the following
|
|
|
|
// operators: +, -, *, &, |, ^, && and ||
|
|
|
|
// C++
|
|
|
|
// reduction-identifier is either an id-expression or one of the following
|
|
|
|
// operators: +, -, *, &, |, ^, && and ||
|
|
|
|
// FIXME: Only 'min' and 'max' identifiers are supported for now.
|
|
|
|
switch (OOK) {
|
|
|
|
case OO_Plus:
|
|
|
|
case OO_Minus:
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
BOK = BO_Add;
|
2014-06-16 15:08:35 +08:00
|
|
|
break;
|
|
|
|
case OO_Star:
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
BOK = BO_Mul;
|
2014-06-16 15:08:35 +08:00
|
|
|
break;
|
|
|
|
case OO_Amp:
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
BOK = BO_And;
|
2014-06-16 15:08:35 +08:00
|
|
|
break;
|
|
|
|
case OO_Pipe:
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
BOK = BO_Or;
|
2014-06-16 15:08:35 +08:00
|
|
|
break;
|
|
|
|
case OO_Caret:
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
BOK = BO_Xor;
|
2014-06-16 15:08:35 +08:00
|
|
|
break;
|
|
|
|
case OO_AmpAmp:
|
|
|
|
BOK = BO_LAnd;
|
|
|
|
break;
|
|
|
|
case OO_PipePipe:
|
|
|
|
BOK = BO_LOr;
|
|
|
|
break;
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
case OO_New:
|
|
|
|
case OO_Delete:
|
|
|
|
case OO_Array_New:
|
|
|
|
case OO_Array_Delete:
|
|
|
|
case OO_Slash:
|
|
|
|
case OO_Percent:
|
|
|
|
case OO_Tilde:
|
|
|
|
case OO_Exclaim:
|
|
|
|
case OO_Equal:
|
|
|
|
case OO_Less:
|
|
|
|
case OO_Greater:
|
|
|
|
case OO_LessEqual:
|
|
|
|
case OO_GreaterEqual:
|
|
|
|
case OO_PlusEqual:
|
|
|
|
case OO_MinusEqual:
|
|
|
|
case OO_StarEqual:
|
|
|
|
case OO_SlashEqual:
|
|
|
|
case OO_PercentEqual:
|
|
|
|
case OO_CaretEqual:
|
|
|
|
case OO_AmpEqual:
|
|
|
|
case OO_PipeEqual:
|
|
|
|
case OO_LessLess:
|
|
|
|
case OO_GreaterGreater:
|
|
|
|
case OO_LessLessEqual:
|
|
|
|
case OO_GreaterGreaterEqual:
|
|
|
|
case OO_EqualEqual:
|
|
|
|
case OO_ExclaimEqual:
|
|
|
|
case OO_PlusPlus:
|
|
|
|
case OO_MinusMinus:
|
|
|
|
case OO_Comma:
|
|
|
|
case OO_ArrowStar:
|
|
|
|
case OO_Arrow:
|
|
|
|
case OO_Call:
|
|
|
|
case OO_Subscript:
|
|
|
|
case OO_Conditional:
|
|
|
|
case NUM_OVERLOADED_OPERATORS:
|
|
|
|
llvm_unreachable("Unexpected reduction identifier");
|
|
|
|
case OO_None:
|
2014-06-16 15:08:35 +08:00
|
|
|
if (auto II = DN.getAsIdentifierInfo()) {
|
|
|
|
if (II->isStr("max"))
|
|
|
|
BOK = BO_GT;
|
|
|
|
else if (II->isStr("min"))
|
|
|
|
BOK = BO_LT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SourceRange ReductionIdRange;
|
|
|
|
if (ReductionIdScopeSpec.isValid()) {
|
|
|
|
ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc());
|
|
|
|
}
|
|
|
|
ReductionIdRange.setEnd(ReductionId.getEndLoc());
|
|
|
|
if (BOK == BO_Comma) {
|
|
|
|
// Not allowed reduction identifier is found.
|
|
|
|
Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier)
|
|
|
|
<< ReductionIdRange;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
SmallVector<Expr *, 8> LHSs;
|
|
|
|
SmallVector<Expr *, 8> RHSs;
|
|
|
|
SmallVector<Expr *, 8> ReductionOps;
|
2014-06-16 15:08:35 +08:00
|
|
|
for (auto RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "nullptr expr in OpenMP reduction clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(RefExpr);
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
LHSs.push_back(nullptr);
|
|
|
|
RHSs.push_back(nullptr);
|
|
|
|
ReductionOps.push_back(nullptr);
|
2014-06-16 15:08:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() ||
|
|
|
|
RefExpr->isInstantiationDependent() ||
|
|
|
|
RefExpr->containsUnexpandedParameterPack()) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(RefExpr);
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
LHSs.push_back(nullptr);
|
|
|
|
RHSs.push_back(nullptr);
|
|
|
|
ReductionOps.push_back(nullptr);
|
2014-06-16 15:08:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ELoc = RefExpr->getExprLoc();
|
|
|
|
auto ERange = RefExpr->getSourceRange();
|
|
|
|
// OpenMP [2.1, C/C++]
|
|
|
|
// A list item is a variable or array section, subject to the restrictions
|
|
|
|
// specified in Section 2.4 on page 42 and in each of the sections
|
|
|
|
// describing clauses and directives for which a list appears.
|
|
|
|
// OpenMP [2.14.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.
|
2015-09-30 17:22:36 +08:00
|
|
|
auto *DE = dyn_cast<DeclRefExpr>(RefExpr);
|
|
|
|
auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr);
|
|
|
|
auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr);
|
|
|
|
if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) {
|
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange;
|
2014-06-16 15:08:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
2015-09-30 17:22:36 +08:00
|
|
|
QualType Type;
|
|
|
|
VarDecl *VD = nullptr;
|
|
|
|
if (DE) {
|
|
|
|
auto D = DE->getDecl();
|
|
|
|
VD = cast<VarDecl>(D);
|
|
|
|
Type = VD->getType();
|
|
|
|
} else if (ASE)
|
|
|
|
Type = ASE->getType();
|
|
|
|
else if (OASE) {
|
|
|
|
auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase());
|
|
|
|
if (auto *ATy = BaseType->getAsArrayTypeUnsafe())
|
|
|
|
Type = ATy->getElementType();
|
|
|
|
else
|
|
|
|
Type = BaseType->getPointeeType();
|
|
|
|
}
|
|
|
|
// OpenMP [2.15.3.6, reduction Clause]
|
|
|
|
// If a list item is an array section, its lower-bound must be zero.
|
|
|
|
llvm::APSInt Result;
|
|
|
|
if (OASE && OASE->getLowerBound() &&
|
|
|
|
OASE->getLowerBound()->EvaluateAsInt(Result, Context) && Result != 0) {
|
|
|
|
Diag(OASE->getLowerBound()->getExprLoc(),
|
|
|
|
diag::err_omp_expected_array_sect_reduction_lb_not_zero)
|
|
|
|
<< OASE->getLowerBound()->getSourceRange();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-16 15:08:35 +08:00
|
|
|
// 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_reduction_incomplete_type))
|
|
|
|
continue;
|
|
|
|
// OpenMP [2.14.3.6, reduction clause, Restrictions]
|
|
|
|
// Arrays may not appear in a reduction clause.
|
|
|
|
if (Type.getNonReferenceType()->isArrayType()) {
|
|
|
|
Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange;
|
2015-09-30 17:22:36 +08:00
|
|
|
if (VD) {
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
}
|
2014-06-16 15:08:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// OpenMP [2.14.3.6, reduction clause, Restrictions]
|
|
|
|
// A list item that appears in a reduction clause must not be
|
|
|
|
// const-qualified.
|
|
|
|
if (Type.getNonReferenceType().isConstant(Context)) {
|
2015-09-30 17:22:36 +08:00
|
|
|
Diag(ELoc, diag::err_omp_const_reduction_list_item)
|
2014-06-16 15:08:35 +08:00
|
|
|
<< getOpenMPClauseName(OMPC_reduction) << Type << ERange;
|
2015-09-30 17:22:36 +08:00
|
|
|
if (VD) {
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
}
|
2014-06-16 15:08:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// OpenMP [2.9.3.6, Restrictions, C/C++, p.4]
|
|
|
|
// If a list-item is a reference type then it must bind to the same object
|
|
|
|
// for all threads of the team.
|
2015-09-30 17:22:36 +08:00
|
|
|
if (VD) {
|
|
|
|
VarDecl *VDDef = VD->getDefinition();
|
|
|
|
if (Type->isReferenceType() && VDDef) {
|
|
|
|
DSARefChecker Check(DSAStack);
|
|
|
|
if (Check.Visit(VDDef->getInit())) {
|
|
|
|
Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange;
|
|
|
|
Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef;
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// OpenMP [2.14.3.6, reduction clause, Restrictions]
|
|
|
|
// The type of a list item that appears in a reduction clause must be valid
|
|
|
|
// for the reduction-identifier. For a max or min reduction in C, the type
|
|
|
|
// of the list item must be an allowed arithmetic data type: char, int,
|
|
|
|
// float, double, or _Bool, possibly modified with long, short, signed, or
|
|
|
|
// unsigned. For a max or min reduction in C++, the type of the list item
|
|
|
|
// must be an allowed arithmetic data type: char, wchar_t, int, float,
|
|
|
|
// double, or bool, possibly modified with long, short, signed, or unsigned.
|
|
|
|
if ((BOK == BO_GT || BOK == BO_LT) &&
|
|
|
|
!(Type->isScalarType() ||
|
|
|
|
(getLangOpts().CPlusPlus && Type->isArithmeticType()))) {
|
|
|
|
Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg)
|
|
|
|
<< getLangOpts().CPlusPlus;
|
2015-09-30 17:22:36 +08:00
|
|
|
if (VD) {
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
}
|
2014-06-16 15:08:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) &&
|
|
|
|
!getLangOpts().CPlusPlus && Type->isFloatingType()) {
|
|
|
|
Diag(ELoc, diag::err_omp_clause_floating_type_arg);
|
2015-09-30 17:22:36 +08:00
|
|
|
if (VD) {
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
}
|
2014-06-16 15:08:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// OpenMP [2.14.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.14.3.6, Restrictions, p.3]
|
|
|
|
// Any number of reduction clauses can be specified on the directive,
|
|
|
|
// but a list item can appear only once in the reduction clauses for that
|
|
|
|
// directive.
|
2015-09-30 17:22:36 +08:00
|
|
|
DSAStackTy::DSAVarData DVar;
|
|
|
|
if (VD) {
|
|
|
|
DVar = DSAStack->getTopDSA(VD, false);
|
|
|
|
if (DVar.CKind == OMPC_reduction) {
|
|
|
|
Diag(ELoc, diag::err_omp_once_referenced)
|
|
|
|
<< getOpenMPClauseName(OMPC_reduction);
|
|
|
|
if (DVar.RefExpr) {
|
|
|
|
Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced);
|
|
|
|
}
|
|
|
|
} else if (DVar.CKind != OMPC_unknown) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_reduction);
|
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
|
|
|
continue;
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.14.3.6, Restrictions, p.1]
|
|
|
|
// A list item that appears in a reduction clause of a worksharing
|
|
|
|
// construct must be shared in the parallel regions to which any of the
|
|
|
|
// worksharing regions arising from the worksharing construct bind.
|
2015-09-30 17:22:36 +08:00
|
|
|
if (VD) {
|
|
|
|
OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective();
|
|
|
|
if (isOpenMPWorksharingDirective(CurrDir) &&
|
|
|
|
!isOpenMPParallelDirective(CurrDir)) {
|
|
|
|
DVar = DSAStack->getImplicitDSA(VD, true);
|
|
|
|
if (DVar.CKind != OMPC_shared) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_access)
|
|
|
|
<< getOpenMPClauseName(OMPC_reduction)
|
|
|
|
<< getOpenMPClauseName(OMPC_shared);
|
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
|
|
|
continue;
|
|
|
|
}
|
2014-06-18 12:14:57 +08:00
|
|
|
}
|
|
|
|
}
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
Type = Type.getNonLValueExprType(Context).getUnqualifiedType();
|
2015-09-30 17:22:36 +08:00
|
|
|
auto *LHSVD =
|
|
|
|
buildVarDecl(*this, ELoc, Type, ".reduction.lhs",
|
|
|
|
VD && VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
|
|
|
auto *RHSVD =
|
|
|
|
buildVarDecl(*this, ELoc, Type, VD ? VD->getName() : ".item.",
|
|
|
|
VD && VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
// Add initializer for private variable.
|
|
|
|
Expr *Init = nullptr;
|
|
|
|
switch (BOK) {
|
|
|
|
case BO_Add:
|
|
|
|
case BO_Xor:
|
|
|
|
case BO_Or:
|
|
|
|
case BO_LOr:
|
|
|
|
// '+', '-', '^', '|', '||' reduction ops - initializer is '0'.
|
|
|
|
if (Type->isScalarType() || Type->isAnyComplexType()) {
|
|
|
|
Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get();
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
break;
|
|
|
|
case BO_Mul:
|
|
|
|
case BO_LAnd:
|
|
|
|
if (Type->isScalarType() || Type->isAnyComplexType()) {
|
|
|
|
// '*' and '&&' reduction ops - initializer is '1'.
|
|
|
|
Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BO_And: {
|
|
|
|
// '&' reduction op - initializer is '~0'.
|
|
|
|
QualType OrigType = Type;
|
|
|
|
if (auto *ComplexTy = OrigType->getAs<ComplexType>()) {
|
|
|
|
Type = ComplexTy->getElementType();
|
|
|
|
}
|
|
|
|
if (Type->isRealFloatingType()) {
|
|
|
|
llvm::APFloat InitValue =
|
|
|
|
llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type),
|
|
|
|
/*isIEEE=*/true);
|
|
|
|
Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true,
|
|
|
|
Type, ELoc);
|
|
|
|
} else if (Type->isScalarType()) {
|
|
|
|
auto Size = Context.getTypeSize(Type);
|
|
|
|
QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0);
|
|
|
|
llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size);
|
|
|
|
Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc);
|
|
|
|
}
|
|
|
|
if (Init && OrigType->isAnyComplexType()) {
|
|
|
|
// Init = 0xFFFF + 0xFFFFi;
|
|
|
|
auto *Im = new (Context) ImaginaryLiteral(Init, OrigType);
|
|
|
|
Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get();
|
|
|
|
}
|
|
|
|
Type = OrigType;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BO_LT:
|
|
|
|
case BO_GT: {
|
|
|
|
// 'min' reduction op - initializer is 'Largest representable number in
|
|
|
|
// the reduction list item type'.
|
|
|
|
// 'max' reduction op - initializer is 'Least representable number in
|
|
|
|
// the reduction list item type'.
|
|
|
|
if (Type->isIntegerType() || Type->isPointerType()) {
|
|
|
|
bool IsSigned = Type->hasSignedIntegerRepresentation();
|
|
|
|
auto Size = Context.getTypeSize(Type);
|
|
|
|
QualType IntTy =
|
|
|
|
Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned);
|
|
|
|
llvm::APInt InitValue =
|
|
|
|
(BOK != BO_LT)
|
|
|
|
? IsSigned ? llvm::APInt::getSignedMinValue(Size)
|
|
|
|
: llvm::APInt::getMinValue(Size)
|
|
|
|
: IsSigned ? llvm::APInt::getSignedMaxValue(Size)
|
|
|
|
: llvm::APInt::getMaxValue(Size);
|
|
|
|
Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc);
|
|
|
|
if (Type->isPointerType()) {
|
|
|
|
// Cast to pointer type.
|
|
|
|
auto CastExpr = BuildCStyleCastExpr(
|
|
|
|
SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc),
|
|
|
|
SourceLocation(), Init);
|
|
|
|
if (CastExpr.isInvalid())
|
|
|
|
continue;
|
|
|
|
Init = CastExpr.get();
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
} else if (Type->isRealFloatingType()) {
|
|
|
|
llvm::APFloat InitValue = llvm::APFloat::getLargest(
|
|
|
|
Context.getFloatTypeSemantics(Type), BOK != BO_LT);
|
|
|
|
Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true,
|
|
|
|
Type, ELoc);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case BO_PtrMemD:
|
|
|
|
case BO_PtrMemI:
|
|
|
|
case BO_MulAssign:
|
|
|
|
case BO_Div:
|
|
|
|
case BO_Rem:
|
|
|
|
case BO_Sub:
|
|
|
|
case BO_Shl:
|
|
|
|
case BO_Shr:
|
|
|
|
case BO_LE:
|
|
|
|
case BO_GE:
|
|
|
|
case BO_EQ:
|
|
|
|
case BO_NE:
|
|
|
|
case BO_AndAssign:
|
|
|
|
case BO_XorAssign:
|
|
|
|
case BO_OrAssign:
|
|
|
|
case BO_Assign:
|
|
|
|
case BO_AddAssign:
|
|
|
|
case BO_SubAssign:
|
|
|
|
case BO_DivAssign:
|
|
|
|
case BO_RemAssign:
|
|
|
|
case BO_ShlAssign:
|
|
|
|
case BO_ShrAssign:
|
|
|
|
case BO_Comma:
|
|
|
|
llvm_unreachable("Unexpected reduction operation");
|
|
|
|
}
|
|
|
|
if (Init) {
|
|
|
|
AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false,
|
|
|
|
/*TypeMayContainAuto=*/false);
|
|
|
|
} else {
|
|
|
|
ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false);
|
|
|
|
}
|
|
|
|
if (!RHSVD->hasInit()) {
|
|
|
|
Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type
|
|
|
|
<< ReductionIdRange;
|
2015-09-30 17:22:36 +08:00
|
|
|
if (VD) {
|
|
|
|
bool IsDecl = VD->isThisDeclarationADefinition(Context) ==
|
|
|
|
VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
}
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
continue;
|
|
|
|
}
|
2015-05-08 18:41:21 +08:00
|
|
|
auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc);
|
|
|
|
auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc);
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
ExprResult ReductionOp =
|
|
|
|
BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK,
|
|
|
|
LHSDRE, RHSDRE);
|
|
|
|
if (ReductionOp.isUsable()) {
|
2015-05-07 11:54:03 +08:00
|
|
|
if (BOK != BO_LT && BOK != BO_GT) {
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
ReductionOp =
|
|
|
|
BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(),
|
|
|
|
BO_Assign, LHSDRE, ReductionOp.get());
|
|
|
|
} else {
|
|
|
|
auto *ConditionalOp = new (Context) ConditionalOperator(
|
|
|
|
ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(),
|
|
|
|
RHSDRE, Type, VK_LValue, OK_Ordinary);
|
|
|
|
ReductionOp =
|
|
|
|
BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(),
|
|
|
|
BO_Assign, LHSDRE, ConditionalOp);
|
|
|
|
}
|
2015-09-03 15:23:48 +08:00
|
|
|
ReductionOp = ActOnFinishFullExpr(ReductionOp.get());
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
if (ReductionOp.isInvalid())
|
|
|
|
continue;
|
2014-06-16 15:08:35 +08:00
|
|
|
|
2015-09-30 17:22:36 +08:00
|
|
|
if (VD)
|
|
|
|
DSAStack->addDSA(VD, DE, OMPC_reduction);
|
|
|
|
Vars.push_back(RefExpr);
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
LHSs.push_back(LHSDRE);
|
|
|
|
RHSs.push_back(RHSDRE);
|
|
|
|
ReductionOps.push_back(ReductionOp.get());
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return OMPReductionClause::Create(
|
|
|
|
Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars,
|
[OPENMP] Codegen for 'reduction' clause in 'parallel' directive.
Emit a code for reduction clause. Next code should be emitted for reductions:
static kmp_critical_name lock = { 0 };
void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
...
*(Type<i> *)lhs[i] = RedOp<i>(*(Type<i> *)lhs[i], *(Type<i> *)rhs[i]);
...
}
... void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n> - 1]};
switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
case 1:
...
<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]);
...
__kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
break;
case 2:
...
Atomic(<LHSExprs>[i] = RedOp<i>(*<LHSExprs>[i], *<RHSExprs>[i]));
...
break;
default:
;
}
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.
Differential Revision: http://reviews.llvm.org/D8915
llvm-svn: 234583
2015-04-10 18:43:45 +08:00
|
|
|
ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, LHSs,
|
|
|
|
RHSs, ReductionOps);
|
2014-06-16 15:08:35 +08:00
|
|
|
}
|
|
|
|
|
2015-08-20 18:54:39 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPLinearClause(
|
|
|
|
ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind,
|
|
|
|
SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) {
|
2014-04-22 21:09:42 +08:00
|
|
|
SmallVector<Expr *, 8> Vars;
|
2015-08-18 14:47:21 +08:00
|
|
|
SmallVector<Expr *, 8> Privates;
|
2015-03-21 18:12:56 +08:00
|
|
|
SmallVector<Expr *, 8> Inits;
|
2015-08-20 18:54:39 +08:00
|
|
|
if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) ||
|
|
|
|
LinKind == OMPC_LINEAR_unknown) {
|
|
|
|
Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus;
|
|
|
|
LinKind = OMPC_LINEAR_val;
|
|
|
|
}
|
2014-05-28 13:53:51 +08:00
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP linear clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
2014-04-22 21:09:42 +08:00
|
|
|
// It will be analyzed later.
|
2014-05-28 13:53:51 +08:00
|
|
|
Vars.push_back(RefExpr);
|
2015-08-18 14:47:21 +08:00
|
|
|
Privates.push_back(nullptr);
|
2015-03-21 18:12:56 +08:00
|
|
|
Inits.push_back(nullptr);
|
2014-04-22 21:09:42 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.14.3.7, linear clause]
|
|
|
|
// A list item that appears in a linear clause is subject to the private
|
|
|
|
// clause semantics described in Section 2.14.3.3 on page 159 except as
|
|
|
|
// noted. In addition, the value of the new list item on each iteration
|
|
|
|
// of the associated loop(s) corresponds to the value of the original
|
|
|
|
// list item before entering the construct plus the logical number of
|
|
|
|
// the iteration times linear-step.
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
SourceLocation ELoc = RefExpr->getExprLoc();
|
2014-04-22 21:09:42 +08:00
|
|
|
// OpenMP [2.1, C/C++]
|
|
|
|
// A list item is a variable name.
|
|
|
|
// OpenMP [2.14.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.
|
2014-05-28 13:53:51 +08:00
|
|
|
DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr);
|
2014-04-22 21:09:42 +08:00
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
2014-05-28 13:53:51 +08:00
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange();
|
2014-04-22 21:09:42 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *VD = cast<VarDecl>(DE->getDecl());
|
|
|
|
|
|
|
|
// OpenMP [2.14.3.7, linear clause]
|
|
|
|
// A list-item cannot appear in more than one linear clause.
|
|
|
|
// A list-item that appears in a linear clause cannot appear in any
|
|
|
|
// other data-sharing attribute clause.
|
2014-07-11 19:25:16 +08:00
|
|
|
DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false);
|
2014-04-22 21:09:42 +08:00
|
|
|
if (DVar.RefExpr) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_linear);
|
2014-06-19 17:13:45 +08:00
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
2014-04-22 21:09:42 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
QualType QType = VD->getType();
|
|
|
|
if (QType->isDependentType() || QType->isInstantiationDependentType()) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(DE);
|
2015-08-18 14:47:21 +08:00
|
|
|
Privates.push_back(nullptr);
|
2015-03-21 18:12:56 +08:00
|
|
|
Inits.push_back(nullptr);
|
2014-04-22 21:09:42 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A variable must not have an incomplete type or a reference type.
|
|
|
|
if (RequireCompleteType(ELoc, QType,
|
|
|
|
diag::err_omp_linear_incomplete_type)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-20 20:15:57 +08:00
|
|
|
if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) &&
|
|
|
|
!QType->isReferenceType()) {
|
|
|
|
Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference)
|
|
|
|
<< QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind);
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-18 14:47:21 +08:00
|
|
|
QType = QType.getNonReferenceType();
|
2014-04-22 21:09:42 +08:00
|
|
|
|
|
|
|
// A list item must not be const-qualified.
|
|
|
|
if (QType.isConstant(Context)) {
|
|
|
|
Diag(ELoc, diag::err_omp_const_variable)
|
|
|
|
<< getOpenMPClauseName(OMPC_linear);
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A list item must be of integral or pointer type.
|
|
|
|
QType = QType.getUnqualifiedType().getCanonicalType();
|
|
|
|
const Type *Ty = QType.getTypePtrOrNull();
|
|
|
|
if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) &&
|
|
|
|
!Ty->isPointerType())) {
|
|
|
|
Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType;
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-18 14:47:21 +08:00
|
|
|
// Build private copy of original var.
|
2015-09-10 17:48:30 +08:00
|
|
|
auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(),
|
|
|
|
VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-08-18 14:47:21 +08:00
|
|
|
auto *PrivateRef = buildDeclRefExpr(
|
|
|
|
*this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc());
|
2015-03-21 18:12:56 +08:00
|
|
|
// Build var to save initial value.
|
2015-05-19 15:46:42 +08:00
|
|
|
VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start");
|
2015-08-21 14:41:23 +08:00
|
|
|
Expr *InitExpr;
|
|
|
|
if (LinKind == OMPC_LINEAR_uval)
|
|
|
|
InitExpr = VD->getInit();
|
|
|
|
else
|
|
|
|
InitExpr = DE;
|
|
|
|
AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(),
|
2015-03-21 18:12:56 +08:00
|
|
|
/*DirectInit*/ false, /*TypeMayContainAuto*/ false);
|
2015-05-19 15:46:42 +08:00
|
|
|
auto InitRef = buildDeclRefExpr(
|
|
|
|
*this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc());
|
2014-04-22 21:09:42 +08:00
|
|
|
DSAStack->addDSA(VD, DE, OMPC_linear);
|
|
|
|
Vars.push_back(DE);
|
2015-08-18 14:47:21 +08:00
|
|
|
Privates.push_back(PrivateRef);
|
2015-03-21 18:12:56 +08:00
|
|
|
Inits.push_back(InitRef);
|
2014-04-22 21:09:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty())
|
2014-05-15 21:04:49 +08:00
|
|
|
return nullptr;
|
2014-04-22 21:09:42 +08:00
|
|
|
|
|
|
|
Expr *StepExpr = Step;
|
2015-03-21 18:12:56 +08:00
|
|
|
Expr *CalcStepExpr = nullptr;
|
2014-04-22 21:09:42 +08:00
|
|
|
if (Step && !Step->isValueDependent() && !Step->isTypeDependent() &&
|
|
|
|
!Step->isInstantiationDependent() &&
|
|
|
|
!Step->containsUnexpandedParameterPack()) {
|
|
|
|
SourceLocation StepLoc = Step->getLocStart();
|
2014-06-03 18:16:47 +08:00
|
|
|
ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step);
|
2014-04-22 21:09:42 +08:00
|
|
|
if (Val.isInvalid())
|
2014-05-15 21:04:49 +08:00
|
|
|
return nullptr;
|
2014-05-29 18:55:11 +08:00
|
|
|
StepExpr = Val.get();
|
2014-04-22 21:09:42 +08:00
|
|
|
|
2015-03-21 18:12:56 +08:00
|
|
|
// Build var to save the step value.
|
|
|
|
VarDecl *SaveVar =
|
2015-05-08 18:41:21 +08:00
|
|
|
buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step");
|
2015-03-21 18:12:56 +08:00
|
|
|
ExprResult SaveRef =
|
2015-05-08 18:41:21 +08:00
|
|
|
buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc);
|
2015-03-21 18:12:56 +08:00
|
|
|
ExprResult CalcStep =
|
|
|
|
BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr);
|
2015-09-03 15:23:48 +08:00
|
|
|
CalcStep = ActOnFinishFullExpr(CalcStep.get());
|
2015-03-21 18:12:56 +08:00
|
|
|
|
2014-04-22 21:09:42 +08:00
|
|
|
// Warn about zero linear step (it would be probably better specified as
|
|
|
|
// making corresponding variables 'const').
|
|
|
|
llvm::APSInt Result;
|
2015-03-21 18:12:56 +08:00
|
|
|
bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context);
|
|
|
|
if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive())
|
2014-04-22 21:09:42 +08:00
|
|
|
Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0]
|
|
|
|
<< (Vars.size() > 1);
|
2015-03-21 18:12:56 +08:00
|
|
|
if (!IsConstant && CalcStep.isUsable()) {
|
|
|
|
// Calculate the step beforehand instead of doing this on each iteration.
|
|
|
|
// (This is not used if the number of iterations may be kfold-ed).
|
|
|
|
CalcStepExpr = CalcStep.get();
|
|
|
|
}
|
2014-04-22 21:09:42 +08:00
|
|
|
}
|
|
|
|
|
2015-08-20 18:54:39 +08:00
|
|
|
return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc,
|
|
|
|
ColonLoc, EndLoc, Vars, Privates, Inits,
|
|
|
|
StepExpr, CalcStepExpr);
|
2015-03-21 18:12:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV,
|
|
|
|
Expr *NumIterations, Sema &SemaRef,
|
|
|
|
Scope *S) {
|
|
|
|
// Walk the vars and build update/final expressions for the CodeGen.
|
|
|
|
SmallVector<Expr *, 8> Updates;
|
|
|
|
SmallVector<Expr *, 8> Finals;
|
|
|
|
Expr *Step = Clause.getStep();
|
|
|
|
Expr *CalcStep = Clause.getCalcStep();
|
|
|
|
// OpenMP [2.14.3.7, linear clause]
|
|
|
|
// If linear-step is not specified it is assumed to be 1.
|
|
|
|
if (Step == nullptr)
|
|
|
|
Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get();
|
|
|
|
else if (CalcStep)
|
|
|
|
Step = cast<BinaryOperator>(CalcStep)->getLHS();
|
|
|
|
bool HasErrors = false;
|
|
|
|
auto CurInit = Clause.inits().begin();
|
2015-08-18 14:47:21 +08:00
|
|
|
auto CurPrivate = Clause.privates().begin();
|
2015-08-21 14:41:23 +08:00
|
|
|
auto LinKind = Clause.getModifier();
|
2015-03-21 18:12:56 +08:00
|
|
|
for (auto &RefExpr : Clause.varlists()) {
|
|
|
|
Expr *InitExpr = *CurInit;
|
|
|
|
|
|
|
|
// Build privatized reference to the current linear var.
|
|
|
|
auto DE = cast<DeclRefExpr>(RefExpr);
|
2015-08-21 14:41:23 +08:00
|
|
|
Expr *CapturedRef;
|
|
|
|
if (LinKind == OMPC_LINEAR_uval)
|
|
|
|
CapturedRef = cast<VarDecl>(DE->getDecl())->getInit();
|
|
|
|
else
|
|
|
|
CapturedRef =
|
|
|
|
buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()),
|
|
|
|
DE->getType().getUnqualifiedType(), DE->getExprLoc(),
|
|
|
|
/*RefersToCapture=*/true);
|
2015-03-21 18:12:56 +08:00
|
|
|
|
|
|
|
// Build update: Var = InitExpr + IV * Step
|
|
|
|
ExprResult Update =
|
2015-08-18 14:47:21 +08:00
|
|
|
BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate,
|
2015-03-21 18:12:56 +08:00
|
|
|
InitExpr, IV, Step, /* Subtract */ false);
|
2015-09-03 15:23:48 +08:00
|
|
|
Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(),
|
|
|
|
/*DiscardedValue=*/true);
|
2015-03-21 18:12:56 +08:00
|
|
|
|
|
|
|
// Build final: Var = InitExpr + NumIterations * Step
|
|
|
|
ExprResult Final =
|
2015-08-18 14:47:21 +08:00
|
|
|
BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef,
|
2015-05-08 18:41:21 +08:00
|
|
|
InitExpr, NumIterations, Step, /* Subtract */ false);
|
2015-09-03 15:23:48 +08:00
|
|
|
Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(),
|
|
|
|
/*DiscardedValue=*/true);
|
2015-03-21 18:12:56 +08:00
|
|
|
if (!Update.isUsable() || !Final.isUsable()) {
|
|
|
|
Updates.push_back(nullptr);
|
|
|
|
Finals.push_back(nullptr);
|
|
|
|
HasErrors = true;
|
|
|
|
} else {
|
|
|
|
Updates.push_back(Update.get());
|
|
|
|
Finals.push_back(Final.get());
|
|
|
|
}
|
2015-08-18 14:47:21 +08:00
|
|
|
++CurInit, ++CurPrivate;
|
2015-03-21 18:12:56 +08:00
|
|
|
}
|
|
|
|
Clause.setUpdates(Updates);
|
|
|
|
Clause.setFinals(Finals);
|
|
|
|
return HasErrors;
|
2014-04-22 21:09:42 +08:00
|
|
|
}
|
|
|
|
|
2014-05-29 22:36:25 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPAlignedClause(
|
|
|
|
ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) {
|
|
|
|
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP aligned clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
|
|
|
// 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) << RefExpr->getSourceRange();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
VarDecl *VD = cast<VarDecl>(DE->getDecl());
|
|
|
|
|
|
|
|
// 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.
|
2015-05-19 15:46:42 +08:00
|
|
|
QualType QType = VD->getType();
|
|
|
|
QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType();
|
2014-05-29 22:36:25 +08:00
|
|
|
const Type *Ty = QType.getTypePtrOrNull();
|
|
|
|
if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() &&
|
|
|
|
!Ty->isPointerType())) {
|
|
|
|
Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr)
|
|
|
|
<< QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange();
|
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.8.1, simd construct, Restrictions]
|
|
|
|
// A list-item cannot appear in more than one aligned clause.
|
|
|
|
if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) {
|
|
|
|
Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange();
|
|
|
|
Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa)
|
|
|
|
<< getOpenMPClauseName(OMPC_aligned);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vars.push_back(DE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.8.1, simd construct, Description]
|
|
|
|
// The parameter of the aligned clause, alignment, must be a constant
|
|
|
|
// positive integer expression.
|
|
|
|
// If no optional parameter is specified, implementation-defined default
|
|
|
|
// alignments for SIMD instructions on the target platforms are assumed.
|
|
|
|
if (Alignment != nullptr) {
|
|
|
|
ExprResult AlignResult =
|
|
|
|
VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned);
|
|
|
|
if (AlignResult.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
Alignment = AlignResult.get();
|
|
|
|
}
|
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc,
|
|
|
|
EndLoc, Vars, Alignment);
|
|
|
|
}
|
|
|
|
|
2014-03-31 11:36:38 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
2015-04-16 13:39:01 +08:00
|
|
|
SmallVector<Expr *, 8> SrcExprs;
|
|
|
|
SmallVector<Expr *, 8> DstExprs;
|
|
|
|
SmallVector<Expr *, 8> AssignmentOps;
|
2014-05-28 13:53:51 +08:00
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP copyin clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
2014-03-31 11:36:38 +08:00
|
|
|
// It will be analyzed later.
|
2014-05-28 13:53:51 +08:00
|
|
|
Vars.push_back(RefExpr);
|
2015-04-16 13:39:01 +08:00
|
|
|
SrcExprs.push_back(nullptr);
|
|
|
|
DstExprs.push_back(nullptr);
|
|
|
|
AssignmentOps.push_back(nullptr);
|
2014-03-31 11:36:38 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
SourceLocation ELoc = RefExpr->getExprLoc();
|
2014-03-31 11:36:38 +08:00
|
|
|
// 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.
|
2014-05-28 13:53:51 +08:00
|
|
|
DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr);
|
2014-03-31 11:36:38 +08:00
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
2014-05-28 13:53:51 +08:00
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange();
|
2014-03-31 11:36:38 +08:00
|
|
|
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);
|
2015-04-16 13:39:01 +08:00
|
|
|
SrcExprs.push_back(nullptr);
|
|
|
|
DstExprs.push_back(nullptr);
|
|
|
|
AssignmentOps.push_back(nullptr);
|
2014-03-31 11:36:38 +08:00
|
|
|
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)
|
2014-05-28 13:53:51 +08:00
|
|
|
<< getOpenMPClauseName(OMPC_copyin)
|
|
|
|
<< getOpenMPDirectiveName(OMPD_threadprivate);
|
2014-03-31 11:36:38 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.14.4.1, Restrictions, C/C++, p.2]
|
|
|
|
// A variable of class type (or array thereof) that appears in a
|
2014-06-18 15:08:49 +08:00
|
|
|
// copyin clause requires an accessible, unambiguous copy assignment
|
2014-03-31 11:36:38 +08:00
|
|
|
// operator for the class type.
|
2015-05-19 15:46:42 +08:00
|
|
|
auto ElemType = Context.getBaseElementType(Type).getNonReferenceType();
|
2015-09-10 17:48:30 +08:00
|
|
|
auto *SrcVD =
|
|
|
|
buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(),
|
|
|
|
".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-05-08 18:41:21 +08:00
|
|
|
auto *PseudoSrcExpr = buildDeclRefExpr(
|
2015-05-19 15:46:42 +08:00
|
|
|
*this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc());
|
|
|
|
auto *DstVD =
|
2015-09-10 17:48:30 +08:00
|
|
|
buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst",
|
|
|
|
VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-04-16 13:39:01 +08:00
|
|
|
auto *PseudoDstExpr =
|
2015-05-19 15:46:42 +08:00
|
|
|
buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc());
|
2015-04-16 13:39:01 +08:00
|
|
|
// For arrays generate assignment operation for single element and replace
|
|
|
|
// it by the original array element in CodeGen.
|
|
|
|
auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign,
|
|
|
|
PseudoDstExpr, PseudoSrcExpr);
|
|
|
|
if (AssignmentOp.isInvalid())
|
|
|
|
continue;
|
|
|
|
AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(),
|
|
|
|
/*DiscardedValue=*/true);
|
|
|
|
if (AssignmentOp.isInvalid())
|
|
|
|
continue;
|
2014-03-31 11:36:38 +08:00
|
|
|
|
|
|
|
DSAStack->addDSA(VD, DE, OMPC_copyin);
|
|
|
|
Vars.push_back(DE);
|
2015-04-16 13:39:01 +08:00
|
|
|
SrcExprs.push_back(PseudoSrcExpr);
|
|
|
|
DstExprs.push_back(PseudoDstExpr);
|
|
|
|
AssignmentOps.push_back(AssignmentOp.get());
|
2014-03-31 11:36:38 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 13:53:51 +08:00
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
2014-03-31 11:36:38 +08:00
|
|
|
|
2015-04-16 13:39:01 +08:00
|
|
|
return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars,
|
|
|
|
SrcExprs, DstExprs, AssignmentOps);
|
2014-03-31 11:36:38 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 18:37:06 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
2015-03-23 14:18:07 +08:00
|
|
|
SmallVector<Expr *, 8> SrcExprs;
|
|
|
|
SmallVector<Expr *, 8> DstExprs;
|
|
|
|
SmallVector<Expr *, 8> AssignmentOps;
|
2014-06-27 18:37:06 +08:00
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP copyprivate clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(RefExpr);
|
2015-03-23 14:18:07 +08:00
|
|
|
SrcExprs.push_back(nullptr);
|
|
|
|
DstExprs.push_back(nullptr);
|
|
|
|
AssignmentOps.push_back(nullptr);
|
2014-06-27 18:37:06 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation ELoc = RefExpr->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>(RefExpr);
|
|
|
|
if (!DE || !isa<VarDecl>(DE->getDecl())) {
|
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->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);
|
2015-03-23 14:18:07 +08:00
|
|
|
SrcExprs.push_back(nullptr);
|
|
|
|
DstExprs.push_back(nullptr);
|
|
|
|
AssignmentOps.push_back(nullptr);
|
2014-06-27 18:37:06 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.14.4.2, Restrictions, p.2]
|
|
|
|
// A list item that appears in a copyprivate clause may not appear in a
|
|
|
|
// private or firstprivate clause on the single construct.
|
|
|
|
if (!DSAStack->isThreadPrivate(VD)) {
|
2014-07-11 19:25:16 +08:00
|
|
|
auto DVar = DSAStack->getTopDSA(VD, false);
|
2015-03-23 14:18:07 +08:00
|
|
|
if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate &&
|
|
|
|
DVar.RefExpr) {
|
2014-06-27 18:37:06 +08:00
|
|
|
Diag(ELoc, diag::err_omp_wrong_dsa)
|
|
|
|
<< getOpenMPClauseName(DVar.CKind)
|
|
|
|
<< getOpenMPClauseName(OMPC_copyprivate);
|
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpenMP [2.11.4.2, Restrictions, p.1]
|
|
|
|
// All list items that appear in a copyprivate clause must be either
|
|
|
|
// threadprivate or private in the enclosing context.
|
|
|
|
if (DVar.CKind == OMPC_unknown) {
|
2014-07-11 19:25:16 +08:00
|
|
|
DVar = DSAStack->getImplicitDSA(VD, false);
|
2014-06-27 18:37:06 +08:00
|
|
|
if (DVar.CKind == OMPC_shared) {
|
|
|
|
Diag(ELoc, diag::err_omp_required_access)
|
|
|
|
<< getOpenMPClauseName(OMPC_copyprivate)
|
|
|
|
<< "threadprivate or private in the enclosing context";
|
|
|
|
ReportOriginalDSA(*this, DSAStack, VD, DVar);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 16:19:24 +08:00
|
|
|
// Variably modified types are not supported.
|
2015-05-21 17:47:46 +08:00
|
|
|
if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) {
|
2015-05-19 16:19:24 +08:00
|
|
|
Diag(ELoc, diag::err_omp_variably_modified_type_not_supported)
|
2015-05-19 16:44:56 +08:00
|
|
|
<< getOpenMPClauseName(OMPC_copyprivate) << Type
|
|
|
|
<< getOpenMPDirectiveName(DSAStack->getCurrentDirective());
|
2015-05-19 16:19:24 +08:00
|
|
|
bool IsDecl =
|
|
|
|
VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly;
|
|
|
|
Diag(VD->getLocation(),
|
|
|
|
IsDecl ? diag::note_previous_decl : diag::note_defined_here)
|
|
|
|
<< VD;
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-19 16:44:56 +08:00
|
|
|
|
2014-06-27 18:37:06 +08:00
|
|
|
// 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 accessible, unambiguous copy assignment
|
|
|
|
// operator for the class type.
|
2015-08-18 14:47:21 +08:00
|
|
|
Type = Context.getBaseElementType(Type.getNonReferenceType())
|
|
|
|
.getUnqualifiedType();
|
2015-04-14 13:11:24 +08:00
|
|
|
auto *SrcVD =
|
2015-09-10 17:48:30 +08:00
|
|
|
buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src",
|
|
|
|
VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-04-14 13:11:24 +08:00
|
|
|
auto *PseudoSrcExpr =
|
2015-05-08 18:41:21 +08:00
|
|
|
buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc());
|
2015-04-14 13:11:24 +08:00
|
|
|
auto *DstVD =
|
2015-09-10 17:48:30 +08:00
|
|
|
buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst",
|
|
|
|
VD->hasAttrs() ? &VD->getAttrs() : nullptr);
|
2015-04-14 13:11:24 +08:00
|
|
|
auto *PseudoDstExpr =
|
2015-05-08 18:41:21 +08:00
|
|
|
buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc());
|
2015-03-23 14:18:07 +08:00
|
|
|
auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign,
|
|
|
|
PseudoDstExpr, PseudoSrcExpr);
|
|
|
|
if (AssignmentOp.isInvalid())
|
|
|
|
continue;
|
|
|
|
AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(),
|
|
|
|
/*DiscardedValue=*/true);
|
|
|
|
if (AssignmentOp.isInvalid())
|
|
|
|
continue;
|
2014-06-27 18:37:06 +08:00
|
|
|
|
|
|
|
// No need to mark vars as copyprivate, they are already threadprivate or
|
|
|
|
// implicitly private.
|
|
|
|
Vars.push_back(DE);
|
2015-03-23 14:18:07 +08:00
|
|
|
SrcExprs.push_back(PseudoSrcExpr);
|
|
|
|
DstExprs.push_back(PseudoDstExpr);
|
|
|
|
AssignmentOps.push_back(AssignmentOp.get());
|
2014-06-27 18:37:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
2015-03-23 14:18:07 +08:00
|
|
|
return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc,
|
|
|
|
Vars, SrcExprs, DstExprs, AssignmentOps);
|
2014-06-27 18:37:06 +08:00
|
|
|
}
|
|
|
|
|
2014-07-21 19:26:11 +08:00
|
|
|
OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList,
|
|
|
|
SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
if (VarList.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList);
|
|
|
|
}
|
2014-07-23 15:46:59 +08:00
|
|
|
|
2015-06-23 22:25:19 +08:00
|
|
|
OMPClause *
|
|
|
|
Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind,
|
|
|
|
SourceLocation DepLoc, SourceLocation ColonLoc,
|
|
|
|
ArrayRef<Expr *> VarList, SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc, SourceLocation EndLoc) {
|
|
|
|
if (DepKind == OMPC_DEPEND_unknown) {
|
|
|
|
std::string Values;
|
|
|
|
std::string Sep(", ");
|
|
|
|
for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) {
|
|
|
|
Values += "'";
|
|
|
|
Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i);
|
|
|
|
Values += "'";
|
|
|
|
switch (i) {
|
|
|
|
case OMPC_DEPEND_unknown - 2:
|
|
|
|
Values += " or ";
|
|
|
|
break;
|
|
|
|
case OMPC_DEPEND_unknown - 1:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Values += Sep;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Diag(DepLoc, diag::err_omp_unexpected_clause_value)
|
|
|
|
<< Values << getOpenMPClauseName(OMPC_depend);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SmallVector<Expr *, 8> Vars;
|
|
|
|
for (auto &RefExpr : VarList) {
|
|
|
|
assert(RefExpr && "NULL expr in OpenMP shared clause.");
|
|
|
|
if (isa<DependentScopeDeclRefExpr>(RefExpr)) {
|
|
|
|
// It will be analyzed later.
|
|
|
|
Vars.push_back(RefExpr);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SourceLocation ELoc = RefExpr->getExprLoc();
|
|
|
|
// OpenMP [2.11.1.1, Restrictions, p.3]
|
|
|
|
// A variable that is part of another variable (such as a field of a
|
|
|
|
// structure) but is not an array element or an array section cannot appear
|
|
|
|
// in a depend clause.
|
|
|
|
auto *SimpleExpr = RefExpr->IgnoreParenCasts();
|
2015-08-25 22:24:04 +08:00
|
|
|
auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr);
|
|
|
|
auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr);
|
|
|
|
auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr);
|
|
|
|
if (!RefExpr->IgnoreParenImpCasts()->isLValue() ||
|
|
|
|
(!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) ||
|
2015-06-23 22:25:19 +08:00
|
|
|
(ASE && !ASE->getBase()->getType()->isAnyPointerType() &&
|
|
|
|
!ASE->getBase()->getType()->isArrayType())) {
|
|
|
|
Diag(ELoc, diag::err_omp_expected_var_name_or_array_item)
|
|
|
|
<< RefExpr->getSourceRange();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vars.push_back(RefExpr->IgnoreParenImpCasts());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Vars.empty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind,
|
|
|
|
DepLoc, ColonLoc, Vars);
|
|
|
|
}
|
2015-08-08 00:16:36 +08:00
|
|
|
|
|
|
|
OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc,
|
|
|
|
SourceLocation LParenLoc,
|
|
|
|
SourceLocation EndLoc) {
|
|
|
|
Expr *ValExpr = Device;
|
|
|
|
if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() &&
|
|
|
|
!ValExpr->isInstantiationDependent()) {
|
|
|
|
SourceLocation Loc = ValExpr->getExprLoc();
|
|
|
|
ExprResult Value = PerformOpenMPImplicitIntegerConversion(Loc, ValExpr);
|
|
|
|
if (Value.isInvalid())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
// OpenMP [2.9.1, Restrictions]
|
|
|
|
// The device expression must evaluate to a non-negative integer value.
|
|
|
|
llvm::APSInt Result;
|
|
|
|
if (Value.get()->isIntegerConstantExpr(Result, Context) &&
|
|
|
|
Result.isSigned() && !Result.isStrictlyPositive()) {
|
|
|
|
Diag(Loc, diag::err_omp_negative_expression_in_clause)
|
|
|
|
<< "device" << ValExpr->getSourceRange();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc);
|
|
|
|
}
|