Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 17 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 20 | #include "clang/AST/StmtCXX.h" |
| 21 | #include "clang/AST/StmtOpenMP.h" |
| 22 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 23 | #include "clang/Basic/OpenMPKinds.h" |
| 24 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 25 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 26 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Scope.h" |
| 28 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 29 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 30 | using namespace clang; |
| 31 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 32 | //===----------------------------------------------------------------------===// |
| 33 | // Stack of data-sharing attributes for variables |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | |
| 36 | namespace { |
| 37 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 38 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 39 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 40 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 41 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 42 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 43 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 44 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 45 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 46 | bool operator()(T Kind) { |
| 47 | for (auto KindEl : Arr) |
| 48 | if (KindEl == Kind) |
| 49 | return true; |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | ArrayRef<T> Arr; |
| 55 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 56 | struct MatchesAlways { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 57 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 58 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 62 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 63 | |
| 64 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 65 | /// clauses and their data-sharing attributes. |
| 66 | class DSAStackTy { |
| 67 | public: |
| 68 | struct DSAVarData { |
| 69 | OpenMPDirectiveKind DKind; |
| 70 | OpenMPClauseKind CKind; |
| 71 | DeclRefExpr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 72 | SourceLocation ImplicitDSALoc; |
| 73 | DSAVarData() |
| 74 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 75 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 76 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 77 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 78 | private: |
| 79 | struct DSAInfo { |
| 80 | OpenMPClauseKind Attributes; |
| 81 | DeclRefExpr *RefExpr; |
| 82 | }; |
| 83 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 84 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 85 | |
| 86 | struct SharingMapTy { |
| 87 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 88 | AlignedMapTy AlignedMap; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 89 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 90 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 91 | OpenMPDirectiveKind Directive; |
| 92 | DeclarationNameInfo DirectiveName; |
| 93 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 94 | SourceLocation ConstructLoc; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 95 | bool OrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 96 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 97 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 98 | Scope *CurScope, SourceLocation Loc) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 99 | : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 100 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 101 | ConstructLoc(Loc), OrderedRegion(false), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 102 | SharingMapTy() |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 103 | : SharingMap(), AlignedMap(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 104 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 105 | ConstructLoc(), OrderedRegion(false), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 109 | |
| 110 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 111 | StackTy Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 112 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 113 | |
| 114 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 115 | |
| 116 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 117 | |
| 118 | /// \brief Checks if the variable is a local for OpenMP region. |
| 119 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 120 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 121 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 122 | explicit DSAStackTy(Sema &S) : Stack(1), SemaRef(S) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 123 | |
| 124 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 125 | Scope *CurScope, SourceLocation Loc) { |
| 126 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 127 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void pop() { |
| 131 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 132 | Stack.pop_back(); |
| 133 | } |
| 134 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 135 | /// \brief If 'aligned' declaration for given variable \a D was not seen yet, |
Alp Toker | 15e62a3 | 2014-06-06 12:02:07 +0000 | [diff] [blame] | 136 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 137 | /// for diagnostics. |
| 138 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 139 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 140 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 141 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 142 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 143 | /// \brief Returns data sharing attributes from top of the stack for the |
| 144 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 145 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 146 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 147 | DSAVarData getImplicitDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 148 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 149 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 150 | /// predicate. |
| 151 | template <class ClausesPredicate, class DirectivesPredicate> |
| 152 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 153 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 154 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 155 | /// match specified \a CPred predicate in any innermost directive which |
| 156 | /// matches \a DPred predicate. |
| 157 | template <class ClausesPredicate, class DirectivesPredicate> |
| 158 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 159 | DirectivesPredicate DPred, |
| 160 | bool FromParent); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 161 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 162 | template <class NamedDirectivesPredicate> |
| 163 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 164 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 165 | /// \brief Returns currently analyzed directive. |
| 166 | OpenMPDirectiveKind getCurrentDirective() const { |
| 167 | return Stack.back().Directive; |
| 168 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 169 | /// \brief Returns parent directive. |
| 170 | OpenMPDirectiveKind getParentDirective() const { |
| 171 | if (Stack.size() > 2) |
| 172 | return Stack[Stack.size() - 2].Directive; |
| 173 | return OMPD_unknown; |
| 174 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 175 | |
| 176 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 177 | void setDefaultDSANone(SourceLocation Loc) { |
| 178 | Stack.back().DefaultAttr = DSA_none; |
| 179 | Stack.back().DefaultAttrLoc = Loc; |
| 180 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 181 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 182 | void setDefaultDSAShared(SourceLocation Loc) { |
| 183 | Stack.back().DefaultAttr = DSA_shared; |
| 184 | Stack.back().DefaultAttrLoc = Loc; |
| 185 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 186 | |
| 187 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 188 | return Stack.back().DefaultAttr; |
| 189 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 190 | SourceLocation getDefaultDSALocation() const { |
| 191 | return Stack.back().DefaultAttrLoc; |
| 192 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 193 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 194 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 195 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 196 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 197 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 200 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
| 201 | void setOrderedRegion(bool IsOrdered = true) { |
| 202 | Stack.back().OrderedRegion = IsOrdered; |
| 203 | } |
| 204 | /// \brief Returns true, if parent region is ordered (has associated |
| 205 | /// 'ordered' clause), false - otherwise. |
| 206 | bool isParentOrderedRegion() const { |
| 207 | if (Stack.size() > 2) |
| 208 | return Stack[Stack.size() - 2].OrderedRegion; |
| 209 | return false; |
| 210 | } |
| 211 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 212 | /// \brief Marks current target region as one with closely nested teams |
| 213 | /// region. |
| 214 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 215 | if (Stack.size() > 2) |
| 216 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 217 | } |
| 218 | /// \brief Returns true, if current region has closely nested teams region. |
| 219 | bool hasInnerTeamsRegion() const { |
| 220 | return getInnerTeamsRegionLoc().isValid(); |
| 221 | } |
| 222 | /// \brief Returns location of the nested teams region (if any). |
| 223 | SourceLocation getInnerTeamsRegionLoc() const { |
| 224 | if (Stack.size() > 1) |
| 225 | return Stack.back().InnerTeamsRegionLoc; |
| 226 | return SourceLocation(); |
| 227 | } |
| 228 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 229 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 230 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 231 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 232 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 233 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 234 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 235 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 236 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 237 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 238 | |
| 239 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 240 | VarDecl *D) { |
| 241 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 242 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 243 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 244 | // in a region but not in construct] |
| 245 | // File-scope or namespace-scope variables referenced in called routines |
| 246 | // in the region are shared unless they appear in a threadprivate |
| 247 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 248 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 249 | DVar.CKind = OMPC_shared; |
| 250 | |
| 251 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 252 | // in a region but not in construct] |
| 253 | // Variables with static storage duration that are declared in called |
| 254 | // routines in the region are shared. |
| 255 | if (D->hasGlobalStorage()) |
| 256 | DVar.CKind = OMPC_shared; |
| 257 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 258 | return DVar; |
| 259 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 260 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 261 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 262 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 263 | // in a Construct, C/C++, predetermined, p.1] |
| 264 | // Variables with automatic storage duration that are declared in a scope |
| 265 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 266 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 267 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 268 | DVar.CKind = OMPC_private; |
| 269 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 272 | // Explicitly specified attributes and local variables with predetermined |
| 273 | // attributes. |
| 274 | if (Iter->SharingMap.count(D)) { |
| 275 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 276 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 277 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 278 | return DVar; |
| 279 | } |
| 280 | |
| 281 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 282 | // in a Construct, C/C++, implicitly determined, p.1] |
| 283 | // In a parallel or task construct, the data-sharing attributes of these |
| 284 | // variables are determined by the default clause, if present. |
| 285 | switch (Iter->DefaultAttr) { |
| 286 | case DSA_shared: |
| 287 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 288 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 289 | return DVar; |
| 290 | case DSA_none: |
| 291 | return DVar; |
| 292 | case DSA_unspecified: |
| 293 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 294 | // in a Construct, implicitly determined, p.2] |
| 295 | // In a parallel construct, if no default clause is present, these |
| 296 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 297 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 298 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 299 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 300 | DVar.CKind = OMPC_shared; |
| 301 | return DVar; |
| 302 | } |
| 303 | |
| 304 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 305 | // in a Construct, implicitly determined, p.4] |
| 306 | // In a task construct, if no default clause is present, a variable that in |
| 307 | // the enclosing context is determined to be shared by all implicit tasks |
| 308 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 309 | if (DVar.DKind == OMPD_task) { |
| 310 | DSAVarData DVarTemp; |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 311 | for (StackTy::reverse_iterator I = std::next(Iter), |
| 312 | EE = std::prev(Stack.rend()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 313 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 314 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 315 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 316 | // in a Construct, implicitly determined, p.6] |
| 317 | // In a task construct, if no default clause is present, a variable |
| 318 | // whose data-sharing attribute is not determined by the rules above is |
| 319 | // firstprivate. |
| 320 | DVarTemp = getDSA(I, D); |
| 321 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 322 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 323 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 324 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 325 | return DVar; |
| 326 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 327 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 328 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 329 | } |
| 330 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 331 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 332 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 333 | return DVar; |
| 334 | } |
| 335 | } |
| 336 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 337 | // in a Construct, implicitly determined, p.3] |
| 338 | // For constructs other than task, if no default clause is present, these |
| 339 | // variables inherit their data-sharing attributes from the enclosing |
| 340 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 341 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 344 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 345 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
| 346 | auto It = Stack.back().AlignedMap.find(D); |
| 347 | if (It == Stack.back().AlignedMap.end()) { |
| 348 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 349 | Stack.back().AlignedMap[D] = NewDE; |
| 350 | return nullptr; |
| 351 | } else { |
| 352 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 353 | return It->second; |
| 354 | } |
| 355 | return nullptr; |
| 356 | } |
| 357 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 358 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
| 359 | if (A == OMPC_threadprivate) { |
| 360 | Stack[0].SharingMap[D].Attributes = A; |
| 361 | Stack[0].SharingMap[D].RefExpr = E; |
| 362 | } else { |
| 363 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 364 | Stack.back().SharingMap[D].Attributes = A; |
| 365 | Stack.back().SharingMap[D].RefExpr = E; |
| 366 | } |
| 367 | } |
| 368 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 369 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 370 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 371 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 372 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 373 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 374 | ++I; |
| 375 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 376 | if (I == E) |
| 377 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 378 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 379 | Scope *CurScope = getCurScope(); |
| 380 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 381 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 382 | } |
| 383 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 384 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 385 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 388 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 389 | DSAVarData DVar; |
| 390 | |
| 391 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 392 | // in a Construct, C/C++, predetermined, p.1] |
| 393 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 394 | if (D->getTLSKind() != VarDecl::TLS_None || |
| 395 | D->getStorageClass() == SC_Register) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 396 | DVar.CKind = OMPC_threadprivate; |
| 397 | return DVar; |
| 398 | } |
| 399 | if (Stack[0].SharingMap.count(D)) { |
| 400 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 401 | DVar.CKind = OMPC_threadprivate; |
| 402 | return DVar; |
| 403 | } |
| 404 | |
| 405 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 406 | // in a Construct, C/C++, predetermined, p.1] |
| 407 | // Variables with automatic storage duration that are declared in a scope |
| 408 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 409 | OpenMPDirectiveKind Kind = |
| 410 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 411 | auto StartI = std::next(Stack.rbegin()); |
| 412 | auto EndI = std::prev(Stack.rend()); |
| 413 | if (FromParent && StartI != EndI) { |
| 414 | StartI = std::next(StartI); |
| 415 | } |
| 416 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 417 | if (isOpenMPLocal(D, StartI) && |
| 418 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 419 | D->getStorageClass() == SC_None)) || |
| 420 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 421 | DVar.CKind = OMPC_private; |
| 422 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 423 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 424 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame^] | 425 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 426 | // in a Construct, C/C++, predetermined, p.4] |
| 427 | // Static data members are shared. |
| 428 | if (D->isStaticDataMember()) { |
| 429 | DVar.CKind = OMPC_shared; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 430 | return DVar; |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame^] | 431 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 432 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame^] | 433 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 434 | // in a Construct, C/C++, predetermined, p.7] |
| 435 | // Variables with static storage duration that are declared in a scope |
| 436 | // inside the construct are shared. |
| 437 | if (D->isStaticLocal()) { |
| 438 | DVar.CKind = OMPC_shared; |
| 439 | return DVar; |
| 440 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 444 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | while (Type->isArrayType()) { |
| 446 | QualType ElemType = cast<ArrayType>(Type.getTypePtr())->getElementType(); |
| 447 | Type = ElemType.getNonReferenceType().getCanonicalType(); |
| 448 | } |
| 449 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 450 | // in a Construct, C/C++, predetermined, p.6] |
| 451 | // Variables with const qualified type having no mutable member are |
| 452 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 453 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 454 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 455 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 456 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 457 | // Variables with const-qualified type having no mutable member may be |
| 458 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 459 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 460 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 461 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 462 | return DVar; |
| 463 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 464 | DVar.CKind = OMPC_shared; |
| 465 | return DVar; |
| 466 | } |
| 467 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 468 | // Explicitly specified attributes and local variables with predetermined |
| 469 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 470 | auto I = std::prev(StartI); |
| 471 | if (I->SharingMap.count(D)) { |
| 472 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 473 | DVar.CKind = I->SharingMap[D].Attributes; |
| 474 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | return DVar; |
| 478 | } |
| 479 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 480 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
| 481 | auto StartI = Stack.rbegin(); |
| 482 | auto EndI = std::prev(Stack.rend()); |
| 483 | if (FromParent && StartI != EndI) { |
| 484 | StartI = std::next(StartI); |
| 485 | } |
| 486 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 487 | } |
| 488 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 489 | template <class ClausesPredicate, class DirectivesPredicate> |
| 490 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 491 | DirectivesPredicate DPred, |
| 492 | bool FromParent) { |
| 493 | auto StartI = std::next(Stack.rbegin()); |
| 494 | auto EndI = std::prev(Stack.rend()); |
| 495 | if (FromParent && StartI != EndI) { |
| 496 | StartI = std::next(StartI); |
| 497 | } |
| 498 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 499 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 500 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 501 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 502 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 503 | return DVar; |
| 504 | } |
| 505 | return DSAVarData(); |
| 506 | } |
| 507 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 508 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 509 | DSAStackTy::DSAVarData |
| 510 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 511 | DirectivesPredicate DPred, bool FromParent) { |
| 512 | auto StartI = std::next(Stack.rbegin()); |
| 513 | auto EndI = std::prev(Stack.rend()); |
| 514 | if (FromParent && StartI != EndI) { |
| 515 | StartI = std::next(StartI); |
| 516 | } |
| 517 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 518 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 519 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 520 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 521 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 522 | return DVar; |
| 523 | return DSAVarData(); |
| 524 | } |
| 525 | return DSAVarData(); |
| 526 | } |
| 527 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 528 | template <class NamedDirectivesPredicate> |
| 529 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 530 | auto StartI = std::next(Stack.rbegin()); |
| 531 | auto EndI = std::prev(Stack.rend()); |
| 532 | if (FromParent && StartI != EndI) { |
| 533 | StartI = std::next(StartI); |
| 534 | } |
| 535 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 536 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 537 | return true; |
| 538 | } |
| 539 | return false; |
| 540 | } |
| 541 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 542 | void Sema::InitDataSharingAttributesStack() { |
| 543 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 544 | } |
| 545 | |
| 546 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 547 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 548 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 549 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 550 | if (DSAStack->getCurrentDirective() != OMPD_unknown) { |
| 551 | auto DVarPrivate = DSAStack->getTopDSA(VD, /*FromParent=*/false); |
| 552 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 553 | return true; |
| 554 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
| 555 | /*FromParent=*/false); |
| 556 | return DVarPrivate.CKind != OMPC_unknown; |
| 557 | } |
| 558 | return false; |
| 559 | } |
| 560 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 561 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 562 | |
| 563 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 564 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 565 | Scope *CurScope, SourceLocation Loc) { |
| 566 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 567 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 568 | } |
| 569 | |
| 570 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 571 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 572 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 573 | // clause requires an accessible, unambiguous default constructor for the |
| 574 | // class type, unless the list item is also specified in a firstprivate |
| 575 | // clause. |
| 576 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
| 577 | for (auto C : D->clauses()) { |
| 578 | if (auto Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 579 | for (auto VarRef : Clause->varlists()) { |
| 580 | if (VarRef->isValueDependent() || VarRef->isTypeDependent()) |
| 581 | continue; |
| 582 | auto VD = cast<VarDecl>(cast<DeclRefExpr>(VarRef)->getDecl()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 583 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 584 | if (DVar.CKind == OMPC_lastprivate) { |
| 585 | SourceLocation ELoc = VarRef->getExprLoc(); |
| 586 | auto Type = VarRef->getType(); |
| 587 | if (Type->isArrayType()) |
| 588 | Type = QualType(Type->getArrayElementTypeNoTypeQual(), 0); |
| 589 | CXXRecordDecl *RD = |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 590 | getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
| 591 | // FIXME This code must be replaced by actual constructing of the |
| 592 | // lastprivate variable. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 593 | if (RD) { |
| 594 | CXXConstructorDecl *CD = LookupDefaultConstructor(RD); |
| 595 | PartialDiagnostic PD = |
| 596 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
| 597 | if (!CD || |
| 598 | CheckConstructorAccess( |
| 599 | ELoc, CD, InitializedEntity::InitializeTemporary(Type), |
| 600 | CD->getAccess(), PD) == AR_inaccessible || |
| 601 | CD->isDeleted()) { |
| 602 | Diag(ELoc, diag::err_omp_required_method) |
| 603 | << getOpenMPClauseName(OMPC_lastprivate) << 0; |
| 604 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 605 | VarDecl::DeclarationOnly; |
| 606 | Diag(VD->getLocation(), IsDecl ? diag::note_previous_decl |
| 607 | : diag::note_defined_here) |
| 608 | << VD; |
| 609 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 610 | continue; |
| 611 | } |
| 612 | MarkFunctionReferenced(ELoc, CD); |
| 613 | DiagnoseUseOfDecl(CD, ELoc); |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 621 | DSAStack->pop(); |
| 622 | DiscardCleanupsInEvaluationContext(); |
| 623 | PopExpressionEvaluationContext(); |
| 624 | } |
| 625 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 626 | namespace { |
| 627 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 628 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 629 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 630 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 631 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 632 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 633 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 634 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 635 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 636 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 637 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 638 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 639 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 640 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 641 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 642 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 643 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 644 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 645 | |
| 646 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 647 | CXXScopeSpec &ScopeSpec, |
| 648 | const DeclarationNameInfo &Id) { |
| 649 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 650 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 651 | |
| 652 | if (Lookup.isAmbiguous()) |
| 653 | return ExprError(); |
| 654 | |
| 655 | VarDecl *VD; |
| 656 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 657 | if (TypoCorrection Corrected = CorrectTypo( |
| 658 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 659 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 660 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 661 | PDiag(Lookup.empty() |
| 662 | ? diag::err_undeclared_var_use_suggest |
| 663 | : diag::err_omp_expected_var_arg_suggest) |
| 664 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 665 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 666 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 667 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 668 | : diag::err_omp_expected_var_arg) |
| 669 | << Id.getName(); |
| 670 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 671 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 672 | } else { |
| 673 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 674 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 675 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 676 | return ExprError(); |
| 677 | } |
| 678 | } |
| 679 | Lookup.suppressDiagnostics(); |
| 680 | |
| 681 | // OpenMP [2.9.2, Syntax, C/C++] |
| 682 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 683 | if (!VD->hasGlobalStorage()) { |
| 684 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 685 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 686 | bool IsDecl = |
| 687 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 688 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 689 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 690 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 691 | return ExprError(); |
| 692 | } |
| 693 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 694 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 695 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 696 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 697 | // A threadprivate directive for file-scope variables must appear outside |
| 698 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 699 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 700 | !getCurLexicalContext()->isTranslationUnit()) { |
| 701 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 702 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 703 | bool IsDecl = |
| 704 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 705 | Diag(VD->getLocation(), |
| 706 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 707 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 708 | return ExprError(); |
| 709 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 710 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 711 | // A threadprivate directive for static class member variables must appear |
| 712 | // in the class definition, in the same scope in which the member |
| 713 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 714 | if (CanonicalVD->isStaticDataMember() && |
| 715 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 716 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 717 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 718 | bool IsDecl = |
| 719 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 720 | Diag(VD->getLocation(), |
| 721 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 722 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 723 | return ExprError(); |
| 724 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 725 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 726 | // A threadprivate directive for namespace-scope variables must appear |
| 727 | // outside any definition or declaration other than the namespace |
| 728 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 729 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 730 | (!getCurLexicalContext()->isFileContext() || |
| 731 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 732 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 733 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 734 | bool IsDecl = |
| 735 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 736 | Diag(VD->getLocation(), |
| 737 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 738 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 739 | return ExprError(); |
| 740 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 741 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 742 | // A threadprivate directive for static block-scope variables must appear |
| 743 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 744 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 745 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 746 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 747 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 748 | bool IsDecl = |
| 749 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 750 | Diag(VD->getLocation(), |
| 751 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 752 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 753 | return ExprError(); |
| 754 | } |
| 755 | |
| 756 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 757 | // A threadprivate directive must lexically precede all references to any |
| 758 | // of the variables in its list. |
| 759 | if (VD->isUsed()) { |
| 760 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 761 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 762 | return ExprError(); |
| 763 | } |
| 764 | |
| 765 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 766 | ExprResult DE = BuildDeclRefExpr(VD, ExprType, VK_LValue, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 767 | return DE; |
| 768 | } |
| 769 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 770 | Sema::DeclGroupPtrTy |
| 771 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 772 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 773 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 774 | CurContext->addDecl(D); |
| 775 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 776 | } |
| 777 | return DeclGroupPtrTy(); |
| 778 | } |
| 779 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 780 | namespace { |
| 781 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 782 | Sema &SemaRef; |
| 783 | |
| 784 | public: |
| 785 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 786 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 787 | if (VD->hasLocalStorage()) { |
| 788 | SemaRef.Diag(E->getLocStart(), |
| 789 | diag::err_omp_local_var_in_threadprivate_init) |
| 790 | << E->getSourceRange(); |
| 791 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 792 | << VD << VD->getSourceRange(); |
| 793 | return true; |
| 794 | } |
| 795 | } |
| 796 | return false; |
| 797 | } |
| 798 | bool VisitStmt(const Stmt *S) { |
| 799 | for (auto Child : S->children()) { |
| 800 | if (Child && Visit(Child)) |
| 801 | return true; |
| 802 | } |
| 803 | return false; |
| 804 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 805 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 806 | }; |
| 807 | } // namespace |
| 808 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 809 | OMPThreadPrivateDecl * |
| 810 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 811 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 812 | for (auto &RefExpr : VarList) { |
| 813 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 814 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 815 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 816 | |
| 817 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 818 | // A threadprivate variable must not have an incomplete type. |
| 819 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 820 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 821 | continue; |
| 822 | } |
| 823 | |
| 824 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 825 | // A threadprivate variable must not have a reference type. |
| 826 | if (VD->getType()->isReferenceType()) { |
| 827 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 828 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 829 | bool IsDecl = |
| 830 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 831 | Diag(VD->getLocation(), |
| 832 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 833 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 834 | continue; |
| 835 | } |
| 836 | |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 837 | // Check if this is a TLS variable. |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 838 | if (VD->getTLSKind() != VarDecl::TLS_None || |
| 839 | VD->getStorageClass() == SC_Register) { |
| 840 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 841 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 842 | bool IsDecl = |
| 843 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 844 | Diag(VD->getLocation(), |
| 845 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 846 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 847 | continue; |
| 848 | } |
| 849 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 850 | // Check if initial value of threadprivate variable reference variable with |
| 851 | // local storage (it is not supported by runtime). |
| 852 | if (auto Init = VD->getAnyInitializer()) { |
| 853 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 854 | if (Checker.Visit(Init)) |
| 855 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 856 | } |
| 857 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 858 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 859 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 860 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 861 | Context, SourceRange(Loc, Loc))); |
| 862 | if (auto *ML = Context.getASTMutationListener()) |
| 863 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 864 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 865 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 866 | if (!Vars.empty()) { |
| 867 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 868 | Vars); |
| 869 | D->setAccess(AS_public); |
| 870 | } |
| 871 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 872 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 873 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 874 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 875 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 876 | bool IsLoopIterVar = false) { |
| 877 | if (DVar.RefExpr) { |
| 878 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 879 | << getOpenMPClauseName(DVar.CKind); |
| 880 | return; |
| 881 | } |
| 882 | enum { |
| 883 | PDSA_StaticMemberShared, |
| 884 | PDSA_StaticLocalVarShared, |
| 885 | PDSA_LoopIterVarPrivate, |
| 886 | PDSA_LoopIterVarLinear, |
| 887 | PDSA_LoopIterVarLastprivate, |
| 888 | PDSA_ConstVarShared, |
| 889 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 890 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 891 | PDSA_LocalVarPrivate, |
| 892 | PDSA_Implicit |
| 893 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 894 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 895 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 896 | if (IsLoopIterVar) { |
| 897 | if (DVar.CKind == OMPC_private) |
| 898 | Reason = PDSA_LoopIterVarPrivate; |
| 899 | else if (DVar.CKind == OMPC_lastprivate) |
| 900 | Reason = PDSA_LoopIterVarLastprivate; |
| 901 | else |
| 902 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 903 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 904 | Reason = PDSA_TaskVarFirstprivate; |
| 905 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 906 | } else if (VD->isStaticLocal()) |
| 907 | Reason = PDSA_StaticLocalVarShared; |
| 908 | else if (VD->isStaticDataMember()) |
| 909 | Reason = PDSA_StaticMemberShared; |
| 910 | else if (VD->isFileVarDecl()) |
| 911 | Reason = PDSA_GlobalVarShared; |
| 912 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 913 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 914 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 915 | ReportHint = true; |
| 916 | Reason = PDSA_LocalVarPrivate; |
| 917 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 918 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 919 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 920 | << Reason << ReportHint |
| 921 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 922 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 923 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 924 | << getOpenMPClauseName(DVar.CKind); |
| 925 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 928 | namespace { |
| 929 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 930 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 931 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 932 | bool ErrorFound; |
| 933 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 934 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 935 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 936 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 937 | public: |
| 938 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 939 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 940 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 941 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 942 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 943 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 944 | auto DVar = Stack->getTopDSA(VD, false); |
| 945 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 946 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 947 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 948 | auto ELoc = E->getExprLoc(); |
| 949 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 950 | // The default(none) clause requires that each variable that is referenced |
| 951 | // in the construct, and does not have a predetermined data-sharing |
| 952 | // attribute, must have its data-sharing attribute explicitly determined |
| 953 | // by being listed in a data-sharing attribute clause. |
| 954 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 955 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 956 | VarsWithInheritedDSA.count(VD) == 0) { |
| 957 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 958 | return; |
| 959 | } |
| 960 | |
| 961 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 962 | // A list item that appears in a reduction clause of the innermost |
| 963 | // enclosing worksharing or parallel construct may not be accessed in an |
| 964 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 965 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 966 | [](OpenMPDirectiveKind K) -> bool { |
| 967 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 968 | isOpenMPWorksharingDirective(K) || |
| 969 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 970 | }, |
| 971 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 972 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 973 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 974 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 975 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 976 | return; |
| 977 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 978 | |
| 979 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 980 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 981 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 982 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 983 | } |
| 984 | } |
| 985 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 986 | for (auto *C : S->clauses()) { |
| 987 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 988 | // for task directives. |
| 989 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 990 | for (auto *CC : C->children()) { |
| 991 | if (CC) |
| 992 | Visit(CC); |
| 993 | } |
| 994 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 995 | } |
| 996 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 997 | for (auto *C : S->children()) { |
| 998 | if (C && !isa<OMPExecutableDirective>(C)) |
| 999 | Visit(C); |
| 1000 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1001 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1002 | |
| 1003 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1004 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1005 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1006 | return VarsWithInheritedDSA; |
| 1007 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1008 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1009 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1010 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1011 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1012 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1013 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1014 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1015 | switch (DKind) { |
| 1016 | case OMPD_parallel: { |
| 1017 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1018 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1019 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1020 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1021 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1022 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1023 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1024 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1025 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1026 | break; |
| 1027 | } |
| 1028 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1029 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1030 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1031 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1032 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1033 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1034 | break; |
| 1035 | } |
| 1036 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1037 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1038 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1039 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1040 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1041 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1042 | break; |
| 1043 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1044 | case OMPD_for_simd: { |
| 1045 | Sema::CapturedParamNameType Params[] = { |
| 1046 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1047 | }; |
| 1048 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1049 | Params); |
| 1050 | break; |
| 1051 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1052 | case OMPD_sections: { |
| 1053 | Sema::CapturedParamNameType Params[] = { |
| 1054 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1055 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1056 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1057 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1058 | break; |
| 1059 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1060 | case OMPD_section: { |
| 1061 | Sema::CapturedParamNameType Params[] = { |
| 1062 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1063 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1064 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1065 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1066 | break; |
| 1067 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1068 | case OMPD_single: { |
| 1069 | Sema::CapturedParamNameType Params[] = { |
| 1070 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1071 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1072 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1073 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1074 | break; |
| 1075 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1076 | case OMPD_master: { |
| 1077 | Sema::CapturedParamNameType Params[] = { |
| 1078 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1079 | }; |
| 1080 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1081 | Params); |
| 1082 | break; |
| 1083 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1084 | case OMPD_critical: { |
| 1085 | Sema::CapturedParamNameType Params[] = { |
| 1086 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1087 | }; |
| 1088 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1089 | Params); |
| 1090 | break; |
| 1091 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1092 | case OMPD_parallel_for: { |
| 1093 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1094 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1095 | Sema::CapturedParamNameType Params[] = { |
| 1096 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1097 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1098 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1099 | }; |
| 1100 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1101 | Params); |
| 1102 | break; |
| 1103 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1104 | case OMPD_parallel_for_simd: { |
| 1105 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1106 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1107 | Sema::CapturedParamNameType Params[] = { |
| 1108 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1109 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1110 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1111 | }; |
| 1112 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1113 | Params); |
| 1114 | break; |
| 1115 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1116 | case OMPD_parallel_sections: { |
| 1117 | Sema::CapturedParamNameType Params[] = { |
| 1118 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1119 | }; |
| 1120 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1121 | Params); |
| 1122 | break; |
| 1123 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1124 | case OMPD_task: { |
| 1125 | Sema::CapturedParamNameType Params[] = { |
| 1126 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1127 | }; |
| 1128 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1129 | Params); |
| 1130 | break; |
| 1131 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1132 | case OMPD_ordered: { |
| 1133 | Sema::CapturedParamNameType Params[] = { |
| 1134 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1135 | }; |
| 1136 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1137 | Params); |
| 1138 | break; |
| 1139 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1140 | case OMPD_atomic: { |
| 1141 | Sema::CapturedParamNameType Params[] = { |
| 1142 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1143 | }; |
| 1144 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1145 | Params); |
| 1146 | break; |
| 1147 | } |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1148 | case OMPD_target: { |
| 1149 | Sema::CapturedParamNameType Params[] = { |
| 1150 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1151 | }; |
| 1152 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1153 | Params); |
| 1154 | break; |
| 1155 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1156 | case OMPD_teams: { |
| 1157 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1158 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1159 | Sema::CapturedParamNameType Params[] = { |
| 1160 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1161 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1162 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1163 | }; |
| 1164 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1165 | Params); |
| 1166 | break; |
| 1167 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1168 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1169 | case OMPD_taskyield: |
| 1170 | case OMPD_barrier: |
| 1171 | case OMPD_taskwait: |
| 1172 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1173 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1174 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1175 | llvm_unreachable("Unknown OpenMP directive"); |
| 1176 | } |
| 1177 | } |
| 1178 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1179 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1180 | OpenMPDirectiveKind CurrentRegion, |
| 1181 | const DeclarationNameInfo &CurrentName, |
| 1182 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1183 | // Allowed nesting of constructs |
| 1184 | // +------------------+-----------------+------------------------------------+ |
| 1185 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1186 | // +------------------+-----------------+------------------------------------+ |
| 1187 | // | parallel | parallel | * | |
| 1188 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1189 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1190 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1191 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1192 | // | parallel | simd | * | |
| 1193 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1194 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1195 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1196 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1197 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1198 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1199 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1200 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1201 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1202 | // | parallel | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1203 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1204 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1205 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1206 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1207 | // | parallel | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1208 | // +------------------+-----------------+------------------------------------+ |
| 1209 | // | for | parallel | * | |
| 1210 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1211 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1212 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1213 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1214 | // | for | simd | * | |
| 1215 | // | for | sections | + | |
| 1216 | // | for | section | + | |
| 1217 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1218 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1219 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1220 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1221 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1222 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1223 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1224 | // | for | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1225 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1226 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1227 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1228 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1229 | // | for | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1230 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1231 | // | master | parallel | * | |
| 1232 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1233 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1234 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1235 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1236 | // | master | simd | * | |
| 1237 | // | master | sections | + | |
| 1238 | // | master | section | + | |
| 1239 | // | master | single | + | |
| 1240 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1241 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1242 | // | master |parallel sections| * | |
| 1243 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1244 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1245 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1246 | // | master | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1247 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1248 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1249 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1250 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1251 | // | master | teams | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1252 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1253 | // | critical | parallel | * | |
| 1254 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1255 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1256 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1257 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1258 | // | critical | simd | * | |
| 1259 | // | critical | sections | + | |
| 1260 | // | critical | section | + | |
| 1261 | // | critical | single | + | |
| 1262 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1263 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1264 | // | critical |parallel sections| * | |
| 1265 | // | critical | task | * | |
| 1266 | // | critical | taskyield | * | |
| 1267 | // | critical | barrier | + | |
| 1268 | // | critical | taskwait | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1269 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1270 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1271 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1272 | // | critical | teams | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1273 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1274 | // | simd | parallel | | |
| 1275 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1276 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1277 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1278 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1279 | // | simd | simd | | |
| 1280 | // | simd | sections | | |
| 1281 | // | simd | section | | |
| 1282 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1283 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1284 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1285 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1286 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1287 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1288 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1289 | // | simd | taskwait | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1290 | // | simd | flush | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1291 | // | simd | ordered | | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1292 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1293 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1294 | // | simd | teams | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1295 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1296 | // | for simd | parallel | | |
| 1297 | // | for simd | for | | |
| 1298 | // | for simd | for simd | | |
| 1299 | // | for simd | master | | |
| 1300 | // | for simd | critical | | |
| 1301 | // | for simd | simd | | |
| 1302 | // | for simd | sections | | |
| 1303 | // | for simd | section | | |
| 1304 | // | for simd | single | | |
| 1305 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1306 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1307 | // | for simd |parallel sections| | |
| 1308 | // | for simd | task | | |
| 1309 | // | for simd | taskyield | | |
| 1310 | // | for simd | barrier | | |
| 1311 | // | for simd | taskwait | | |
| 1312 | // | for simd | flush | | |
| 1313 | // | for simd | ordered | | |
| 1314 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1315 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1316 | // | for simd | teams | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1317 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1318 | // | parallel for simd| parallel | | |
| 1319 | // | parallel for simd| for | | |
| 1320 | // | parallel for simd| for simd | | |
| 1321 | // | parallel for simd| master | | |
| 1322 | // | parallel for simd| critical | | |
| 1323 | // | parallel for simd| simd | | |
| 1324 | // | parallel for simd| sections | | |
| 1325 | // | parallel for simd| section | | |
| 1326 | // | parallel for simd| single | | |
| 1327 | // | parallel for simd| parallel for | | |
| 1328 | // | parallel for simd|parallel for simd| | |
| 1329 | // | parallel for simd|parallel sections| | |
| 1330 | // | parallel for simd| task | | |
| 1331 | // | parallel for simd| taskyield | | |
| 1332 | // | parallel for simd| barrier | | |
| 1333 | // | parallel for simd| taskwait | | |
| 1334 | // | parallel for simd| flush | | |
| 1335 | // | parallel for simd| ordered | | |
| 1336 | // | parallel for simd| atomic | | |
| 1337 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1338 | // | parallel for simd| teams | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1339 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1340 | // | sections | parallel | * | |
| 1341 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1342 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1343 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1344 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1345 | // | sections | simd | * | |
| 1346 | // | sections | sections | + | |
| 1347 | // | sections | section | * | |
| 1348 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1349 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1350 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1351 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1352 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1353 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1354 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1355 | // | sections | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1356 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1357 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1358 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1359 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1360 | // | sections | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1361 | // +------------------+-----------------+------------------------------------+ |
| 1362 | // | section | parallel | * | |
| 1363 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1364 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1365 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1366 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1367 | // | section | simd | * | |
| 1368 | // | section | sections | + | |
| 1369 | // | section | section | + | |
| 1370 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1371 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1372 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1373 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1374 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1375 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1376 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1377 | // | section | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1378 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1379 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1380 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1381 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1382 | // | section | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1383 | // +------------------+-----------------+------------------------------------+ |
| 1384 | // | single | parallel | * | |
| 1385 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1386 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1387 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1388 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1389 | // | single | simd | * | |
| 1390 | // | single | sections | + | |
| 1391 | // | single | section | + | |
| 1392 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1393 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1394 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1395 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1396 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1397 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1398 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1399 | // | single | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1400 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1401 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1402 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1403 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1404 | // | single | teams | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1405 | // +------------------+-----------------+------------------------------------+ |
| 1406 | // | parallel for | parallel | * | |
| 1407 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1408 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1409 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1410 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1411 | // | parallel for | simd | * | |
| 1412 | // | parallel for | sections | + | |
| 1413 | // | parallel for | section | + | |
| 1414 | // | parallel for | single | + | |
| 1415 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1416 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1417 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1418 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1419 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1420 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1421 | // | parallel for | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1422 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1423 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1424 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1425 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1426 | // | parallel for | teams | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1427 | // +------------------+-----------------+------------------------------------+ |
| 1428 | // | parallel sections| parallel | * | |
| 1429 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1430 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1431 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1432 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1433 | // | parallel sections| simd | * | |
| 1434 | // | parallel sections| sections | + | |
| 1435 | // | parallel sections| section | * | |
| 1436 | // | parallel sections| single | + | |
| 1437 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1438 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1439 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1440 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1441 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1442 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1443 | // | parallel sections| taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1444 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1445 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1446 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1447 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1448 | // | parallel sections| teams | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1449 | // +------------------+-----------------+------------------------------------+ |
| 1450 | // | task | parallel | * | |
| 1451 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1452 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1453 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1454 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1455 | // | task | simd | * | |
| 1456 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1457 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1458 | // | task | single | + | |
| 1459 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1460 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1461 | // | task |parallel sections| * | |
| 1462 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1463 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1464 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1465 | // | task | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1466 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1467 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1468 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1469 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1470 | // | task | teams | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1471 | // +------------------+-----------------+------------------------------------+ |
| 1472 | // | ordered | parallel | * | |
| 1473 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1474 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1475 | // | ordered | master | * | |
| 1476 | // | ordered | critical | * | |
| 1477 | // | ordered | simd | * | |
| 1478 | // | ordered | sections | + | |
| 1479 | // | ordered | section | + | |
| 1480 | // | ordered | single | + | |
| 1481 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1482 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1483 | // | ordered |parallel sections| * | |
| 1484 | // | ordered | task | * | |
| 1485 | // | ordered | taskyield | * | |
| 1486 | // | ordered | barrier | + | |
| 1487 | // | ordered | taskwait | * | |
| 1488 | // | ordered | flush | * | |
| 1489 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1490 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1491 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1492 | // | ordered | teams | + | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1493 | // +------------------+-----------------+------------------------------------+ |
| 1494 | // | atomic | parallel | | |
| 1495 | // | atomic | for | | |
| 1496 | // | atomic | for simd | | |
| 1497 | // | atomic | master | | |
| 1498 | // | atomic | critical | | |
| 1499 | // | atomic | simd | | |
| 1500 | // | atomic | sections | | |
| 1501 | // | atomic | section | | |
| 1502 | // | atomic | single | | |
| 1503 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1504 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1505 | // | atomic |parallel sections| | |
| 1506 | // | atomic | task | | |
| 1507 | // | atomic | taskyield | | |
| 1508 | // | atomic | barrier | | |
| 1509 | // | atomic | taskwait | | |
| 1510 | // | atomic | flush | | |
| 1511 | // | atomic | ordered | | |
| 1512 | // | atomic | atomic | | |
| 1513 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1514 | // | atomic | teams | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1515 | // +------------------+-----------------+------------------------------------+ |
| 1516 | // | target | parallel | * | |
| 1517 | // | target | for | * | |
| 1518 | // | target | for simd | * | |
| 1519 | // | target | master | * | |
| 1520 | // | target | critical | * | |
| 1521 | // | target | simd | * | |
| 1522 | // | target | sections | * | |
| 1523 | // | target | section | * | |
| 1524 | // | target | single | * | |
| 1525 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1526 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1527 | // | target |parallel sections| * | |
| 1528 | // | target | task | * | |
| 1529 | // | target | taskyield | * | |
| 1530 | // | target | barrier | * | |
| 1531 | // | target | taskwait | * | |
| 1532 | // | target | flush | * | |
| 1533 | // | target | ordered | * | |
| 1534 | // | target | atomic | * | |
| 1535 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1536 | // | target | teams | * | |
| 1537 | // +------------------+-----------------+------------------------------------+ |
| 1538 | // | teams | parallel | * | |
| 1539 | // | teams | for | + | |
| 1540 | // | teams | for simd | + | |
| 1541 | // | teams | master | + | |
| 1542 | // | teams | critical | + | |
| 1543 | // | teams | simd | + | |
| 1544 | // | teams | sections | + | |
| 1545 | // | teams | section | + | |
| 1546 | // | teams | single | + | |
| 1547 | // | teams | parallel for | * | |
| 1548 | // | teams |parallel for simd| * | |
| 1549 | // | teams |parallel sections| * | |
| 1550 | // | teams | task | + | |
| 1551 | // | teams | taskyield | + | |
| 1552 | // | teams | barrier | + | |
| 1553 | // | teams | taskwait | + | |
| 1554 | // | teams | flush | + | |
| 1555 | // | teams | ordered | + | |
| 1556 | // | teams | atomic | + | |
| 1557 | // | teams | target | + | |
| 1558 | // | teams | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1559 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1560 | if (Stack->getCurScope()) { |
| 1561 | auto ParentRegion = Stack->getParentDirective(); |
| 1562 | bool NestingProhibited = false; |
| 1563 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1564 | enum { |
| 1565 | NoRecommend, |
| 1566 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1567 | ShouldBeInOrderedRegion, |
| 1568 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1569 | } Recommend = NoRecommend; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1570 | if (isOpenMPSimdDirective(ParentRegion)) { |
| 1571 | // OpenMP [2.16, Nesting of Regions] |
| 1572 | // OpenMP constructs may not be nested inside a simd region. |
| 1573 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1574 | return true; |
| 1575 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1576 | if (ParentRegion == OMPD_atomic) { |
| 1577 | // OpenMP [2.16, Nesting of Regions] |
| 1578 | // OpenMP constructs may not be nested inside an atomic region. |
| 1579 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1580 | return true; |
| 1581 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1582 | if (CurrentRegion == OMPD_section) { |
| 1583 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1584 | // Orphaned section directives are prohibited. That is, the section |
| 1585 | // directives must appear within the sections construct and must not be |
| 1586 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1587 | if (ParentRegion != OMPD_sections && |
| 1588 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1589 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1590 | << (ParentRegion != OMPD_unknown) |
| 1591 | << getOpenMPDirectiveName(ParentRegion); |
| 1592 | return true; |
| 1593 | } |
| 1594 | return false; |
| 1595 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1596 | // Allow some constructs to be orphaned (they could be used in functions, |
| 1597 | // called from OpenMP regions with the required preconditions). |
| 1598 | if (ParentRegion == OMPD_unknown) |
| 1599 | return false; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1600 | if (CurrentRegion == OMPD_master) { |
| 1601 | // OpenMP [2.16, Nesting of Regions] |
| 1602 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1603 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1604 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 1605 | ParentRegion == OMPD_task; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1606 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 1607 | // OpenMP [2.16, Nesting of Regions] |
| 1608 | // A critical region may not be nested (closely or otherwise) inside a |
| 1609 | // critical region with the same name. Note that this restriction is not |
| 1610 | // sufficient to prevent deadlock. |
| 1611 | SourceLocation PreviousCriticalLoc; |
| 1612 | bool DeadLock = |
| 1613 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 1614 | OpenMPDirectiveKind K, |
| 1615 | const DeclarationNameInfo &DNI, |
| 1616 | SourceLocation Loc) |
| 1617 | ->bool { |
| 1618 | if (K == OMPD_critical && |
| 1619 | DNI.getName() == CurrentName.getName()) { |
| 1620 | PreviousCriticalLoc = Loc; |
| 1621 | return true; |
| 1622 | } else |
| 1623 | return false; |
| 1624 | }, |
| 1625 | false /* skip top directive */); |
| 1626 | if (DeadLock) { |
| 1627 | SemaRef.Diag(StartLoc, |
| 1628 | diag::err_omp_prohibited_region_critical_same_name) |
| 1629 | << CurrentName.getName(); |
| 1630 | if (PreviousCriticalLoc.isValid()) |
| 1631 | SemaRef.Diag(PreviousCriticalLoc, |
| 1632 | diag::note_omp_previous_critical_region); |
| 1633 | return true; |
| 1634 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1635 | } else if (CurrentRegion == OMPD_barrier) { |
| 1636 | // OpenMP [2.16, Nesting of Regions] |
| 1637 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1638 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1639 | NestingProhibited = |
| 1640 | isOpenMPWorksharingDirective(ParentRegion) || |
| 1641 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1642 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1643 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1644 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1645 | // OpenMP [2.16, Nesting of Regions] |
| 1646 | // A worksharing region may not be closely nested inside a worksharing, |
| 1647 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1648 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1649 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1650 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1651 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
| 1652 | Recommend = ShouldBeInParallelRegion; |
| 1653 | } else if (CurrentRegion == OMPD_ordered) { |
| 1654 | // OpenMP [2.16, Nesting of Regions] |
| 1655 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1656 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1657 | // An ordered region must be closely nested inside a loop region (or |
| 1658 | // parallel loop region) with an ordered clause. |
| 1659 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1660 | ParentRegion == OMPD_task || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1661 | !Stack->isParentOrderedRegion(); |
| 1662 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1663 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 1664 | // OpenMP [2.16, Nesting of Regions] |
| 1665 | // If specified, a teams construct must be contained within a target |
| 1666 | // construct. |
| 1667 | NestingProhibited = ParentRegion != OMPD_target; |
| 1668 | Recommend = ShouldBeInTargetRegion; |
| 1669 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 1670 | } |
| 1671 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 1672 | // OpenMP [2.16, Nesting of Regions] |
| 1673 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 1674 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 1675 | // constructs that can be closely nested in the teams region. |
| 1676 | // TODO: add distribute directive. |
| 1677 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 1678 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1679 | } |
| 1680 | if (NestingProhibited) { |
| 1681 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1682 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 1683 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1684 | return true; |
| 1685 | } |
| 1686 | } |
| 1687 | return false; |
| 1688 | } |
| 1689 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1690 | StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1691 | const DeclarationNameInfo &DirName, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1692 | ArrayRef<OMPClause *> Clauses, |
| 1693 | Stmt *AStmt, |
| 1694 | SourceLocation StartLoc, |
| 1695 | SourceLocation EndLoc) { |
| 1696 | StmtResult Res = StmtError(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1697 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1698 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1699 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1700 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1701 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1702 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1703 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1704 | if (AStmt) { |
| 1705 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1706 | |
| 1707 | // Check default data sharing attributes for referenced variables. |
| 1708 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 1709 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 1710 | if (DSAChecker.isErrorFound()) |
| 1711 | return StmtError(); |
| 1712 | // Generate list of implicitly defined firstprivate variables. |
| 1713 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1714 | |
| 1715 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 1716 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 1717 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 1718 | SourceLocation(), SourceLocation())) { |
| 1719 | ClausesWithImplicit.push_back(Implicit); |
| 1720 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 1721 | DSAChecker.getImplicitFirstprivate().size(); |
| 1722 | } else |
| 1723 | ErrorFound = true; |
| 1724 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1725 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1726 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1727 | switch (Kind) { |
| 1728 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1729 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1730 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1731 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1732 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1733 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 1734 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1735 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1736 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1737 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 1738 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1739 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1740 | case OMPD_for_simd: |
| 1741 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1742 | EndLoc, VarsWithInheritedDSA); |
| 1743 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1744 | case OMPD_sections: |
| 1745 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1746 | EndLoc); |
| 1747 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1748 | case OMPD_section: |
| 1749 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1750 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1751 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 1752 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1753 | case OMPD_single: |
| 1754 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1755 | EndLoc); |
| 1756 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1757 | case OMPD_master: |
| 1758 | assert(ClausesWithImplicit.empty() && |
| 1759 | "No clauses are allowed for 'omp master' directive"); |
| 1760 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 1761 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1762 | case OMPD_critical: |
| 1763 | assert(ClausesWithImplicit.empty() && |
| 1764 | "No clauses are allowed for 'omp critical' directive"); |
| 1765 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 1766 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1767 | case OMPD_parallel_for: |
| 1768 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1769 | EndLoc, VarsWithInheritedDSA); |
| 1770 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1771 | case OMPD_parallel_for_simd: |
| 1772 | Res = ActOnOpenMPParallelForSimdDirective( |
| 1773 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 1774 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1775 | case OMPD_parallel_sections: |
| 1776 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 1777 | StartLoc, EndLoc); |
| 1778 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1779 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1780 | Res = |
| 1781 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 1782 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1783 | case OMPD_taskyield: |
| 1784 | assert(ClausesWithImplicit.empty() && |
| 1785 | "No clauses are allowed for 'omp taskyield' directive"); |
| 1786 | assert(AStmt == nullptr && |
| 1787 | "No associated statement allowed for 'omp taskyield' directive"); |
| 1788 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 1789 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1790 | case OMPD_barrier: |
| 1791 | assert(ClausesWithImplicit.empty() && |
| 1792 | "No clauses are allowed for 'omp barrier' directive"); |
| 1793 | assert(AStmt == nullptr && |
| 1794 | "No associated statement allowed for 'omp barrier' directive"); |
| 1795 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 1796 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1797 | case OMPD_taskwait: |
| 1798 | assert(ClausesWithImplicit.empty() && |
| 1799 | "No clauses are allowed for 'omp taskwait' directive"); |
| 1800 | assert(AStmt == nullptr && |
| 1801 | "No associated statement allowed for 'omp taskwait' directive"); |
| 1802 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 1803 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1804 | case OMPD_flush: |
| 1805 | assert(AStmt == nullptr && |
| 1806 | "No associated statement allowed for 'omp flush' directive"); |
| 1807 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 1808 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1809 | case OMPD_ordered: |
| 1810 | assert(ClausesWithImplicit.empty() && |
| 1811 | "No clauses are allowed for 'omp ordered' directive"); |
| 1812 | Res = ActOnOpenMPOrderedDirective(AStmt, StartLoc, EndLoc); |
| 1813 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1814 | case OMPD_atomic: |
| 1815 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1816 | EndLoc); |
| 1817 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1818 | case OMPD_teams: |
| 1819 | Res = |
| 1820 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 1821 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1822 | case OMPD_target: |
| 1823 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1824 | EndLoc); |
| 1825 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1826 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1827 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1828 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1829 | llvm_unreachable("Unknown OpenMP directive"); |
| 1830 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1831 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1832 | for (auto P : VarsWithInheritedDSA) { |
| 1833 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 1834 | << P.first << P.second->getSourceRange(); |
| 1835 | } |
| 1836 | if (!VarsWithInheritedDSA.empty()) |
| 1837 | return StmtError(); |
| 1838 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1839 | if (ErrorFound) |
| 1840 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1841 | return Res; |
| 1842 | } |
| 1843 | |
| 1844 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 1845 | Stmt *AStmt, |
| 1846 | SourceLocation StartLoc, |
| 1847 | SourceLocation EndLoc) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1848 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1849 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 1850 | // 1.2.2 OpenMP Language Terminology |
| 1851 | // Structured block - An executable statement with a single entry at the |
| 1852 | // top and a single exit at the bottom. |
| 1853 | // The point of exit cannot be a branch out of the structured block. |
| 1854 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 1855 | CS->getCapturedDecl()->setNothrow(); |
| 1856 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1857 | getCurFunction()->setHasBranchProtectedScope(); |
| 1858 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1859 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 1860 | AStmt); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1863 | namespace { |
| 1864 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 1865 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 1866 | /// for IR generation. |
| 1867 | class OpenMPIterationSpaceChecker { |
| 1868 | /// \brief Reference to Sema. |
| 1869 | Sema &SemaRef; |
| 1870 | /// \brief A location for diagnostics (when there is no some better location). |
| 1871 | SourceLocation DefaultLoc; |
| 1872 | /// \brief A location for diagnostics (when increment is not compatible). |
| 1873 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1874 | /// \brief A source location for referring to loop init later. |
| 1875 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1876 | /// \brief A source location for referring to condition later. |
| 1877 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1878 | /// \brief A source location for referring to increment later. |
| 1879 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1880 | /// \brief Loop variable. |
| 1881 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 1882 | /// \brief Reference to loop variable. |
| 1883 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1884 | /// \brief Lower bound (initializer for the var). |
| 1885 | Expr *LB; |
| 1886 | /// \brief Upper bound. |
| 1887 | Expr *UB; |
| 1888 | /// \brief Loop step (increment). |
| 1889 | Expr *Step; |
| 1890 | /// \brief This flag is true when condition is one of: |
| 1891 | /// Var < UB |
| 1892 | /// Var <= UB |
| 1893 | /// UB > Var |
| 1894 | /// UB >= Var |
| 1895 | bool TestIsLessOp; |
| 1896 | /// \brief This flag is true when condition is strict ( < or > ). |
| 1897 | bool TestIsStrictOp; |
| 1898 | /// \brief This flag is true when step is subtracted on each iteration. |
| 1899 | bool SubtractStep; |
| 1900 | |
| 1901 | public: |
| 1902 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 1903 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1904 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 1905 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 1906 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 1907 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1908 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 1909 | /// variable - #Var and its initialization value - #LB. |
| 1910 | bool CheckInit(Stmt *S); |
| 1911 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 1912 | /// for less/greater and for strict/non-strict comparison. |
| 1913 | bool CheckCond(Expr *S); |
| 1914 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 1915 | /// does not conform, otherwise save loop step (#Step). |
| 1916 | bool CheckInc(Expr *S); |
| 1917 | /// \brief Return the loop counter variable. |
| 1918 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 1919 | /// \brief Return the reference expression to loop counter variable. |
| 1920 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1921 | /// \brief Source range of the loop init. |
| 1922 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 1923 | /// \brief Source range of the loop condition. |
| 1924 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 1925 | /// \brief Source range of the loop increment. |
| 1926 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 1927 | /// \brief True if the step should be subtracted. |
| 1928 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 1929 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 1930 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1931 | /// \brief Build reference expression to the counter be used for codegen. |
| 1932 | Expr *BuildCounterVar() const; |
| 1933 | /// \brief Build initization of the counter be used for codegen. |
| 1934 | Expr *BuildCounterInit() const; |
| 1935 | /// \brief Build step of the counter be used for codegen. |
| 1936 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1937 | /// \brief Return true if any expression is dependent. |
| 1938 | bool Dependent() const; |
| 1939 | |
| 1940 | private: |
| 1941 | /// \brief Check the right-hand side of an assignment in the increment |
| 1942 | /// expression. |
| 1943 | bool CheckIncRHS(Expr *RHS); |
| 1944 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 1945 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1946 | /// \brief Helper to set upper bound. |
| 1947 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR, |
| 1948 | const SourceLocation &SL); |
| 1949 | /// \brief Helper to set loop increment. |
| 1950 | bool SetStep(Expr *NewStep, bool Subtract); |
| 1951 | }; |
| 1952 | |
| 1953 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 1954 | if (!Var) { |
| 1955 | assert(!LB && !UB && !Step); |
| 1956 | return false; |
| 1957 | } |
| 1958 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 1959 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 1960 | } |
| 1961 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 1962 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 1963 | DeclRefExpr *NewVarRefExpr, |
| 1964 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1965 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 1966 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 1967 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1968 | if (!NewVar || !NewLB) |
| 1969 | return true; |
| 1970 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 1971 | VarRef = NewVarRefExpr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1972 | LB = NewLB; |
| 1973 | return false; |
| 1974 | } |
| 1975 | |
| 1976 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| 1977 | const SourceRange &SR, |
| 1978 | const SourceLocation &SL) { |
| 1979 | // State consistency checking to ensure correct usage. |
| 1980 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 1981 | !TestIsLessOp && !TestIsStrictOp); |
| 1982 | if (!NewUB) |
| 1983 | return true; |
| 1984 | UB = NewUB; |
| 1985 | TestIsLessOp = LessOp; |
| 1986 | TestIsStrictOp = StrictOp; |
| 1987 | ConditionSrcRange = SR; |
| 1988 | ConditionLoc = SL; |
| 1989 | return false; |
| 1990 | } |
| 1991 | |
| 1992 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 1993 | // State consistency checking to ensure correct usage. |
| 1994 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 1995 | if (!NewStep) |
| 1996 | return true; |
| 1997 | if (!NewStep->isValueDependent()) { |
| 1998 | // Check that the step is integer expression. |
| 1999 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2000 | ExprResult Val = |
| 2001 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2002 | if (Val.isInvalid()) |
| 2003 | return true; |
| 2004 | NewStep = Val.get(); |
| 2005 | |
| 2006 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2007 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2008 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2009 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2010 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2011 | // the loop. |
| 2012 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2013 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2014 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2015 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2016 | // the loop. |
| 2017 | llvm::APSInt Result; |
| 2018 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2019 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2020 | bool IsConstNeg = |
| 2021 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2022 | bool IsConstPos = |
| 2023 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2024 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2025 | if (UB && (IsConstZero || |
| 2026 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2027 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2028 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2029 | diag::err_omp_loop_incr_not_compatible) |
| 2030 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2031 | SemaRef.Diag(ConditionLoc, |
| 2032 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2033 | << TestIsLessOp << ConditionSrcRange; |
| 2034 | return true; |
| 2035 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2036 | if (TestIsLessOp == Subtract) { |
| 2037 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2038 | NewStep).get(); |
| 2039 | Subtract = !Subtract; |
| 2040 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | Step = NewStep; |
| 2044 | SubtractStep = Subtract; |
| 2045 | return false; |
| 2046 | } |
| 2047 | |
| 2048 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S) { |
| 2049 | // Check init-expr for canonical loop form and save loop counter |
| 2050 | // variable - #Var and its initialization value - #LB. |
| 2051 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2052 | // var = lb |
| 2053 | // integer-type var = lb |
| 2054 | // random-access-iterator-type var = lb |
| 2055 | // pointer-type var = lb |
| 2056 | // |
| 2057 | if (!S) { |
| 2058 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2059 | return true; |
| 2060 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2061 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2062 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2063 | S = E->IgnoreParens(); |
| 2064 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2065 | if (BO->getOpcode() == BO_Assign) |
| 2066 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2067 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2068 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2069 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2070 | if (DS->isSingleDecl()) { |
| 2071 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
| 2072 | if (Var->hasInit()) { |
| 2073 | // Accept non-canonical init form here but emit ext. warning. |
| 2074 | if (Var->getInitStyle() != VarDecl::CInit) |
| 2075 | SemaRef.Diag(S->getLocStart(), |
| 2076 | diag::ext_omp_loop_not_canonical_init) |
| 2077 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2078 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | } |
| 2082 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2083 | if (CE->getOperator() == OO_Equal) |
| 2084 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2085 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2086 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2087 | |
| 2088 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2089 | << S->getSourceRange(); |
| 2090 | return true; |
| 2091 | } |
| 2092 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2093 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2094 | /// variable (which may be the loop variable) if possible. |
| 2095 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2096 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2097 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2098 | E = E->IgnoreParenImpCasts(); |
| 2099 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2100 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| 2101 | if (Ctor->isCopyConstructor() && CE->getNumArgs() == 1 && |
| 2102 | CE->getArg(0) != nullptr) |
| 2103 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2104 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2105 | if (!DRE) |
| 2106 | return nullptr; |
| 2107 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2108 | } |
| 2109 | |
| 2110 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2111 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2112 | // less/greater and for strict/non-strict comparison. |
| 2113 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2114 | // var relational-op b |
| 2115 | // b relational-op var |
| 2116 | // |
| 2117 | if (!S) { |
| 2118 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2119 | return true; |
| 2120 | } |
| 2121 | S = S->IgnoreParenImpCasts(); |
| 2122 | SourceLocation CondLoc = S->getLocStart(); |
| 2123 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2124 | if (BO->isRelationalOp()) { |
| 2125 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2126 | return SetUB(BO->getRHS(), |
| 2127 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2128 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2129 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2130 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2131 | return SetUB(BO->getLHS(), |
| 2132 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2133 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2134 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2135 | } |
| 2136 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2137 | if (CE->getNumArgs() == 2) { |
| 2138 | auto Op = CE->getOperator(); |
| 2139 | switch (Op) { |
| 2140 | case OO_Greater: |
| 2141 | case OO_GreaterEqual: |
| 2142 | case OO_Less: |
| 2143 | case OO_LessEqual: |
| 2144 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2145 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2146 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2147 | CE->getOperatorLoc()); |
| 2148 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2149 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2150 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2151 | CE->getOperatorLoc()); |
| 2152 | break; |
| 2153 | default: |
| 2154 | break; |
| 2155 | } |
| 2156 | } |
| 2157 | } |
| 2158 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2159 | << S->getSourceRange() << Var; |
| 2160 | return true; |
| 2161 | } |
| 2162 | |
| 2163 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2164 | // RHS of canonical loop form increment can be: |
| 2165 | // var + incr |
| 2166 | // incr + var |
| 2167 | // var - incr |
| 2168 | // |
| 2169 | RHS = RHS->IgnoreParenImpCasts(); |
| 2170 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2171 | if (BO->isAdditiveOp()) { |
| 2172 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2173 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2174 | return SetStep(BO->getRHS(), !IsAdd); |
| 2175 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2176 | return SetStep(BO->getLHS(), false); |
| 2177 | } |
| 2178 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2179 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2180 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2181 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2182 | return SetStep(CE->getArg(1), !IsAdd); |
| 2183 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2184 | return SetStep(CE->getArg(0), false); |
| 2185 | } |
| 2186 | } |
| 2187 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2188 | << RHS->getSourceRange() << Var; |
| 2189 | return true; |
| 2190 | } |
| 2191 | |
| 2192 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2193 | // Check incr-expr for canonical loop form and return true if it |
| 2194 | // does not conform. |
| 2195 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2196 | // ++var |
| 2197 | // var++ |
| 2198 | // --var |
| 2199 | // var-- |
| 2200 | // var += incr |
| 2201 | // var -= incr |
| 2202 | // var = var + incr |
| 2203 | // var = incr + var |
| 2204 | // var = var - incr |
| 2205 | // |
| 2206 | if (!S) { |
| 2207 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2208 | return true; |
| 2209 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2210 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2211 | S = S->IgnoreParens(); |
| 2212 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2213 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2214 | return SetStep( |
| 2215 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2216 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2217 | false); |
| 2218 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2219 | switch (BO->getOpcode()) { |
| 2220 | case BO_AddAssign: |
| 2221 | case BO_SubAssign: |
| 2222 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2223 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2224 | break; |
| 2225 | case BO_Assign: |
| 2226 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2227 | return CheckIncRHS(BO->getRHS()); |
| 2228 | break; |
| 2229 | default: |
| 2230 | break; |
| 2231 | } |
| 2232 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2233 | switch (CE->getOperator()) { |
| 2234 | case OO_PlusPlus: |
| 2235 | case OO_MinusMinus: |
| 2236 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2237 | return SetStep( |
| 2238 | SemaRef.ActOnIntegerConstant( |
| 2239 | CE->getLocStart(), |
| 2240 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2241 | false); |
| 2242 | break; |
| 2243 | case OO_PlusEqual: |
| 2244 | case OO_MinusEqual: |
| 2245 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2246 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2247 | break; |
| 2248 | case OO_Equal: |
| 2249 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2250 | return CheckIncRHS(CE->getArg(1)); |
| 2251 | break; |
| 2252 | default: |
| 2253 | break; |
| 2254 | } |
| 2255 | } |
| 2256 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2257 | << S->getSourceRange() << Var; |
| 2258 | return true; |
| 2259 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2260 | |
| 2261 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2262 | Expr * |
| 2263 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2264 | const bool LimitedType) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2265 | ExprResult Diff; |
| 2266 | if (Var->getType()->isIntegerType() || Var->getType()->isPointerType() || |
| 2267 | SemaRef.getLangOpts().CPlusPlus) { |
| 2268 | // Upper - Lower |
| 2269 | Expr *Upper = TestIsLessOp ? UB : LB; |
| 2270 | Expr *Lower = TestIsLessOp ? LB : UB; |
| 2271 | |
| 2272 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2273 | |
| 2274 | if (!Diff.isUsable() && Var->getType()->getAsCXXRecordDecl()) { |
| 2275 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2276 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2277 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2278 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2279 | return nullptr; |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | if (!Diff.isUsable()) |
| 2284 | return nullptr; |
| 2285 | |
| 2286 | // Upper - Lower [- 1] |
| 2287 | if (TestIsStrictOp) |
| 2288 | Diff = SemaRef.BuildBinOp( |
| 2289 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2290 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2291 | if (!Diff.isUsable()) |
| 2292 | return nullptr; |
| 2293 | |
| 2294 | // Upper - Lower [- 1] + Step |
| 2295 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), |
| 2296 | Step->IgnoreImplicit()); |
| 2297 | if (!Diff.isUsable()) |
| 2298 | return nullptr; |
| 2299 | |
| 2300 | // Parentheses (for dumping/debugging purposes only). |
| 2301 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 2302 | if (!Diff.isUsable()) |
| 2303 | return nullptr; |
| 2304 | |
| 2305 | // (Upper - Lower [- 1] + Step) / Step |
| 2306 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), |
| 2307 | Step->IgnoreImplicit()); |
| 2308 | if (!Diff.isUsable()) |
| 2309 | return nullptr; |
| 2310 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2311 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
| 2312 | if (LimitedType) { |
| 2313 | auto &C = SemaRef.Context; |
| 2314 | QualType Type = Diff.get()->getType(); |
| 2315 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 2316 | if (NewSize != C.getTypeSize(Type)) { |
| 2317 | if (NewSize < C.getTypeSize(Type)) { |
| 2318 | assert(NewSize == 64 && "incorrect loop var size"); |
| 2319 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 2320 | << InitSrcRange << ConditionSrcRange; |
| 2321 | } |
| 2322 | QualType NewType = C.getIntTypeForBitwidth( |
| 2323 | NewSize, Type->hasSignedIntegerRepresentation()); |
| 2324 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 2325 | Sema::AA_Converting, true); |
| 2326 | if (!Diff.isUsable()) |
| 2327 | return nullptr; |
| 2328 | } |
| 2329 | } |
| 2330 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2331 | return Diff.get(); |
| 2332 | } |
| 2333 | |
| 2334 | /// \brief Build reference expression to the counter be used for codegen. |
| 2335 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
| 2336 | return DeclRefExpr::Create(SemaRef.Context, NestedNameSpecifierLoc(), |
| 2337 | GetIncrementSrcRange().getBegin(), Var, false, |
| 2338 | DefaultLoc, Var->getType(), VK_LValue); |
| 2339 | } |
| 2340 | |
| 2341 | /// \brief Build initization of the counter be used for codegen. |
| 2342 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 2343 | |
| 2344 | /// \brief Build step of the counter be used for codegen. |
| 2345 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 2346 | |
| 2347 | /// \brief Iteration space of a single for loop. |
| 2348 | struct LoopIterationSpace { |
| 2349 | /// \brief This expression calculates the number of iterations in the loop. |
| 2350 | /// It is always possible to calculate it before starting the loop. |
| 2351 | Expr *NumIterations; |
| 2352 | /// \brief The loop counter variable. |
| 2353 | Expr *CounterVar; |
| 2354 | /// \brief This is initializer for the initial value of #CounterVar. |
| 2355 | Expr *CounterInit; |
| 2356 | /// \brief This is step for the #CounterVar used to generate its update: |
| 2357 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 2358 | Expr *CounterStep; |
| 2359 | /// \brief Should step be subtracted? |
| 2360 | bool Subtract; |
| 2361 | /// \brief Source range of the loop init. |
| 2362 | SourceRange InitSrcRange; |
| 2363 | /// \brief Source range of the loop condition. |
| 2364 | SourceRange CondSrcRange; |
| 2365 | /// \brief Source range of the loop increment. |
| 2366 | SourceRange IncSrcRange; |
| 2367 | }; |
| 2368 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2369 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2370 | |
| 2371 | /// \brief Called on a for stmt to check and extract its iteration space |
| 2372 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2373 | static bool CheckOpenMPIterationSpace( |
| 2374 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 2375 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
| 2376 | Expr *NestedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2377 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 2378 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2379 | // OpenMP [2.6, Canonical Loop Form] |
| 2380 | // for (init-expr; test-expr; incr-expr) structured-block |
| 2381 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 2382 | if (!For) { |
| 2383 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2384 | << (NestedLoopCountExpr != nullptr) << getOpenMPDirectiveName(DKind) |
| 2385 | << NestedLoopCount << (CurrentNestedLoopCount > 0) |
| 2386 | << CurrentNestedLoopCount; |
| 2387 | if (NestedLoopCount > 1) |
| 2388 | SemaRef.Diag(NestedLoopCountExpr->getExprLoc(), |
| 2389 | diag::note_omp_collapse_expr) |
| 2390 | << NestedLoopCountExpr->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2391 | return true; |
| 2392 | } |
| 2393 | assert(For->getBody()); |
| 2394 | |
| 2395 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 2396 | |
| 2397 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2398 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2399 | if (ISC.CheckInit(Init)) { |
| 2400 | return true; |
| 2401 | } |
| 2402 | |
| 2403 | bool HasErrors = false; |
| 2404 | |
| 2405 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2406 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2407 | |
| 2408 | // OpenMP [2.6, Canonical Loop Form] |
| 2409 | // Var is one of the following: |
| 2410 | // A variable of signed or unsigned integer type. |
| 2411 | // For C++, a variable of a random access iterator type. |
| 2412 | // For C, a variable of a pointer type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2413 | auto VarType = Var->getType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2414 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 2415 | !VarType->isPointerType() && |
| 2416 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 2417 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 2418 | << SemaRef.getLangOpts().CPlusPlus; |
| 2419 | HasErrors = true; |
| 2420 | } |
| 2421 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2422 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 2423 | // Construct |
| 2424 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2425 | // parallel for construct is (are) private. |
| 2426 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2427 | // with just one associated for-loop is linear with a constant-linear-step |
| 2428 | // that is the increment of the associated for-loop. |
| 2429 | // Exclude loop var from the list of variables with implicitly defined data |
| 2430 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 2431 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2432 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2433 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 2434 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 2435 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2436 | // with just one associated for-loop may be listed in a linear clause with a |
| 2437 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2438 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2439 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2440 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2441 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 2442 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 2443 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2444 | auto PredeterminedCKind = |
| 2445 | isOpenMPSimdDirective(DKind) |
| 2446 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 2447 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2448 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2449 | DVar.CKind != PredeterminedCKind) || |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2450 | (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && |
| 2451 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && |
| 2452 | DVar.CKind != OMPC_lastprivate)) && |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2453 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2454 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2455 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 2456 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2457 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2458 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2459 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2460 | // Make the loop iteration variable private (for worksharing constructs), |
| 2461 | // linear (for simd directives with the only one associated loop) or |
| 2462 | // lastprivate (for simd directives with several collapsed loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 2463 | // FIXME: the next check and error message must be removed once the |
| 2464 | // capturing of global variables in loops is fixed. |
| 2465 | if (DVar.CKind == OMPC_unknown) |
| 2466 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 2467 | /*FromParent=*/false); |
| 2468 | if (!Var->hasLocalStorage() && DVar.CKind == OMPC_unknown) { |
| 2469 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_global_loop_var_dsa) |
| 2470 | << getOpenMPClauseName(PredeterminedCKind) |
| 2471 | << getOpenMPDirectiveName(DKind); |
| 2472 | HasErrors = true; |
| 2473 | } else |
| 2474 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2477 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2478 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2479 | // Check test-expr. |
| 2480 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 2481 | |
| 2482 | // Check incr-expr. |
| 2483 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 2484 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2485 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2486 | return HasErrors; |
| 2487 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2488 | // Build the loop's iteration space representation. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2489 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
| 2490 | DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2491 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
| 2492 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 2493 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 2494 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 2495 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 2496 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 2497 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 2498 | |
| 2499 | HasErrors |= (ResultIterSpace.NumIterations == nullptr || |
| 2500 | ResultIterSpace.CounterVar == nullptr || |
| 2501 | ResultIterSpace.CounterInit == nullptr || |
| 2502 | ResultIterSpace.CounterStep == nullptr); |
| 2503 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2504 | return HasErrors; |
| 2505 | } |
| 2506 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2507 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 2508 | static VarDecl *BuildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
| 2509 | StringRef Name) { |
| 2510 | DeclContext *DC = SemaRef.CurContext; |
| 2511 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 2512 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 2513 | VarDecl *Decl = |
| 2514 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
| 2515 | Decl->setImplicit(); |
| 2516 | return Decl; |
| 2517 | } |
| 2518 | |
| 2519 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 2520 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 2521 | SourceLocation Loc, ExprResult VarRef, |
| 2522 | ExprResult Start, ExprResult Iter, |
| 2523 | ExprResult Step, bool Subtract) { |
| 2524 | // Add parentheses (for debugging purposes only). |
| 2525 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 2526 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 2527 | !Step.isUsable()) |
| 2528 | return ExprError(); |
| 2529 | |
| 2530 | ExprResult Update = SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), |
| 2531 | Step.get()->IgnoreImplicit()); |
| 2532 | if (!Update.isUsable()) |
| 2533 | return ExprError(); |
| 2534 | |
| 2535 | // Build 'VarRef = Start + Iter * Step'. |
| 2536 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
| 2537 | Start.get()->IgnoreImplicit(), Update.get()); |
| 2538 | if (!Update.isUsable()) |
| 2539 | return ExprError(); |
| 2540 | |
| 2541 | Update = SemaRef.PerformImplicitConversion( |
| 2542 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 2543 | if (!Update.isUsable()) |
| 2544 | return ExprError(); |
| 2545 | |
| 2546 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 2547 | return Update; |
| 2548 | } |
| 2549 | |
| 2550 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 2551 | /// bits. |
| 2552 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 2553 | Sema &SemaRef) { |
| 2554 | if (E == nullptr) |
| 2555 | return ExprError(); |
| 2556 | auto &C = SemaRef.Context; |
| 2557 | QualType OldType = E->getType(); |
| 2558 | unsigned HasBits = C.getTypeSize(OldType); |
| 2559 | if (HasBits >= Bits) |
| 2560 | return ExprResult(E); |
| 2561 | // OK to convert to signed, because new type has more bits than old. |
| 2562 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 2563 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 2564 | true); |
| 2565 | } |
| 2566 | |
| 2567 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 2568 | /// into \a Bits bits. |
| 2569 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 2570 | if (E == nullptr) |
| 2571 | return false; |
| 2572 | llvm::APSInt Result; |
| 2573 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 2574 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 2575 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | /// \brief Called on a for stmt to check itself and nested loops (if any). |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 2579 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 2580 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2581 | static unsigned |
| 2582 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *NestedLoopCountExpr, |
| 2583 | Stmt *AStmt, Sema &SemaRef, DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2584 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2585 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2586 | unsigned NestedLoopCount = 1; |
| 2587 | if (NestedLoopCountExpr) { |
| 2588 | // Found 'collapse' clause - calculate collapse number. |
| 2589 | llvm::APSInt Result; |
| 2590 | if (NestedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 2591 | NestedLoopCount = Result.getLimitedValue(); |
| 2592 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2593 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 2594 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2595 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 2596 | IterSpaces.resize(NestedLoopCount); |
| 2597 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2598 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2599 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2600 | NestedLoopCount, NestedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2601 | VarsWithImplicitDSA, IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 2602 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2603 | // Move on to the next nested for loop, or to the loop body. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2604 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2605 | // All loops associated with the construct must be perfectly nested; that |
| 2606 | // is, there must be no intervening code nor any OpenMP directive between |
| 2607 | // any two loops. |
| 2608 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2609 | } |
| 2610 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2611 | Built.clear(/* size */ NestedLoopCount); |
| 2612 | |
| 2613 | if (SemaRef.CurContext->isDependentContext()) |
| 2614 | return NestedLoopCount; |
| 2615 | |
| 2616 | // An example of what is generated for the following code: |
| 2617 | // |
| 2618 | // #pragma omp simd collapse(2) |
| 2619 | // for (i = 0; i < NI; ++i) |
| 2620 | // for (j = J0; j < NJ; j+=2) { |
| 2621 | // <loop body> |
| 2622 | // } |
| 2623 | // |
| 2624 | // We generate the code below. |
| 2625 | // Note: the loop body may be outlined in CodeGen. |
| 2626 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 2627 | // iterations and operator+= to calculate counter value. |
| 2628 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 2629 | // or i64 is currently supported). |
| 2630 | // |
| 2631 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 2632 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 2633 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 2634 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 2635 | // // similar updates for vars in clauses (e.g. 'linear') |
| 2636 | // <loop body (using local i and j)> |
| 2637 | // } |
| 2638 | // i = NI; // assign final values of counters |
| 2639 | // j = NJ; |
| 2640 | // |
| 2641 | |
| 2642 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 2643 | // the iteration counts of the collapsed for loops. |
| 2644 | auto N0 = IterSpaces[0].NumIterations; |
| 2645 | ExprResult LastIteration32 = WidenIterationCount(32 /* Bits */, N0, SemaRef); |
| 2646 | ExprResult LastIteration64 = WidenIterationCount(64 /* Bits */, N0, SemaRef); |
| 2647 | |
| 2648 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 2649 | return NestedLoopCount; |
| 2650 | |
| 2651 | auto &C = SemaRef.Context; |
| 2652 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 2653 | |
| 2654 | Scope *CurScope = DSA.getCurScope(); |
| 2655 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
| 2656 | auto N = IterSpaces[Cnt].NumIterations; |
| 2657 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 2658 | if (LastIteration32.isUsable()) |
| 2659 | LastIteration32 = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_Mul, |
| 2660 | LastIteration32.get(), N); |
| 2661 | if (LastIteration64.isUsable()) |
| 2662 | LastIteration64 = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_Mul, |
| 2663 | LastIteration64.get(), N); |
| 2664 | } |
| 2665 | |
| 2666 | // Choose either the 32-bit or 64-bit version. |
| 2667 | ExprResult LastIteration = LastIteration64; |
| 2668 | if (LastIteration32.isUsable() && |
| 2669 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 2670 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 2671 | FitsInto( |
| 2672 | 32 /* Bits */, |
| 2673 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 2674 | LastIteration64.get(), SemaRef))) |
| 2675 | LastIteration = LastIteration32; |
| 2676 | |
| 2677 | if (!LastIteration.isUsable()) |
| 2678 | return 0; |
| 2679 | |
| 2680 | // Save the number of iterations. |
| 2681 | ExprResult NumIterations = LastIteration; |
| 2682 | { |
| 2683 | LastIteration = SemaRef.BuildBinOp( |
| 2684 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 2685 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2686 | if (!LastIteration.isUsable()) |
| 2687 | return 0; |
| 2688 | } |
| 2689 | |
| 2690 | // Calculate the last iteration number beforehand instead of doing this on |
| 2691 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 2692 | llvm::APSInt Result; |
| 2693 | bool IsConstant = |
| 2694 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2695 | ExprResult CalcLastIteration; |
| 2696 | if (!IsConstant) { |
| 2697 | SourceLocation SaveLoc; |
| 2698 | VarDecl *SaveVar = |
| 2699 | BuildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
| 2700 | ".omp.last.iteration"); |
| 2701 | ExprResult SaveRef = SemaRef.BuildDeclRefExpr( |
| 2702 | SaveVar, LastIteration.get()->getType(), VK_LValue, SaveLoc); |
| 2703 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 2704 | SaveRef.get(), LastIteration.get()); |
| 2705 | LastIteration = SaveRef; |
| 2706 | |
| 2707 | // Prepare SaveRef + 1. |
| 2708 | NumIterations = SemaRef.BuildBinOp( |
| 2709 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 2710 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2711 | if (!NumIterations.isUsable()) |
| 2712 | return 0; |
| 2713 | } |
| 2714 | |
| 2715 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 2716 | |
| 2717 | // Precondition tests if there is at least one iteration (LastIteration > 0). |
| 2718 | ExprResult PreCond = SemaRef.BuildBinOp( |
| 2719 | CurScope, InitLoc, BO_GT, LastIteration.get(), |
| 2720 | SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get()); |
| 2721 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2722 | QualType VType = LastIteration.get()->getType(); |
| 2723 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 2724 | ExprResult LB, UB, IL, ST, EUB; |
| 2725 | if (isOpenMPWorksharingDirective(DKind)) { |
| 2726 | // Lower bound variable, initialized with zero. |
| 2727 | VarDecl *LBDecl = BuildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 2728 | LB = SemaRef.BuildDeclRefExpr(LBDecl, VType, VK_LValue, InitLoc); |
| 2729 | SemaRef.AddInitializerToDecl( |
| 2730 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 2731 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 2732 | |
| 2733 | // Upper bound variable, initialized with last iteration number. |
| 2734 | VarDecl *UBDecl = BuildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 2735 | UB = SemaRef.BuildDeclRefExpr(UBDecl, VType, VK_LValue, InitLoc); |
| 2736 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 2737 | /*DirectInit*/ false, |
| 2738 | /*TypeMayContainAuto*/ false); |
| 2739 | |
| 2740 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 2741 | // This will be used to implement clause 'lastprivate'. |
| 2742 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
| 2743 | VarDecl *ILDecl = BuildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 2744 | IL = SemaRef.BuildDeclRefExpr(ILDecl, Int32Ty, VK_LValue, InitLoc); |
| 2745 | SemaRef.AddInitializerToDecl( |
| 2746 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 2747 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 2748 | |
| 2749 | // Stride variable returned by runtime (we initialize it to 1 by default). |
| 2750 | VarDecl *STDecl = BuildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 2751 | ST = SemaRef.BuildDeclRefExpr(STDecl, VType, VK_LValue, InitLoc); |
| 2752 | SemaRef.AddInitializerToDecl( |
| 2753 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 2754 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 2755 | |
| 2756 | // Build expression: UB = min(UB, LastIteration) |
| 2757 | // It is nesessary for CodeGen of directives with static scheduling. |
| 2758 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 2759 | UB.get(), LastIteration.get()); |
| 2760 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 2761 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 2762 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 2763 | CondOp.get()); |
| 2764 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 2765 | } |
| 2766 | |
| 2767 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2768 | ExprResult IV; |
| 2769 | ExprResult Init; |
| 2770 | { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2771 | VarDecl *IVDecl = BuildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 2772 | IV = SemaRef.BuildDeclRefExpr(IVDecl, VType, VK_LValue, InitLoc); |
| 2773 | Expr *RHS = isOpenMPWorksharingDirective(DKind) |
| 2774 | ? LB.get() |
| 2775 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 2776 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 2777 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2780 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2781 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2782 | ExprResult Cond = |
| 2783 | isOpenMPWorksharingDirective(DKind) |
| 2784 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 2785 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 2786 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2787 | // Loop condition with 1 iteration separated (IV < LastIteration) |
| 2788 | ExprResult SeparatedCond = SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, |
| 2789 | IV.get(), LastIteration.get()); |
| 2790 | |
| 2791 | // Loop increment (IV = IV + 1) |
| 2792 | SourceLocation IncLoc; |
| 2793 | ExprResult Inc = |
| 2794 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 2795 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 2796 | if (!Inc.isUsable()) |
| 2797 | return 0; |
| 2798 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2799 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 2800 | if (!Inc.isUsable()) |
| 2801 | return 0; |
| 2802 | |
| 2803 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 2804 | // Used for directives with static scheduling. |
| 2805 | ExprResult NextLB, NextUB; |
| 2806 | if (isOpenMPWorksharingDirective(DKind)) { |
| 2807 | // LB + ST |
| 2808 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 2809 | if (!NextLB.isUsable()) |
| 2810 | return 0; |
| 2811 | // LB = LB + ST |
| 2812 | NextLB = |
| 2813 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 2814 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 2815 | if (!NextLB.isUsable()) |
| 2816 | return 0; |
| 2817 | // UB + ST |
| 2818 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 2819 | if (!NextUB.isUsable()) |
| 2820 | return 0; |
| 2821 | // UB = UB + ST |
| 2822 | NextUB = |
| 2823 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 2824 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 2825 | if (!NextUB.isUsable()) |
| 2826 | return 0; |
| 2827 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2828 | |
| 2829 | // Build updates and final values of the loop counters. |
| 2830 | bool HasErrors = false; |
| 2831 | Built.Counters.resize(NestedLoopCount); |
| 2832 | Built.Updates.resize(NestedLoopCount); |
| 2833 | Built.Finals.resize(NestedLoopCount); |
| 2834 | { |
| 2835 | ExprResult Div; |
| 2836 | // Go from inner nested loop to outer. |
| 2837 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 2838 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 2839 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 2840 | // Build: Iter = (IV / Div) % IS.NumIters |
| 2841 | // where Div is product of previous iterations' IS.NumIters. |
| 2842 | ExprResult Iter; |
| 2843 | if (Div.isUsable()) { |
| 2844 | Iter = |
| 2845 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 2846 | } else { |
| 2847 | Iter = IV; |
| 2848 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 2849 | "unusable div expected on first iteration only"); |
| 2850 | } |
| 2851 | |
| 2852 | if (Cnt != 0 && Iter.isUsable()) |
| 2853 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 2854 | IS.NumIterations); |
| 2855 | if (!Iter.isUsable()) { |
| 2856 | HasErrors = true; |
| 2857 | break; |
| 2858 | } |
| 2859 | |
| 2860 | // Build update: IS.CounterVar = IS.Start + Iter * IS.Step |
| 2861 | ExprResult Update = |
| 2862 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, IS.CounterVar, |
| 2863 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 2864 | if (!Update.isUsable()) { |
| 2865 | HasErrors = true; |
| 2866 | break; |
| 2867 | } |
| 2868 | |
| 2869 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 2870 | ExprResult Final = BuildCounterUpdate( |
| 2871 | SemaRef, CurScope, UpdLoc, IS.CounterVar, IS.CounterInit, |
| 2872 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 2873 | if (!Final.isUsable()) { |
| 2874 | HasErrors = true; |
| 2875 | break; |
| 2876 | } |
| 2877 | |
| 2878 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 2879 | if (Cnt != 0) { |
| 2880 | if (Div.isUnset()) |
| 2881 | Div = IS.NumIterations; |
| 2882 | else |
| 2883 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 2884 | IS.NumIterations); |
| 2885 | |
| 2886 | // Add parentheses (for debugging purposes only). |
| 2887 | if (Div.isUsable()) |
| 2888 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 2889 | if (!Div.isUsable()) { |
| 2890 | HasErrors = true; |
| 2891 | break; |
| 2892 | } |
| 2893 | } |
| 2894 | if (!Update.isUsable() || !Final.isUsable()) { |
| 2895 | HasErrors = true; |
| 2896 | break; |
| 2897 | } |
| 2898 | // Save results |
| 2899 | Built.Counters[Cnt] = IS.CounterVar; |
| 2900 | Built.Updates[Cnt] = Update.get(); |
| 2901 | Built.Finals[Cnt] = Final.get(); |
| 2902 | } |
| 2903 | } |
| 2904 | |
| 2905 | if (HasErrors) |
| 2906 | return 0; |
| 2907 | |
| 2908 | // Save results |
| 2909 | Built.IterationVarRef = IV.get(); |
| 2910 | Built.LastIteration = LastIteration.get(); |
| 2911 | Built.CalcLastIteration = CalcLastIteration.get(); |
| 2912 | Built.PreCond = PreCond.get(); |
| 2913 | Built.Cond = Cond.get(); |
| 2914 | Built.SeparatedCond = SeparatedCond.get(); |
| 2915 | Built.Init = Init.get(); |
| 2916 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2917 | Built.LB = LB.get(); |
| 2918 | Built.UB = UB.get(); |
| 2919 | Built.IL = IL.get(); |
| 2920 | Built.ST = ST.get(); |
| 2921 | Built.EUB = EUB.get(); |
| 2922 | Built.NLB = NextLB.get(); |
| 2923 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2924 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 2925 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2926 | } |
| 2927 | |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2928 | static Expr *GetCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2929 | auto CollapseFilter = [](const OMPClause *C) -> bool { |
| 2930 | return C->getClauseKind() == OMPC_collapse; |
| 2931 | }; |
| 2932 | OMPExecutableDirective::filtered_clause_iterator<decltype(CollapseFilter)> I( |
| 2933 | Clauses, CollapseFilter); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2934 | if (I) |
| 2935 | return cast<OMPCollapseClause>(*I)->getNumForLoops(); |
| 2936 | return nullptr; |
| 2937 | } |
| 2938 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2939 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 2940 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 2941 | SourceLocation EndLoc, |
| 2942 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2943 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2944 | // In presence of clause 'collapse', it will define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2945 | unsigned NestedLoopCount = |
| 2946 | CheckOpenMPLoop(OMPD_simd, GetCollapseNumberExpr(Clauses), AStmt, *this, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2947 | *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 2948 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2949 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2950 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2951 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 2952 | "omp simd loop exprs were not built"); |
| 2953 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2954 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2955 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 2956 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2959 | StmtResult Sema::ActOnOpenMPForDirective( |
| 2960 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 2961 | SourceLocation EndLoc, |
| 2962 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2963 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2964 | // In presence of clause 'collapse', it will define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2965 | unsigned NestedLoopCount = |
| 2966 | CheckOpenMPLoop(OMPD_for, GetCollapseNumberExpr(Clauses), AStmt, *this, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2967 | *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 2968 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2969 | return StmtError(); |
| 2970 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2971 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 2972 | "omp for loop exprs were not built"); |
| 2973 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2974 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2975 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 2976 | Clauses, AStmt, B); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2977 | } |
| 2978 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2979 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 2980 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 2981 | SourceLocation EndLoc, |
| 2982 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2983 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2984 | // In presence of clause 'collapse', it will define the nested loops number. |
| 2985 | unsigned NestedLoopCount = |
| 2986 | CheckOpenMPLoop(OMPD_for_simd, GetCollapseNumberExpr(Clauses), AStmt, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2987 | *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2988 | if (NestedLoopCount == 0) |
| 2989 | return StmtError(); |
| 2990 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2991 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 2992 | "omp for simd loop exprs were not built"); |
| 2993 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2994 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2995 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 2996 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2997 | } |
| 2998 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2999 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3000 | Stmt *AStmt, |
| 3001 | SourceLocation StartLoc, |
| 3002 | SourceLocation EndLoc) { |
| 3003 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3004 | auto BaseStmt = AStmt; |
| 3005 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3006 | BaseStmt = CS->getCapturedStmt(); |
| 3007 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3008 | auto S = C->children(); |
| 3009 | if (!S) |
| 3010 | return StmtError(); |
| 3011 | // All associated statements must be '#pragma omp section' except for |
| 3012 | // the first one. |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3013 | for (++S; S; ++S) { |
| 3014 | auto SectionStmt = *S; |
| 3015 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3016 | if (SectionStmt) |
| 3017 | Diag(SectionStmt->getLocStart(), |
| 3018 | diag::err_omp_sections_substmt_not_section); |
| 3019 | return StmtError(); |
| 3020 | } |
| 3021 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3022 | } else { |
| 3023 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 3024 | return StmtError(); |
| 3025 | } |
| 3026 | |
| 3027 | getCurFunction()->setHasBranchProtectedScope(); |
| 3028 | |
| 3029 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 3030 | AStmt); |
| 3031 | } |
| 3032 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3033 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 3034 | SourceLocation StartLoc, |
| 3035 | SourceLocation EndLoc) { |
| 3036 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3037 | |
| 3038 | getCurFunction()->setHasBranchProtectedScope(); |
| 3039 | |
| 3040 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3041 | } |
| 3042 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3043 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 3044 | Stmt *AStmt, |
| 3045 | SourceLocation StartLoc, |
| 3046 | SourceLocation EndLoc) { |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3047 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3048 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3049 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3050 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3051 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3052 | } |
| 3053 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3054 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 3055 | SourceLocation StartLoc, |
| 3056 | SourceLocation EndLoc) { |
| 3057 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3058 | |
| 3059 | getCurFunction()->setHasBranchProtectedScope(); |
| 3060 | |
| 3061 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3062 | } |
| 3063 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3064 | StmtResult |
| 3065 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 3066 | Stmt *AStmt, SourceLocation StartLoc, |
| 3067 | SourceLocation EndLoc) { |
| 3068 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3069 | |
| 3070 | getCurFunction()->setHasBranchProtectedScope(); |
| 3071 | |
| 3072 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 3073 | AStmt); |
| 3074 | } |
| 3075 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3076 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 3077 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3078 | SourceLocation EndLoc, |
| 3079 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3080 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3081 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3082 | // 1.2.2 OpenMP Language Terminology |
| 3083 | // Structured block - An executable statement with a single entry at the |
| 3084 | // top and a single exit at the bottom. |
| 3085 | // The point of exit cannot be a branch out of the structured block. |
| 3086 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3087 | CS->getCapturedDecl()->setNothrow(); |
| 3088 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3089 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3090 | // In presence of clause 'collapse', it will define the nested loops number. |
| 3091 | unsigned NestedLoopCount = |
| 3092 | CheckOpenMPLoop(OMPD_parallel_for, GetCollapseNumberExpr(Clauses), AStmt, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3093 | *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3094 | if (NestedLoopCount == 0) |
| 3095 | return StmtError(); |
| 3096 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3097 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3098 | "omp parallel for loop exprs were not built"); |
| 3099 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3100 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3101 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 3102 | NestedLoopCount, Clauses, AStmt, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3103 | } |
| 3104 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3105 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 3106 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3107 | SourceLocation EndLoc, |
| 3108 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3109 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3110 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3111 | // 1.2.2 OpenMP Language Terminology |
| 3112 | // Structured block - An executable statement with a single entry at the |
| 3113 | // top and a single exit at the bottom. |
| 3114 | // The point of exit cannot be a branch out of the structured block. |
| 3115 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3116 | CS->getCapturedDecl()->setNothrow(); |
| 3117 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3118 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3119 | // In presence of clause 'collapse', it will define the nested loops number. |
| 3120 | unsigned NestedLoopCount = |
| 3121 | CheckOpenMPLoop(OMPD_parallel_for_simd, GetCollapseNumberExpr(Clauses), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3122 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3123 | if (NestedLoopCount == 0) |
| 3124 | return StmtError(); |
| 3125 | |
| 3126 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3127 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3128 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3129 | } |
| 3130 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3131 | StmtResult |
| 3132 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3133 | Stmt *AStmt, SourceLocation StartLoc, |
| 3134 | SourceLocation EndLoc) { |
| 3135 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3136 | auto BaseStmt = AStmt; |
| 3137 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3138 | BaseStmt = CS->getCapturedStmt(); |
| 3139 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3140 | auto S = C->children(); |
| 3141 | if (!S) |
| 3142 | return StmtError(); |
| 3143 | // All associated statements must be '#pragma omp section' except for |
| 3144 | // the first one. |
| 3145 | for (++S; S; ++S) { |
| 3146 | auto SectionStmt = *S; |
| 3147 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3148 | if (SectionStmt) |
| 3149 | Diag(SectionStmt->getLocStart(), |
| 3150 | diag::err_omp_parallel_sections_substmt_not_section); |
| 3151 | return StmtError(); |
| 3152 | } |
| 3153 | } |
| 3154 | } else { |
| 3155 | Diag(AStmt->getLocStart(), |
| 3156 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 3157 | return StmtError(); |
| 3158 | } |
| 3159 | |
| 3160 | getCurFunction()->setHasBranchProtectedScope(); |
| 3161 | |
| 3162 | return OMPParallelSectionsDirective::Create(Context, StartLoc, EndLoc, |
| 3163 | Clauses, AStmt); |
| 3164 | } |
| 3165 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3166 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 3167 | Stmt *AStmt, SourceLocation StartLoc, |
| 3168 | SourceLocation EndLoc) { |
| 3169 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3170 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3171 | // 1.2.2 OpenMP Language Terminology |
| 3172 | // Structured block - An executable statement with a single entry at the |
| 3173 | // top and a single exit at the bottom. |
| 3174 | // The point of exit cannot be a branch out of the structured block. |
| 3175 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3176 | CS->getCapturedDecl()->setNothrow(); |
| 3177 | |
| 3178 | getCurFunction()->setHasBranchProtectedScope(); |
| 3179 | |
| 3180 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3181 | } |
| 3182 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3183 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 3184 | SourceLocation EndLoc) { |
| 3185 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 3186 | } |
| 3187 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3188 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 3189 | SourceLocation EndLoc) { |
| 3190 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 3191 | } |
| 3192 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3193 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 3194 | SourceLocation EndLoc) { |
| 3195 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 3196 | } |
| 3197 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3198 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 3199 | SourceLocation StartLoc, |
| 3200 | SourceLocation EndLoc) { |
| 3201 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 3202 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 3203 | } |
| 3204 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3205 | StmtResult Sema::ActOnOpenMPOrderedDirective(Stmt *AStmt, |
| 3206 | SourceLocation StartLoc, |
| 3207 | SourceLocation EndLoc) { |
| 3208 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3209 | |
| 3210 | getCurFunction()->setHasBranchProtectedScope(); |
| 3211 | |
| 3212 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3213 | } |
| 3214 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3215 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 3216 | Stmt *AStmt, |
| 3217 | SourceLocation StartLoc, |
| 3218 | SourceLocation EndLoc) { |
| 3219 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3220 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3221 | // 1.2.2 OpenMP Language Terminology |
| 3222 | // Structured block - An executable statement with a single entry at the |
| 3223 | // top and a single exit at the bottom. |
| 3224 | // The point of exit cannot be a branch out of the structured block. |
| 3225 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3226 | // TODO further analysis of associated statements and clauses. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3227 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 3228 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3229 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3230 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3231 | C->getClauseKind() == OMPC_update || |
| 3232 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3233 | if (AtomicKind != OMPC_unknown) { |
| 3234 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 3235 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 3236 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 3237 | << getOpenMPClauseName(AtomicKind); |
| 3238 | } else { |
| 3239 | AtomicKind = C->getClauseKind(); |
| 3240 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3241 | } |
| 3242 | } |
| 3243 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3244 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3245 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3246 | Expr *X = nullptr; |
| 3247 | Expr *V = nullptr; |
| 3248 | Expr *E = nullptr; |
| 3249 | // OpenMP [2.12.6, atomic Construct] |
| 3250 | // In the next expressions: |
| 3251 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 3252 | // * During the execution of an atomic region, multiple syntactic |
| 3253 | // occurrences of x must designate the same storage location. |
| 3254 | // * Neither of v and expr (as applicable) may access the storage location |
| 3255 | // designated by x. |
| 3256 | // * Neither of x and expr (as applicable) may access the storage location |
| 3257 | // designated by v. |
| 3258 | // * expr is an expression with scalar type. |
| 3259 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 3260 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 3261 | // * The expression x binop expr must be numerically equivalent to x binop |
| 3262 | // (expr). This requirement is satisfied if the operators in expr have |
| 3263 | // precedence greater than binop, or by using parentheses around expr or |
| 3264 | // subexpressions of expr. |
| 3265 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 3266 | // binop x. This requirement is satisfied if the operators in expr have |
| 3267 | // precedence equal to or greater than binop, or by using parentheses around |
| 3268 | // expr or subexpressions of expr. |
| 3269 | // * For forms that allow multiple occurrences of x, the number of times |
| 3270 | // that x is evaluated is unspecified. |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3271 | enum { |
| 3272 | NotAnExpression, |
| 3273 | NotAnAssignmentOp, |
| 3274 | NotAScalarType, |
| 3275 | NotAnLValue, |
| 3276 | NoError |
| 3277 | } ErrorFound = NoError; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3278 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3279 | SourceLocation ErrorLoc, NoteLoc; |
| 3280 | SourceRange ErrorRange, NoteRange; |
| 3281 | // If clause is read: |
| 3282 | // v = x; |
| 3283 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 3284 | auto AtomicBinOp = |
| 3285 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 3286 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 3287 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 3288 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 3289 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 3290 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 3291 | if (!X->isLValue() || !V->isLValue()) { |
| 3292 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 3293 | ErrorFound = NotAnLValue; |
| 3294 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3295 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3296 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 3297 | NoteRange = NotLValueExpr->getSourceRange(); |
| 3298 | } |
| 3299 | } else if (!X->isInstantiationDependent() || |
| 3300 | !V->isInstantiationDependent()) { |
| 3301 | auto NotScalarExpr = |
| 3302 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 3303 | ? V |
| 3304 | : X; |
| 3305 | ErrorFound = NotAScalarType; |
| 3306 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3307 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3308 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 3309 | NoteRange = NotScalarExpr->getSourceRange(); |
| 3310 | } |
| 3311 | } else { |
| 3312 | ErrorFound = NotAnAssignmentOp; |
| 3313 | ErrorLoc = AtomicBody->getExprLoc(); |
| 3314 | ErrorRange = AtomicBody->getSourceRange(); |
| 3315 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 3316 | : AtomicBody->getExprLoc(); |
| 3317 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 3318 | : AtomicBody->getSourceRange(); |
| 3319 | } |
| 3320 | } else { |
| 3321 | ErrorFound = NotAnExpression; |
| 3322 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 3323 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3324 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3325 | if (ErrorFound != NoError) { |
| 3326 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 3327 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3328 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 3329 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3330 | return StmtError(); |
| 3331 | } else if (CurContext->isDependentContext()) |
| 3332 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3333 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3334 | SourceLocation ErrorLoc, NoteLoc; |
| 3335 | SourceRange ErrorRange, NoteRange; |
| 3336 | // If clause is write: |
| 3337 | // x = expr; |
| 3338 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 3339 | auto AtomicBinOp = |
| 3340 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 3341 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 3342 | X = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 3343 | E = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 3344 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 3345 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 3346 | if (!X->isLValue()) { |
| 3347 | ErrorFound = NotAnLValue; |
| 3348 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3349 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3350 | NoteLoc = X->getExprLoc(); |
| 3351 | NoteRange = X->getSourceRange(); |
| 3352 | } |
| 3353 | } else if (!X->isInstantiationDependent() || |
| 3354 | !E->isInstantiationDependent()) { |
| 3355 | auto NotScalarExpr = |
| 3356 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 3357 | ? E |
| 3358 | : X; |
| 3359 | ErrorFound = NotAScalarType; |
| 3360 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3361 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3362 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 3363 | NoteRange = NotScalarExpr->getSourceRange(); |
| 3364 | } |
| 3365 | } else { |
| 3366 | ErrorFound = NotAnAssignmentOp; |
| 3367 | ErrorLoc = AtomicBody->getExprLoc(); |
| 3368 | ErrorRange = AtomicBody->getSourceRange(); |
| 3369 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 3370 | : AtomicBody->getExprLoc(); |
| 3371 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 3372 | : AtomicBody->getSourceRange(); |
| 3373 | } |
| 3374 | } else { |
| 3375 | ErrorFound = NotAnExpression; |
| 3376 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 3377 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3378 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3379 | if (ErrorFound != NoError) { |
| 3380 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 3381 | << ErrorRange; |
| 3382 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 3383 | << NoteRange; |
| 3384 | return StmtError(); |
| 3385 | } else if (CurContext->isDependentContext()) |
| 3386 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3387 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3388 | if (!isa<Expr>(Body)) { |
| 3389 | Diag(Body->getLocStart(), |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3390 | diag::err_omp_atomic_update_not_expression_statement) |
| 3391 | << (AtomicKind == OMPC_update); |
| 3392 | return StmtError(); |
| 3393 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3394 | } else if (AtomicKind == OMPC_capture) { |
| 3395 | if (isa<Expr>(Body) && !isa<BinaryOperator>(Body)) { |
| 3396 | Diag(Body->getLocStart(), |
| 3397 | diag::err_omp_atomic_capture_not_expression_statement); |
| 3398 | return StmtError(); |
| 3399 | } else if (!isa<Expr>(Body) && !isa<CompoundStmt>(Body)) { |
| 3400 | Diag(Body->getLocStart(), |
| 3401 | diag::err_omp_atomic_capture_not_compound_statement); |
| 3402 | return StmtError(); |
| 3403 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3404 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3405 | |
| 3406 | getCurFunction()->setHasBranchProtectedScope(); |
| 3407 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3408 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3409 | X, V, E); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3412 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 3413 | Stmt *AStmt, |
| 3414 | SourceLocation StartLoc, |
| 3415 | SourceLocation EndLoc) { |
| 3416 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3417 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3418 | // OpenMP [2.16, Nesting of Regions] |
| 3419 | // If specified, a teams construct must be contained within a target |
| 3420 | // construct. That target construct must contain no statements or directives |
| 3421 | // outside of the teams construct. |
| 3422 | if (DSAStack->hasInnerTeamsRegion()) { |
| 3423 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 3424 | bool OMPTeamsFound = true; |
| 3425 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 3426 | auto I = CS->body_begin(); |
| 3427 | while (I != CS->body_end()) { |
| 3428 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 3429 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 3430 | OMPTeamsFound = false; |
| 3431 | break; |
| 3432 | } |
| 3433 | ++I; |
| 3434 | } |
| 3435 | assert(I != CS->body_end() && "Not found statement"); |
| 3436 | S = *I; |
| 3437 | } |
| 3438 | if (!OMPTeamsFound) { |
| 3439 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 3440 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 3441 | diag::note_omp_nested_teams_construct_here); |
| 3442 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 3443 | << isa<OMPExecutableDirective>(S); |
| 3444 | return StmtError(); |
| 3445 | } |
| 3446 | } |
| 3447 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3448 | getCurFunction()->setHasBranchProtectedScope(); |
| 3449 | |
| 3450 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3451 | } |
| 3452 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3453 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 3454 | Stmt *AStmt, SourceLocation StartLoc, |
| 3455 | SourceLocation EndLoc) { |
| 3456 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3457 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3458 | // 1.2.2 OpenMP Language Terminology |
| 3459 | // Structured block - An executable statement with a single entry at the |
| 3460 | // top and a single exit at the bottom. |
| 3461 | // The point of exit cannot be a branch out of the structured block. |
| 3462 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3463 | CS->getCapturedDecl()->setNothrow(); |
| 3464 | |
| 3465 | getCurFunction()->setHasBranchProtectedScope(); |
| 3466 | |
| 3467 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3468 | } |
| 3469 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3470 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3471 | SourceLocation StartLoc, |
| 3472 | SourceLocation LParenLoc, |
| 3473 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3474 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3475 | switch (Kind) { |
| 3476 | case OMPC_if: |
| 3477 | Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 3478 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 3479 | case OMPC_final: |
| 3480 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 3481 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3482 | case OMPC_num_threads: |
| 3483 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 3484 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 3485 | case OMPC_safelen: |
| 3486 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 3487 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 3488 | case OMPC_collapse: |
| 3489 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 3490 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3491 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 3492 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 3493 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3494 | case OMPC_private: |
| 3495 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3496 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3497 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 3498 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3499 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 3500 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3501 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3502 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3503 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 3504 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 3505 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 3506 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3507 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3508 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3509 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3510 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3511 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3512 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 3513 | case OMPC_seq_cst: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3514 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3515 | llvm_unreachable("Clause is not allowed."); |
| 3516 | } |
| 3517 | return Res; |
| 3518 | } |
| 3519 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3520 | OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3521 | SourceLocation LParenLoc, |
| 3522 | SourceLocation EndLoc) { |
| 3523 | Expr *ValExpr = Condition; |
| 3524 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 3525 | !Condition->isInstantiationDependent() && |
| 3526 | !Condition->containsUnexpandedParameterPack()) { |
| 3527 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3528 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3529 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3530 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3531 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3532 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 3536 | } |
| 3537 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 3538 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 3539 | SourceLocation StartLoc, |
| 3540 | SourceLocation LParenLoc, |
| 3541 | SourceLocation EndLoc) { |
| 3542 | Expr *ValExpr = Condition; |
| 3543 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 3544 | !Condition->isInstantiationDependent() && |
| 3545 | !Condition->containsUnexpandedParameterPack()) { |
| 3546 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 3547 | Condition->getExprLoc(), Condition); |
| 3548 | if (Val.isInvalid()) |
| 3549 | return nullptr; |
| 3550 | |
| 3551 | ValExpr = Val.get(); |
| 3552 | } |
| 3553 | |
| 3554 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 3555 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3556 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 3557 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3558 | if (!Op) |
| 3559 | return ExprError(); |
| 3560 | |
| 3561 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 3562 | public: |
| 3563 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3564 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 3565 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 3566 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3567 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 3568 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3569 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 3570 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3571 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 3572 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3573 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 3574 | QualType T, |
| 3575 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3576 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 3577 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3578 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 3579 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3580 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3581 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3582 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3583 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 3584 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3585 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 3586 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3587 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 3588 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3589 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3590 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3591 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3592 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 3593 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3594 | llvm_unreachable("conversion functions are permitted"); |
| 3595 | } |
| 3596 | } ConvertDiagnoser; |
| 3597 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 3598 | } |
| 3599 | |
| 3600 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 3601 | SourceLocation StartLoc, |
| 3602 | SourceLocation LParenLoc, |
| 3603 | SourceLocation EndLoc) { |
| 3604 | Expr *ValExpr = NumThreads; |
| 3605 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3606 | !NumThreads->containsUnexpandedParameterPack()) { |
| 3607 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 3608 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3609 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3610 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3611 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3612 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3613 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3614 | |
| 3615 | // OpenMP [2.5, Restrictions] |
| 3616 | // The num_threads expression must evaluate to a positive integer value. |
| 3617 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3618 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 3619 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3620 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 3621 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3622 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3623 | } |
| 3624 | } |
| 3625 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3626 | return new (Context) |
| 3627 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3628 | } |
| 3629 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 3630 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 3631 | OpenMPClauseKind CKind) { |
| 3632 | if (!E) |
| 3633 | return ExprError(); |
| 3634 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3635 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 3636 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 3637 | llvm::APSInt Result; |
| 3638 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 3639 | if (ICE.isInvalid()) |
| 3640 | return ExprError(); |
| 3641 | if (!Result.isStrictlyPositive()) { |
| 3642 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 3643 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 3644 | return ExprError(); |
| 3645 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 3646 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 3647 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 3648 | << E->getSourceRange(); |
| 3649 | return ExprError(); |
| 3650 | } |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 3651 | return ICE; |
| 3652 | } |
| 3653 | |
| 3654 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 3655 | SourceLocation LParenLoc, |
| 3656 | SourceLocation EndLoc) { |
| 3657 | // OpenMP [2.8.1, simd construct, Description] |
| 3658 | // The parameter of the safelen clause must be a constant |
| 3659 | // positive integer expression. |
| 3660 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 3661 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3662 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 3663 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 3664 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 3667 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 3668 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 3669 | SourceLocation LParenLoc, |
| 3670 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 3671 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 3672 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 3673 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 3674 | // The parameter of the collapse clause must be a constant |
| 3675 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 3676 | ExprResult NumForLoopsResult = |
| 3677 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 3678 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 3679 | return nullptr; |
| 3680 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 3681 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 3682 | } |
| 3683 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3684 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 3685 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 3686 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3687 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3688 | switch (Kind) { |
| 3689 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3690 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3691 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 3692 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3693 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 3694 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3695 | Res = ActOnOpenMPProcBindClause( |
| 3696 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 3697 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 3698 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3699 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 3700 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 3701 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 3702 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 3703 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 3704 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3705 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3706 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3707 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3708 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 3709 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 3710 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 3711 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 3712 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3713 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3714 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 3715 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 3716 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 3717 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3718 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3719 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3720 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3721 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3722 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3723 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 3724 | case OMPC_seq_cst: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3725 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3726 | llvm_unreachable("Clause is not allowed."); |
| 3727 | } |
| 3728 | return Res; |
| 3729 | } |
| 3730 | |
| 3731 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 3732 | SourceLocation KindKwLoc, |
| 3733 | SourceLocation StartLoc, |
| 3734 | SourceLocation LParenLoc, |
| 3735 | SourceLocation EndLoc) { |
| 3736 | if (Kind == OMPC_DEFAULT_unknown) { |
| 3737 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 3738 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 3739 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 3740 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 3741 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3742 | Values += "'"; |
| 3743 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 3744 | Values += "'"; |
| 3745 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 3746 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3747 | Values += " or "; |
| 3748 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 3749 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3750 | break; |
| 3751 | default: |
| 3752 | Values += Sep; |
| 3753 | break; |
| 3754 | } |
| 3755 | } |
| 3756 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3757 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3758 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3759 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3760 | switch (Kind) { |
| 3761 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3762 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3763 | break; |
| 3764 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3765 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3766 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3767 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 3768 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3769 | break; |
| 3770 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3771 | return new (Context) |
| 3772 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 3775 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 3776 | SourceLocation KindKwLoc, |
| 3777 | SourceLocation StartLoc, |
| 3778 | SourceLocation LParenLoc, |
| 3779 | SourceLocation EndLoc) { |
| 3780 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 3781 | std::string Values; |
| 3782 | std::string Sep(", "); |
| 3783 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 3784 | Values += "'"; |
| 3785 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 3786 | Values += "'"; |
| 3787 | switch (i) { |
| 3788 | case OMPC_PROC_BIND_unknown - 2: |
| 3789 | Values += " or "; |
| 3790 | break; |
| 3791 | case OMPC_PROC_BIND_unknown - 1: |
| 3792 | break; |
| 3793 | default: |
| 3794 | Values += Sep; |
| 3795 | break; |
| 3796 | } |
| 3797 | } |
| 3798 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3799 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 3800 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 3801 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3802 | return new (Context) |
| 3803 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 3804 | } |
| 3805 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 3806 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 3807 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 3808 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 3809 | SourceLocation ArgumentLoc, SourceLocation CommaLoc, |
| 3810 | SourceLocation EndLoc) { |
| 3811 | OMPClause *Res = nullptr; |
| 3812 | switch (Kind) { |
| 3813 | case OMPC_schedule: |
| 3814 | Res = ActOnOpenMPScheduleClause( |
| 3815 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
| 3816 | LParenLoc, ArgumentLoc, CommaLoc, EndLoc); |
| 3817 | break; |
| 3818 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 3819 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 3820 | case OMPC_num_threads: |
| 3821 | case OMPC_safelen: |
| 3822 | case OMPC_collapse: |
| 3823 | case OMPC_default: |
| 3824 | case OMPC_proc_bind: |
| 3825 | case OMPC_private: |
| 3826 | case OMPC_firstprivate: |
| 3827 | case OMPC_lastprivate: |
| 3828 | case OMPC_shared: |
| 3829 | case OMPC_reduction: |
| 3830 | case OMPC_linear: |
| 3831 | case OMPC_aligned: |
| 3832 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3833 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3834 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 3835 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 3836 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 3837 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 3838 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3839 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3840 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3841 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3842 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3843 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 3844 | case OMPC_seq_cst: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 3845 | case OMPC_unknown: |
| 3846 | llvm_unreachable("Clause is not allowed."); |
| 3847 | } |
| 3848 | return Res; |
| 3849 | } |
| 3850 | |
| 3851 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 3852 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 3853 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 3854 | SourceLocation EndLoc) { |
| 3855 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 3856 | std::string Values; |
| 3857 | std::string Sep(", "); |
| 3858 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 3859 | Values += "'"; |
| 3860 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 3861 | Values += "'"; |
| 3862 | switch (i) { |
| 3863 | case OMPC_SCHEDULE_unknown - 2: |
| 3864 | Values += " or "; |
| 3865 | break; |
| 3866 | case OMPC_SCHEDULE_unknown - 1: |
| 3867 | break; |
| 3868 | default: |
| 3869 | Values += Sep; |
| 3870 | break; |
| 3871 | } |
| 3872 | } |
| 3873 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 3874 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 3875 | return nullptr; |
| 3876 | } |
| 3877 | Expr *ValExpr = ChunkSize; |
| 3878 | if (ChunkSize) { |
| 3879 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 3880 | !ChunkSize->isInstantiationDependent() && |
| 3881 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 3882 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 3883 | ExprResult Val = |
| 3884 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 3885 | if (Val.isInvalid()) |
| 3886 | return nullptr; |
| 3887 | |
| 3888 | ValExpr = Val.get(); |
| 3889 | |
| 3890 | // OpenMP [2.7.1, Restrictions] |
| 3891 | // chunk_size must be a loop invariant integer expression with a positive |
| 3892 | // value. |
| 3893 | llvm::APSInt Result; |
| 3894 | if (ValExpr->isIntegerConstantExpr(Result, Context) && |
| 3895 | Result.isSigned() && !Result.isStrictlyPositive()) { |
| 3896 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 3897 | << "schedule" << ChunkSize->getSourceRange(); |
| 3898 | return nullptr; |
| 3899 | } |
| 3900 | } |
| 3901 | } |
| 3902 | |
| 3903 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
| 3904 | EndLoc, Kind, ValExpr); |
| 3905 | } |
| 3906 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3907 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 3908 | SourceLocation StartLoc, |
| 3909 | SourceLocation EndLoc) { |
| 3910 | OMPClause *Res = nullptr; |
| 3911 | switch (Kind) { |
| 3912 | case OMPC_ordered: |
| 3913 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 3914 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 3915 | case OMPC_nowait: |
| 3916 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 3917 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 3918 | case OMPC_untied: |
| 3919 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 3920 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 3921 | case OMPC_mergeable: |
| 3922 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 3923 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3924 | case OMPC_read: |
| 3925 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 3926 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3927 | case OMPC_write: |
| 3928 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 3929 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3930 | case OMPC_update: |
| 3931 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 3932 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3933 | case OMPC_capture: |
| 3934 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 3935 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 3936 | case OMPC_seq_cst: |
| 3937 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 3938 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3939 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 3940 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3941 | case OMPC_num_threads: |
| 3942 | case OMPC_safelen: |
| 3943 | case OMPC_collapse: |
| 3944 | case OMPC_schedule: |
| 3945 | case OMPC_private: |
| 3946 | case OMPC_firstprivate: |
| 3947 | case OMPC_lastprivate: |
| 3948 | case OMPC_shared: |
| 3949 | case OMPC_reduction: |
| 3950 | case OMPC_linear: |
| 3951 | case OMPC_aligned: |
| 3952 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 3953 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3954 | case OMPC_default: |
| 3955 | case OMPC_proc_bind: |
| 3956 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3957 | case OMPC_flush: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3958 | case OMPC_unknown: |
| 3959 | llvm_unreachable("Clause is not allowed."); |
| 3960 | } |
| 3961 | return Res; |
| 3962 | } |
| 3963 | |
| 3964 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 3965 | SourceLocation EndLoc) { |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3966 | DSAStack->setOrderedRegion(); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 3967 | return new (Context) OMPOrderedClause(StartLoc, EndLoc); |
| 3968 | } |
| 3969 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 3970 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 3971 | SourceLocation EndLoc) { |
| 3972 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 3973 | } |
| 3974 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 3975 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 3976 | SourceLocation EndLoc) { |
| 3977 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 3978 | } |
| 3979 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 3980 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 3981 | SourceLocation EndLoc) { |
| 3982 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 3983 | } |
| 3984 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3985 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 3986 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3987 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 3988 | } |
| 3989 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3990 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 3991 | SourceLocation EndLoc) { |
| 3992 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 3993 | } |
| 3994 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3995 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 3996 | SourceLocation EndLoc) { |
| 3997 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 3998 | } |
| 3999 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4000 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 4001 | SourceLocation EndLoc) { |
| 4002 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 4003 | } |
| 4004 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4005 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 4006 | SourceLocation EndLoc) { |
| 4007 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 4008 | } |
| 4009 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4010 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 4011 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 4012 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 4013 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
| 4014 | const DeclarationNameInfo &ReductionId) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4015 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4016 | switch (Kind) { |
| 4017 | case OMPC_private: |
| 4018 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4019 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4020 | case OMPC_firstprivate: |
| 4021 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4022 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4023 | case OMPC_lastprivate: |
| 4024 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4025 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4026 | case OMPC_shared: |
| 4027 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4028 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4029 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4030 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 4031 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4032 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4033 | case OMPC_linear: |
| 4034 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 4035 | ColonLoc, EndLoc); |
| 4036 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4037 | case OMPC_aligned: |
| 4038 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 4039 | ColonLoc, EndLoc); |
| 4040 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4041 | case OMPC_copyin: |
| 4042 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4043 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4044 | case OMPC_copyprivate: |
| 4045 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4046 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4047 | case OMPC_flush: |
| 4048 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4049 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4050 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4051 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4052 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4053 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4054 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4055 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4056 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4057 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4058 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4059 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4060 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4061 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4062 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4063 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4064 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4065 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4066 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4067 | case OMPC_seq_cst: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4068 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4069 | llvm_unreachable("Clause is not allowed."); |
| 4070 | } |
| 4071 | return Res; |
| 4072 | } |
| 4073 | |
| 4074 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 4075 | SourceLocation StartLoc, |
| 4076 | SourceLocation LParenLoc, |
| 4077 | SourceLocation EndLoc) { |
| 4078 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4079 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4080 | for (auto &RefExpr : VarList) { |
| 4081 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 4082 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4083 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4084 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4085 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4086 | continue; |
| 4087 | } |
| 4088 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4089 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4090 | // OpenMP [2.1, C/C++] |
| 4091 | // A list item is a variable name. |
| 4092 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 4093 | // A variable that is part of another variable (as an array or |
| 4094 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4095 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4096 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4097 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4098 | continue; |
| 4099 | } |
| 4100 | Decl *D = DE->getDecl(); |
| 4101 | VarDecl *VD = cast<VarDecl>(D); |
| 4102 | |
| 4103 | QualType Type = VD->getType(); |
| 4104 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 4105 | // It will be analyzed later. |
| 4106 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4107 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4108 | continue; |
| 4109 | } |
| 4110 | |
| 4111 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 4112 | // A variable that appears in a private clause must not have an incomplete |
| 4113 | // type or a reference type. |
| 4114 | if (RequireCompleteType(ELoc, Type, |
| 4115 | diag::err_omp_private_incomplete_type)) { |
| 4116 | continue; |
| 4117 | } |
| 4118 | if (Type->isReferenceType()) { |
| 4119 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4120 | << getOpenMPClauseName(OMPC_private) << Type; |
| 4121 | bool IsDecl = |
| 4122 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4123 | Diag(VD->getLocation(), |
| 4124 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4125 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4126 | continue; |
| 4127 | } |
| 4128 | |
| 4129 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 4130 | // A variable of class type (or array thereof) that appears in a private |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4131 | // clause requires an accessible, unambiguous default constructor for the |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4132 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4133 | while (Type->isArrayType()) { |
| 4134 | Type = cast<ArrayType>(Type.getTypePtr())->getElementType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4135 | } |
| 4136 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4137 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4138 | // in a Construct] |
| 4139 | // Variables with the predetermined data-sharing attributes may not be |
| 4140 | // listed in data-sharing attributes clauses, except for the cases |
| 4141 | // listed below. For these exceptions only, listing a predetermined |
| 4142 | // variable in a data-sharing attribute clause is allowed and overrides |
| 4143 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4144 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4145 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4146 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 4147 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4148 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4149 | continue; |
| 4150 | } |
| 4151 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4152 | // Generate helper private variable and initialize it with the default |
| 4153 | // value. The address of the original variable is replaced by the address of |
| 4154 | // the new private variable in CodeGen. This new variable is not added to |
| 4155 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 4156 | // proper diagnostics. |
| 4157 | auto VDPrivate = |
| 4158 | VarDecl::Create(Context, CurContext, DE->getLocStart(), |
| 4159 | DE->getExprLoc(), VD->getIdentifier(), VD->getType(), |
| 4160 | VD->getTypeSourceInfo(), /*S*/ SC_Auto); |
| 4161 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto*/ false); |
| 4162 | if (VDPrivate->isInvalidDecl()) |
| 4163 | continue; |
| 4164 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 07649fb | 2014-12-16 08:01:48 +0000 | [diff] [blame] | 4165 | auto VDPrivateRefExpr = |
| 4166 | DeclRefExpr::Create(Context, /*QualifierLoc*/ NestedNameSpecifierLoc(), |
| 4167 | /*TemplateKWLoc*/ SourceLocation(), VDPrivate, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 4168 | /*RefersToEnclosingVariableOrCapture*/ false, |
Alexey Bataev | 07649fb | 2014-12-16 08:01:48 +0000 | [diff] [blame] | 4169 | /*NameLoc*/ SourceLocation(), DE->getType(), |
| 4170 | /*VK*/ VK_LValue); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4171 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4172 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4173 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4174 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4175 | } |
| 4176 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4177 | if (Vars.empty()) |
| 4178 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4179 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4180 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 4181 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4182 | } |
| 4183 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4184 | namespace { |
| 4185 | class DiagsUninitializedSeveretyRAII { |
| 4186 | private: |
| 4187 | DiagnosticsEngine &Diags; |
| 4188 | SourceLocation SavedLoc; |
| 4189 | bool IsIgnored; |
| 4190 | |
| 4191 | public: |
| 4192 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 4193 | bool IsIgnored) |
| 4194 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 4195 | if (!IsIgnored) { |
| 4196 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 4197 | /*Map*/ diag::Severity::Ignored, Loc); |
| 4198 | } |
| 4199 | } |
| 4200 | ~DiagsUninitializedSeveretyRAII() { |
| 4201 | if (!IsIgnored) |
| 4202 | Diags.popMappings(SavedLoc); |
| 4203 | } |
| 4204 | }; |
| 4205 | } |
| 4206 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4207 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 4208 | SourceLocation StartLoc, |
| 4209 | SourceLocation LParenLoc, |
| 4210 | SourceLocation EndLoc) { |
| 4211 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4212 | SmallVector<Expr *, 8> PrivateCopies; |
| 4213 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4214 | bool IsImplicitClause = |
| 4215 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 4216 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 4217 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4218 | for (auto &RefExpr : VarList) { |
| 4219 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 4220 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4221 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4222 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4223 | PrivateCopies.push_back(nullptr); |
| 4224 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4225 | continue; |
| 4226 | } |
| 4227 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4228 | SourceLocation ELoc = |
| 4229 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4230 | // OpenMP [2.1, C/C++] |
| 4231 | // A list item is a variable name. |
| 4232 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 4233 | // A variable that is part of another variable (as an array or |
| 4234 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4235 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4236 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4237 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4238 | continue; |
| 4239 | } |
| 4240 | Decl *D = DE->getDecl(); |
| 4241 | VarDecl *VD = cast<VarDecl>(D); |
| 4242 | |
| 4243 | QualType Type = VD->getType(); |
| 4244 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 4245 | // It will be analyzed later. |
| 4246 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4247 | PrivateCopies.push_back(nullptr); |
| 4248 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4249 | continue; |
| 4250 | } |
| 4251 | |
| 4252 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 4253 | // A variable that appears in a private clause must not have an incomplete |
| 4254 | // type or a reference type. |
| 4255 | if (RequireCompleteType(ELoc, Type, |
| 4256 | diag::err_omp_firstprivate_incomplete_type)) { |
| 4257 | continue; |
| 4258 | } |
| 4259 | if (Type->isReferenceType()) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4260 | if (IsImplicitClause) { |
| 4261 | Diag(ImplicitClauseLoc, |
| 4262 | diag::err_omp_task_predetermined_firstprivate_ref_type_arg) |
| 4263 | << Type; |
| 4264 | Diag(RefExpr->getExprLoc(), diag::note_used_here); |
| 4265 | } else { |
| 4266 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 4267 | << getOpenMPClauseName(OMPC_firstprivate) << Type; |
| 4268 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4269 | bool IsDecl = |
| 4270 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4271 | Diag(VD->getLocation(), |
| 4272 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4273 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4274 | continue; |
| 4275 | } |
| 4276 | |
| 4277 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 4278 | // A variable of class type (or array thereof) that appears in a private |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4279 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4280 | // class type. |
| 4281 | Type = Context.getBaseElementType(Type); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4282 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4283 | // If an implicit firstprivate variable found it was checked already. |
| 4284 | if (!IsImplicitClause) { |
| 4285 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4286 | Type = Type.getNonReferenceType().getCanonicalType(); |
| 4287 | bool IsConstant = Type.isConstant(Context); |
| 4288 | Type = Context.getBaseElementType(Type); |
| 4289 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 4290 | // A list item that specifies a given variable may not appear in more |
| 4291 | // than one clause on the same directive, except that a variable may be |
| 4292 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4293 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4294 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4295 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4296 | << getOpenMPClauseName(DVar.CKind) |
| 4297 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4298 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4299 | continue; |
| 4300 | } |
| 4301 | |
| 4302 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4303 | // in a Construct] |
| 4304 | // Variables with the predetermined data-sharing attributes may not be |
| 4305 | // listed in data-sharing attributes clauses, except for the cases |
| 4306 | // listed below. For these exceptions only, listing a predetermined |
| 4307 | // variable in a data-sharing attribute clause is allowed and overrides |
| 4308 | // the variable's predetermined data-sharing attributes. |
| 4309 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4310 | // in a Construct, C/C++, p.2] |
| 4311 | // Variables with const-qualified type having no mutable member may be |
| 4312 | // listed in a firstprivate clause, even if they are static data members. |
| 4313 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 4314 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 4315 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4316 | << getOpenMPClauseName(DVar.CKind) |
| 4317 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4318 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4319 | continue; |
| 4320 | } |
| 4321 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4322 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4323 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 4324 | // A list item that is private within a parallel region must not appear |
| 4325 | // in a firstprivate clause on a worksharing construct if any of the |
| 4326 | // worksharing regions arising from the worksharing construct ever bind |
| 4327 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4328 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 4329 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4330 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 4331 | if (DVar.CKind != OMPC_shared && |
| 4332 | (isOpenMPParallelDirective(DVar.DKind) || |
| 4333 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4334 | Diag(ELoc, diag::err_omp_required_access) |
| 4335 | << getOpenMPClauseName(OMPC_firstprivate) |
| 4336 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4337 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4338 | continue; |
| 4339 | } |
| 4340 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4341 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 4342 | // A list item that appears in a reduction clause of a parallel construct |
| 4343 | // must not appear in a firstprivate clause on a worksharing or task |
| 4344 | // construct if any of the worksharing or task regions arising from the |
| 4345 | // worksharing or task construct ever bind to any of the parallel regions |
| 4346 | // arising from the parallel construct. |
| 4347 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 4348 | // A list item that appears in a reduction clause in worksharing |
| 4349 | // construct must not appear in a firstprivate clause in a task construct |
| 4350 | // encountered during execution of any of the worksharing regions arising |
| 4351 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4352 | if (CurrDir == OMPD_task) { |
| 4353 | DVar = |
| 4354 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 4355 | [](OpenMPDirectiveKind K) -> bool { |
| 4356 | return isOpenMPParallelDirective(K) || |
| 4357 | isOpenMPWorksharingDirective(K); |
| 4358 | }, |
| 4359 | false); |
| 4360 | if (DVar.CKind == OMPC_reduction && |
| 4361 | (isOpenMPParallelDirective(DVar.DKind) || |
| 4362 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 4363 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 4364 | << getOpenMPDirectiveName(DVar.DKind); |
| 4365 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 4366 | continue; |
| 4367 | } |
| 4368 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4369 | } |
| 4370 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4371 | Type = Type.getUnqualifiedType(); |
| 4372 | auto VDPrivate = VarDecl::Create(Context, CurContext, DE->getLocStart(), |
| 4373 | ELoc, VD->getIdentifier(), VD->getType(), |
| 4374 | VD->getTypeSourceInfo(), /*S*/ SC_Auto); |
| 4375 | // Generate helper private variable and initialize it with the value of the |
| 4376 | // original variable. The address of the original variable is replaced by |
| 4377 | // the address of the new private variable in the CodeGen. This new variable |
| 4378 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 4379 | // original variable for proper diagnostics and variable capturing. |
| 4380 | Expr *VDInitRefExpr = nullptr; |
| 4381 | // For arrays generate initializer for single element and replace it by the |
| 4382 | // original array element in CodeGen. |
| 4383 | if (DE->getType()->isArrayType()) { |
| 4384 | auto VDInit = VarDecl::Create(Context, CurContext, DE->getLocStart(), |
| 4385 | ELoc, VD->getIdentifier(), Type, |
| 4386 | VD->getTypeSourceInfo(), /*S*/ SC_Auto); |
| 4387 | CurContext->addHiddenDecl(VDInit); |
| 4388 | VDInitRefExpr = DeclRefExpr::Create( |
| 4389 | Context, /*QualifierLoc*/ NestedNameSpecifierLoc(), |
| 4390 | /*TemplateKWLoc*/ SourceLocation(), VDInit, |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 4391 | /*RefersToEnclosingVariableOrCapture*/ true, ELoc, Type, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4392 | /*VK*/ VK_LValue); |
| 4393 | VDInit->setIsUsed(); |
| 4394 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
| 4395 | InitializedEntity Entity = InitializedEntity::InitializeVariable(VDInit); |
| 4396 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 4397 | |
| 4398 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 4399 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 4400 | if (Result.isInvalid()) |
| 4401 | VDPrivate->setInvalidDecl(); |
| 4402 | else |
| 4403 | VDPrivate->setInit(Result.getAs<Expr>()); |
| 4404 | } else { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 4405 | AddInitializerToDecl( |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 4406 | VDPrivate, |
| 4407 | DefaultLvalueConversion( |
| 4408 | DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 4409 | SourceLocation(), DE->getDecl(), |
| 4410 | /*RefersToEnclosingVariableOrCapture=*/true, |
| 4411 | DE->getExprLoc(), DE->getType(), |
| 4412 | /*VK=*/VK_LValue)).get(), |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 4413 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4414 | } |
| 4415 | if (VDPrivate->isInvalidDecl()) { |
| 4416 | if (IsImplicitClause) { |
| 4417 | Diag(DE->getExprLoc(), |
| 4418 | diag::note_omp_task_predetermined_firstprivate_here); |
| 4419 | } |
| 4420 | continue; |
| 4421 | } |
| 4422 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 19acc3d | 2015-01-12 10:17:46 +0000 | [diff] [blame] | 4423 | auto VDPrivateRefExpr = |
| 4424 | DeclRefExpr::Create(Context, /*QualifierLoc*/ NestedNameSpecifierLoc(), |
| 4425 | /*TemplateKWLoc*/ SourceLocation(), VDPrivate, |
| 4426 | /*RefersToEnclosingVariableOrCapture*/ false, |
| 4427 | DE->getLocStart(), DE->getType(), |
| 4428 | /*VK*/ VK_LValue); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4429 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 4430 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4431 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 4432 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4433 | } |
| 4434 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4435 | if (Vars.empty()) |
| 4436 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4437 | |
| 4438 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4439 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4440 | } |
| 4441 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4442 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 4443 | SourceLocation StartLoc, |
| 4444 | SourceLocation LParenLoc, |
| 4445 | SourceLocation EndLoc) { |
| 4446 | SmallVector<Expr *, 8> Vars; |
| 4447 | for (auto &RefExpr : VarList) { |
| 4448 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 4449 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 4450 | // It will be analyzed later. |
| 4451 | Vars.push_back(RefExpr); |
| 4452 | continue; |
| 4453 | } |
| 4454 | |
| 4455 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 4456 | // OpenMP [2.1, C/C++] |
| 4457 | // A list item is a variable name. |
| 4458 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 4459 | // A variable that is part of another variable (as an array or structure |
| 4460 | // element) cannot appear in a lastprivate clause. |
| 4461 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 4462 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 4463 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 4464 | continue; |
| 4465 | } |
| 4466 | Decl *D = DE->getDecl(); |
| 4467 | VarDecl *VD = cast<VarDecl>(D); |
| 4468 | |
| 4469 | QualType Type = VD->getType(); |
| 4470 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 4471 | // It will be analyzed later. |
| 4472 | Vars.push_back(DE); |
| 4473 | continue; |
| 4474 | } |
| 4475 | |
| 4476 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 4477 | // A variable that appears in a lastprivate clause must not have an |
| 4478 | // incomplete type or a reference type. |
| 4479 | if (RequireCompleteType(ELoc, Type, |
| 4480 | diag::err_omp_lastprivate_incomplete_type)) { |
| 4481 | continue; |
| 4482 | } |
| 4483 | if (Type->isReferenceType()) { |
| 4484 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 4485 | << getOpenMPClauseName(OMPC_lastprivate) << Type; |
| 4486 | bool IsDecl = |
| 4487 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4488 | Diag(VD->getLocation(), |
| 4489 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4490 | << VD; |
| 4491 | continue; |
| 4492 | } |
| 4493 | |
| 4494 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4495 | // in a Construct] |
| 4496 | // Variables with the predetermined data-sharing attributes may not be |
| 4497 | // listed in data-sharing attributes clauses, except for the cases |
| 4498 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4499 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4500 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 4501 | DVar.CKind != OMPC_firstprivate && |
| 4502 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 4503 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 4504 | << getOpenMPClauseName(DVar.CKind) |
| 4505 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4506 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4507 | continue; |
| 4508 | } |
| 4509 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4510 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 4511 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 4512 | // A list item that is private within a parallel region, or that appears in |
| 4513 | // the reduction clause of a parallel construct, must not appear in a |
| 4514 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 4515 | // worksharing regions ever binds to any of the corresponding parallel |
| 4516 | // regions. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4517 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 4518 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4519 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4520 | if (DVar.CKind != OMPC_shared) { |
| 4521 | Diag(ELoc, diag::err_omp_required_access) |
| 4522 | << getOpenMPClauseName(OMPC_lastprivate) |
| 4523 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4524 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4525 | continue; |
| 4526 | } |
| 4527 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4528 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4529 | // A variable of class type (or array thereof) that appears in a |
| 4530 | // lastprivate clause requires an accessible, unambiguous default |
| 4531 | // constructor for the class type, unless the list item is also specified |
| 4532 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4533 | // A variable of class type (or array thereof) that appears in a |
| 4534 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 4535 | // operator for the class type. |
| 4536 | while (Type.getNonReferenceType()->isArrayType()) |
| 4537 | Type = cast<ArrayType>(Type.getNonReferenceType().getTypePtr()) |
| 4538 | ->getElementType(); |
| 4539 | CXXRecordDecl *RD = getLangOpts().CPlusPlus |
| 4540 | ? Type.getNonReferenceType()->getAsCXXRecordDecl() |
| 4541 | : nullptr; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4542 | // FIXME This code must be replaced by actual copying and destructing of the |
| 4543 | // lastprivate variable. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4544 | if (RD) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4545 | CXXMethodDecl *MD = LookupCopyingAssignment(RD, 0, false, 0); |
| 4546 | DeclAccessPair FoundDecl = DeclAccessPair::make(MD, MD->getAccess()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4547 | if (MD) { |
| 4548 | if (CheckMemberAccess(ELoc, RD, FoundDecl) == AR_inaccessible || |
| 4549 | MD->isDeleted()) { |
| 4550 | Diag(ELoc, diag::err_omp_required_method) |
| 4551 | << getOpenMPClauseName(OMPC_lastprivate) << 2; |
| 4552 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 4553 | VarDecl::DeclarationOnly; |
| 4554 | Diag(VD->getLocation(), |
| 4555 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4556 | << VD; |
| 4557 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 4558 | continue; |
| 4559 | } |
| 4560 | MarkFunctionReferenced(ELoc, MD); |
| 4561 | DiagnoseUseOfDecl(MD, ELoc); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4562 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4563 | |
| 4564 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 4565 | if (DD) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4566 | PartialDiagnostic PD = |
| 4567 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4568 | if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible || |
| 4569 | DD->isDeleted()) { |
| 4570 | Diag(ELoc, diag::err_omp_required_method) |
| 4571 | << getOpenMPClauseName(OMPC_lastprivate) << 4; |
| 4572 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 4573 | VarDecl::DeclarationOnly; |
| 4574 | Diag(VD->getLocation(), |
| 4575 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4576 | << VD; |
| 4577 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 4578 | continue; |
| 4579 | } |
| 4580 | MarkFunctionReferenced(ELoc, DD); |
| 4581 | DiagnoseUseOfDecl(DD, ELoc); |
| 4582 | } |
| 4583 | } |
| 4584 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4585 | if (DVar.CKind != OMPC_firstprivate) |
| 4586 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4587 | Vars.push_back(DE); |
| 4588 | } |
| 4589 | |
| 4590 | if (Vars.empty()) |
| 4591 | return nullptr; |
| 4592 | |
| 4593 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 4594 | Vars); |
| 4595 | } |
| 4596 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4597 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 4598 | SourceLocation StartLoc, |
| 4599 | SourceLocation LParenLoc, |
| 4600 | SourceLocation EndLoc) { |
| 4601 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4602 | for (auto &RefExpr : VarList) { |
| 4603 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 4604 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4605 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4606 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4607 | continue; |
| 4608 | } |
| 4609 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4610 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4611 | // OpenMP [2.1, C/C++] |
| 4612 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 4613 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 4614 | // A variable that is part of another variable (as an array or structure |
| 4615 | // element) cannot appear in a shared unless it is a static data member |
| 4616 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4617 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4618 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4619 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4620 | continue; |
| 4621 | } |
| 4622 | Decl *D = DE->getDecl(); |
| 4623 | VarDecl *VD = cast<VarDecl>(D); |
| 4624 | |
| 4625 | QualType Type = VD->getType(); |
| 4626 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 4627 | // It will be analyzed later. |
| 4628 | Vars.push_back(DE); |
| 4629 | continue; |
| 4630 | } |
| 4631 | |
| 4632 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4633 | // in a Construct] |
| 4634 | // Variables with the predetermined data-sharing attributes may not be |
| 4635 | // listed in data-sharing attributes clauses, except for the cases |
| 4636 | // listed below. For these exceptions only, listing a predetermined |
| 4637 | // variable in a data-sharing attribute clause is allowed and overrides |
| 4638 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4639 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4640 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 4641 | DVar.RefExpr) { |
| 4642 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 4643 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4644 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4645 | continue; |
| 4646 | } |
| 4647 | |
| 4648 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 4649 | Vars.push_back(DE); |
| 4650 | } |
| 4651 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4652 | if (Vars.empty()) |
| 4653 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4654 | |
| 4655 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 4656 | } |
| 4657 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4658 | namespace { |
| 4659 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 4660 | DSAStackTy *Stack; |
| 4661 | |
| 4662 | public: |
| 4663 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 4664 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4665 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4666 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 4667 | return false; |
| 4668 | if (DVar.CKind != OMPC_unknown) |
| 4669 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4670 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4671 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4672 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4673 | return true; |
| 4674 | return false; |
| 4675 | } |
| 4676 | return false; |
| 4677 | } |
| 4678 | bool VisitStmt(Stmt *S) { |
| 4679 | for (auto Child : S->children()) { |
| 4680 | if (Child && Visit(Child)) |
| 4681 | return true; |
| 4682 | } |
| 4683 | return false; |
| 4684 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4685 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4686 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4687 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4688 | |
| 4689 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 4690 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 4691 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 4692 | CXXScopeSpec &ReductionIdScopeSpec, |
| 4693 | const DeclarationNameInfo &ReductionId) { |
| 4694 | // TODO: Allow scope specification search when 'declare reduction' is |
| 4695 | // supported. |
| 4696 | assert(ReductionIdScopeSpec.isEmpty() && |
| 4697 | "No support for scoped reduction identifiers yet."); |
| 4698 | |
| 4699 | auto DN = ReductionId.getName(); |
| 4700 | auto OOK = DN.getCXXOverloadedOperator(); |
| 4701 | BinaryOperatorKind BOK = BO_Comma; |
| 4702 | |
| 4703 | // OpenMP [2.14.3.6, reduction clause] |
| 4704 | // C |
| 4705 | // reduction-identifier is either an identifier or one of the following |
| 4706 | // operators: +, -, *, &, |, ^, && and || |
| 4707 | // C++ |
| 4708 | // reduction-identifier is either an id-expression or one of the following |
| 4709 | // operators: +, -, *, &, |, ^, && and || |
| 4710 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 4711 | switch (OOK) { |
| 4712 | case OO_Plus: |
| 4713 | case OO_Minus: |
| 4714 | BOK = BO_AddAssign; |
| 4715 | break; |
| 4716 | case OO_Star: |
| 4717 | BOK = BO_MulAssign; |
| 4718 | break; |
| 4719 | case OO_Amp: |
| 4720 | BOK = BO_AndAssign; |
| 4721 | break; |
| 4722 | case OO_Pipe: |
| 4723 | BOK = BO_OrAssign; |
| 4724 | break; |
| 4725 | case OO_Caret: |
| 4726 | BOK = BO_XorAssign; |
| 4727 | break; |
| 4728 | case OO_AmpAmp: |
| 4729 | BOK = BO_LAnd; |
| 4730 | break; |
| 4731 | case OO_PipePipe: |
| 4732 | BOK = BO_LOr; |
| 4733 | break; |
| 4734 | default: |
| 4735 | if (auto II = DN.getAsIdentifierInfo()) { |
| 4736 | if (II->isStr("max")) |
| 4737 | BOK = BO_GT; |
| 4738 | else if (II->isStr("min")) |
| 4739 | BOK = BO_LT; |
| 4740 | } |
| 4741 | break; |
| 4742 | } |
| 4743 | SourceRange ReductionIdRange; |
| 4744 | if (ReductionIdScopeSpec.isValid()) { |
| 4745 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 4746 | } |
| 4747 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 4748 | if (BOK == BO_Comma) { |
| 4749 | // Not allowed reduction identifier is found. |
| 4750 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 4751 | << ReductionIdRange; |
| 4752 | return nullptr; |
| 4753 | } |
| 4754 | |
| 4755 | SmallVector<Expr *, 8> Vars; |
| 4756 | for (auto RefExpr : VarList) { |
| 4757 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 4758 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 4759 | // It will be analyzed later. |
| 4760 | Vars.push_back(RefExpr); |
| 4761 | continue; |
| 4762 | } |
| 4763 | |
| 4764 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 4765 | RefExpr->isInstantiationDependent() || |
| 4766 | RefExpr->containsUnexpandedParameterPack()) { |
| 4767 | // It will be analyzed later. |
| 4768 | Vars.push_back(RefExpr); |
| 4769 | continue; |
| 4770 | } |
| 4771 | |
| 4772 | auto ELoc = RefExpr->getExprLoc(); |
| 4773 | auto ERange = RefExpr->getSourceRange(); |
| 4774 | // OpenMP [2.1, C/C++] |
| 4775 | // A list item is a variable or array section, subject to the restrictions |
| 4776 | // specified in Section 2.4 on page 42 and in each of the sections |
| 4777 | // describing clauses and directives for which a list appears. |
| 4778 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 4779 | // A variable that is part of another variable (as an array or |
| 4780 | // structure element) cannot appear in a private clause. |
| 4781 | auto DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 4782 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 4783 | Diag(ELoc, diag::err_omp_expected_var_name) << ERange; |
| 4784 | continue; |
| 4785 | } |
| 4786 | auto D = DE->getDecl(); |
| 4787 | auto VD = cast<VarDecl>(D); |
| 4788 | auto Type = VD->getType(); |
| 4789 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 4790 | // A variable that appears in a private clause must not have an incomplete |
| 4791 | // type or a reference type. |
| 4792 | if (RequireCompleteType(ELoc, Type, |
| 4793 | diag::err_omp_reduction_incomplete_type)) |
| 4794 | continue; |
| 4795 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 4796 | // Arrays may not appear in a reduction clause. |
| 4797 | if (Type.getNonReferenceType()->isArrayType()) { |
| 4798 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
| 4799 | bool IsDecl = |
| 4800 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4801 | Diag(VD->getLocation(), |
| 4802 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4803 | << VD; |
| 4804 | continue; |
| 4805 | } |
| 4806 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 4807 | // A list item that appears in a reduction clause must not be |
| 4808 | // const-qualified. |
| 4809 | if (Type.getNonReferenceType().isConstant(Context)) { |
| 4810 | Diag(ELoc, diag::err_omp_const_variable) |
| 4811 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
| 4812 | bool IsDecl = |
| 4813 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4814 | Diag(VD->getLocation(), |
| 4815 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4816 | << VD; |
| 4817 | continue; |
| 4818 | } |
| 4819 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 4820 | // If a list-item is a reference type then it must bind to the same object |
| 4821 | // for all threads of the team. |
| 4822 | VarDecl *VDDef = VD->getDefinition(); |
| 4823 | if (Type->isReferenceType() && VDDef) { |
| 4824 | DSARefChecker Check(DSAStack); |
| 4825 | if (Check.Visit(VDDef->getInit())) { |
| 4826 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 4827 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 4828 | continue; |
| 4829 | } |
| 4830 | } |
| 4831 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 4832 | // The type of a list item that appears in a reduction clause must be valid |
| 4833 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 4834 | // of the list item must be an allowed arithmetic data type: char, int, |
| 4835 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 4836 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 4837 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 4838 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 4839 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 4840 | !(Type->isScalarType() || |
| 4841 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 4842 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 4843 | << getLangOpts().CPlusPlus; |
| 4844 | bool IsDecl = |
| 4845 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4846 | Diag(VD->getLocation(), |
| 4847 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4848 | << VD; |
| 4849 | continue; |
| 4850 | } |
| 4851 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 4852 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 4853 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 4854 | bool IsDecl = |
| 4855 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4856 | Diag(VD->getLocation(), |
| 4857 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4858 | << VD; |
| 4859 | continue; |
| 4860 | } |
| 4861 | bool Suppress = getDiagnostics().getSuppressAllDiagnostics(); |
| 4862 | getDiagnostics().setSuppressAllDiagnostics(true); |
| 4863 | ExprResult ReductionOp = |
| 4864 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 4865 | RefExpr, RefExpr); |
| 4866 | getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4867 | if (ReductionOp.isInvalid()) { |
| 4868 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4869 | << ReductionIdRange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4870 | bool IsDecl = |
| 4871 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4872 | Diag(VD->getLocation(), |
| 4873 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4874 | << VD; |
| 4875 | continue; |
| 4876 | } |
| 4877 | |
| 4878 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4879 | // in a Construct] |
| 4880 | // Variables with the predetermined data-sharing attributes may not be |
| 4881 | // listed in data-sharing attributes clauses, except for the cases |
| 4882 | // listed below. For these exceptions only, listing a predetermined |
| 4883 | // variable in a data-sharing attribute clause is allowed and overrides |
| 4884 | // the variable's predetermined data-sharing attributes. |
| 4885 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 4886 | // Any number of reduction clauses can be specified on the directive, |
| 4887 | // but a list item can appear only once in the reduction clauses for that |
| 4888 | // directive. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4889 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4890 | if (DVar.CKind == OMPC_reduction) { |
| 4891 | Diag(ELoc, diag::err_omp_once_referenced) |
| 4892 | << getOpenMPClauseName(OMPC_reduction); |
| 4893 | if (DVar.RefExpr) { |
| 4894 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 4895 | } |
| 4896 | } else if (DVar.CKind != OMPC_unknown) { |
| 4897 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 4898 | << getOpenMPClauseName(DVar.CKind) |
| 4899 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4900 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4901 | continue; |
| 4902 | } |
| 4903 | |
| 4904 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 4905 | // A list item that appears in a reduction clause of a worksharing |
| 4906 | // construct must be shared in the parallel regions to which any of the |
| 4907 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4908 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4909 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 4910 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4911 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4912 | if (DVar.CKind != OMPC_shared) { |
| 4913 | Diag(ELoc, diag::err_omp_required_access) |
| 4914 | << getOpenMPClauseName(OMPC_reduction) |
| 4915 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4916 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4917 | continue; |
| 4918 | } |
| 4919 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4920 | |
| 4921 | CXXRecordDecl *RD = getLangOpts().CPlusPlus |
| 4922 | ? Type.getNonReferenceType()->getAsCXXRecordDecl() |
| 4923 | : nullptr; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4924 | // FIXME This code must be replaced by actual constructing/destructing of |
| 4925 | // the reduction variable. |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4926 | if (RD) { |
| 4927 | CXXConstructorDecl *CD = LookupDefaultConstructor(RD); |
| 4928 | PartialDiagnostic PD = |
| 4929 | PartialDiagnostic(PartialDiagnostic::NullDiagnostic()); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4930 | if (!CD || |
| 4931 | CheckConstructorAccess(ELoc, CD, |
| 4932 | InitializedEntity::InitializeTemporary(Type), |
| 4933 | CD->getAccess(), PD) == AR_inaccessible || |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4934 | CD->isDeleted()) { |
| 4935 | Diag(ELoc, diag::err_omp_required_method) |
| 4936 | << getOpenMPClauseName(OMPC_reduction) << 0; |
| 4937 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 4938 | VarDecl::DeclarationOnly; |
| 4939 | Diag(VD->getLocation(), |
| 4940 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4941 | << VD; |
| 4942 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 4943 | continue; |
| 4944 | } |
| 4945 | MarkFunctionReferenced(ELoc, CD); |
| 4946 | DiagnoseUseOfDecl(CD, ELoc); |
| 4947 | |
| 4948 | CXXDestructorDecl *DD = RD->getDestructor(); |
| 4949 | if (DD) { |
| 4950 | if (CheckDestructorAccess(ELoc, DD, PD) == AR_inaccessible || |
| 4951 | DD->isDeleted()) { |
| 4952 | Diag(ELoc, diag::err_omp_required_method) |
| 4953 | << getOpenMPClauseName(OMPC_reduction) << 4; |
| 4954 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 4955 | VarDecl::DeclarationOnly; |
| 4956 | Diag(VD->getLocation(), |
| 4957 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4958 | << VD; |
| 4959 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 4960 | continue; |
| 4961 | } |
| 4962 | MarkFunctionReferenced(ELoc, DD); |
| 4963 | DiagnoseUseOfDecl(DD, ELoc); |
| 4964 | } |
| 4965 | } |
| 4966 | |
| 4967 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 4968 | Vars.push_back(DE); |
| 4969 | } |
| 4970 | |
| 4971 | if (Vars.empty()) |
| 4972 | return nullptr; |
| 4973 | |
| 4974 | return OMPReductionClause::Create( |
| 4975 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
| 4976 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId); |
| 4977 | } |
| 4978 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4979 | OMPClause *Sema::ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 4980 | SourceLocation StartLoc, |
| 4981 | SourceLocation LParenLoc, |
| 4982 | SourceLocation ColonLoc, |
| 4983 | SourceLocation EndLoc) { |
| 4984 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4985 | for (auto &RefExpr : VarList) { |
| 4986 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 4987 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4988 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4989 | Vars.push_back(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4990 | continue; |
| 4991 | } |
| 4992 | |
| 4993 | // OpenMP [2.14.3.7, linear clause] |
| 4994 | // A list item that appears in a linear clause is subject to the private |
| 4995 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 4996 | // noted. In addition, the value of the new list item on each iteration |
| 4997 | // of the associated loop(s) corresponds to the value of the original |
| 4998 | // list item before entering the construct plus the logical number of |
| 4999 | // the iteration times linear-step. |
| 5000 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5001 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5002 | // OpenMP [2.1, C/C++] |
| 5003 | // A list item is a variable name. |
| 5004 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 5005 | // A variable that is part of another variable (as an array or |
| 5006 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5007 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5008 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5009 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5010 | continue; |
| 5011 | } |
| 5012 | |
| 5013 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 5014 | |
| 5015 | // OpenMP [2.14.3.7, linear clause] |
| 5016 | // A list-item cannot appear in more than one linear clause. |
| 5017 | // A list-item that appears in a linear clause cannot appear in any |
| 5018 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5019 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5020 | if (DVar.RefExpr) { |
| 5021 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5022 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5023 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5024 | continue; |
| 5025 | } |
| 5026 | |
| 5027 | QualType QType = VD->getType(); |
| 5028 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 5029 | // It will be analyzed later. |
| 5030 | Vars.push_back(DE); |
| 5031 | continue; |
| 5032 | } |
| 5033 | |
| 5034 | // A variable must not have an incomplete type or a reference type. |
| 5035 | if (RequireCompleteType(ELoc, QType, |
| 5036 | diag::err_omp_linear_incomplete_type)) { |
| 5037 | continue; |
| 5038 | } |
| 5039 | if (QType->isReferenceType()) { |
| 5040 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 5041 | << getOpenMPClauseName(OMPC_linear) << QType; |
| 5042 | bool IsDecl = |
| 5043 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5044 | Diag(VD->getLocation(), |
| 5045 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5046 | << VD; |
| 5047 | continue; |
| 5048 | } |
| 5049 | |
| 5050 | // A list item must not be const-qualified. |
| 5051 | if (QType.isConstant(Context)) { |
| 5052 | Diag(ELoc, diag::err_omp_const_variable) |
| 5053 | << getOpenMPClauseName(OMPC_linear); |
| 5054 | bool IsDecl = |
| 5055 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5056 | Diag(VD->getLocation(), |
| 5057 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5058 | << VD; |
| 5059 | continue; |
| 5060 | } |
| 5061 | |
| 5062 | // A list item must be of integral or pointer type. |
| 5063 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 5064 | const Type *Ty = QType.getTypePtrOrNull(); |
| 5065 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 5066 | !Ty->isPointerType())) { |
| 5067 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 5068 | bool IsDecl = |
| 5069 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5070 | Diag(VD->getLocation(), |
| 5071 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5072 | << VD; |
| 5073 | continue; |
| 5074 | } |
| 5075 | |
| 5076 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 5077 | Vars.push_back(DE); |
| 5078 | } |
| 5079 | |
| 5080 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5081 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5082 | |
| 5083 | Expr *StepExpr = Step; |
| 5084 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 5085 | !Step->isInstantiationDependent() && |
| 5086 | !Step->containsUnexpandedParameterPack()) { |
| 5087 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5088 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5089 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5090 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5091 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5092 | |
| 5093 | // Warn about zero linear step (it would be probably better specified as |
| 5094 | // making corresponding variables 'const'). |
| 5095 | llvm::APSInt Result; |
| 5096 | if (StepExpr->isIntegerConstantExpr(Result, Context) && |
| 5097 | !Result.isNegative() && !Result.isStrictlyPositive()) |
| 5098 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 5099 | << (Vars.size() > 1); |
| 5100 | } |
| 5101 | |
| 5102 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, ColonLoc, EndLoc, |
| 5103 | Vars, StepExpr); |
| 5104 | } |
| 5105 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5106 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 5107 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 5108 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 5109 | |
| 5110 | SmallVector<Expr *, 8> Vars; |
| 5111 | for (auto &RefExpr : VarList) { |
| 5112 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 5113 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5114 | // It will be analyzed later. |
| 5115 | Vars.push_back(RefExpr); |
| 5116 | continue; |
| 5117 | } |
| 5118 | |
| 5119 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 5120 | // OpenMP [2.1, C/C++] |
| 5121 | // A list item is a variable name. |
| 5122 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 5123 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5124 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 5125 | continue; |
| 5126 | } |
| 5127 | |
| 5128 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 5129 | |
| 5130 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 5131 | // The type of list items appearing in the aligned clause must be |
| 5132 | // array, pointer, reference to array, or reference to pointer. |
| 5133 | QualType QType = DE->getType() |
| 5134 | .getNonReferenceType() |
| 5135 | .getUnqualifiedType() |
| 5136 | .getCanonicalType(); |
| 5137 | const Type *Ty = QType.getTypePtrOrNull(); |
| 5138 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 5139 | !Ty->isPointerType())) { |
| 5140 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 5141 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 5142 | bool IsDecl = |
| 5143 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5144 | Diag(VD->getLocation(), |
| 5145 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5146 | << VD; |
| 5147 | continue; |
| 5148 | } |
| 5149 | |
| 5150 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 5151 | // A list-item cannot appear in more than one aligned clause. |
| 5152 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 5153 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 5154 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 5155 | << getOpenMPClauseName(OMPC_aligned); |
| 5156 | continue; |
| 5157 | } |
| 5158 | |
| 5159 | Vars.push_back(DE); |
| 5160 | } |
| 5161 | |
| 5162 | // OpenMP [2.8.1, simd construct, Description] |
| 5163 | // The parameter of the aligned clause, alignment, must be a constant |
| 5164 | // positive integer expression. |
| 5165 | // If no optional parameter is specified, implementation-defined default |
| 5166 | // alignments for SIMD instructions on the target platforms are assumed. |
| 5167 | if (Alignment != nullptr) { |
| 5168 | ExprResult AlignResult = |
| 5169 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 5170 | if (AlignResult.isInvalid()) |
| 5171 | return nullptr; |
| 5172 | Alignment = AlignResult.get(); |
| 5173 | } |
| 5174 | if (Vars.empty()) |
| 5175 | return nullptr; |
| 5176 | |
| 5177 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 5178 | EndLoc, Vars, Alignment); |
| 5179 | } |
| 5180 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5181 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 5182 | SourceLocation StartLoc, |
| 5183 | SourceLocation LParenLoc, |
| 5184 | SourceLocation EndLoc) { |
| 5185 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5186 | for (auto &RefExpr : VarList) { |
| 5187 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 5188 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5189 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5190 | Vars.push_back(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5191 | continue; |
| 5192 | } |
| 5193 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5194 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5195 | // OpenMP [2.1, C/C++] |
| 5196 | // A list item is a variable name. |
| 5197 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 5198 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5199 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5200 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5201 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5202 | continue; |
| 5203 | } |
| 5204 | |
| 5205 | Decl *D = DE->getDecl(); |
| 5206 | VarDecl *VD = cast<VarDecl>(D); |
| 5207 | |
| 5208 | QualType Type = VD->getType(); |
| 5209 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5210 | // It will be analyzed later. |
| 5211 | Vars.push_back(DE); |
| 5212 | continue; |
| 5213 | } |
| 5214 | |
| 5215 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 5216 | // A list item that appears in a copyin clause must be threadprivate. |
| 5217 | if (!DSAStack->isThreadPrivate(VD)) { |
| 5218 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5219 | << getOpenMPClauseName(OMPC_copyin) |
| 5220 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5221 | continue; |
| 5222 | } |
| 5223 | |
| 5224 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 5225 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5226 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5227 | // operator for the class type. |
| 5228 | Type = Context.getBaseElementType(Type); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5229 | CXXRecordDecl *RD = |
| 5230 | getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5231 | // FIXME This code must be replaced by actual assignment of the |
| 5232 | // threadprivate variable. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5233 | if (RD) { |
| 5234 | CXXMethodDecl *MD = LookupCopyingAssignment(RD, 0, false, 0); |
| 5235 | DeclAccessPair FoundDecl = DeclAccessPair::make(MD, MD->getAccess()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5236 | if (MD) { |
| 5237 | if (CheckMemberAccess(ELoc, RD, FoundDecl) == AR_inaccessible || |
| 5238 | MD->isDeleted()) { |
| 5239 | Diag(ELoc, diag::err_omp_required_method) |
| 5240 | << getOpenMPClauseName(OMPC_copyin) << 2; |
| 5241 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 5242 | VarDecl::DeclarationOnly; |
| 5243 | Diag(VD->getLocation(), |
| 5244 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5245 | << VD; |
| 5246 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 5247 | continue; |
| 5248 | } |
| 5249 | MarkFunctionReferenced(ELoc, MD); |
| 5250 | DiagnoseUseOfDecl(MD, ELoc); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5251 | } |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 5255 | Vars.push_back(DE); |
| 5256 | } |
| 5257 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5258 | if (Vars.empty()) |
| 5259 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5260 | |
| 5261 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 5262 | } |
| 5263 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5264 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 5265 | SourceLocation StartLoc, |
| 5266 | SourceLocation LParenLoc, |
| 5267 | SourceLocation EndLoc) { |
| 5268 | SmallVector<Expr *, 8> Vars; |
| 5269 | for (auto &RefExpr : VarList) { |
| 5270 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 5271 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5272 | // It will be analyzed later. |
| 5273 | Vars.push_back(RefExpr); |
| 5274 | continue; |
| 5275 | } |
| 5276 | |
| 5277 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 5278 | // OpenMP [2.1, C/C++] |
| 5279 | // A list item is a variable name. |
| 5280 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 5281 | // A list item that appears in a copyin clause must be threadprivate. |
| 5282 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 5283 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5284 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 5285 | continue; |
| 5286 | } |
| 5287 | |
| 5288 | Decl *D = DE->getDecl(); |
| 5289 | VarDecl *VD = cast<VarDecl>(D); |
| 5290 | |
| 5291 | QualType Type = VD->getType(); |
| 5292 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5293 | // It will be analyzed later. |
| 5294 | Vars.push_back(DE); |
| 5295 | continue; |
| 5296 | } |
| 5297 | |
| 5298 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 5299 | // A list item that appears in a copyprivate clause may not appear in a |
| 5300 | // private or firstprivate clause on the single construct. |
| 5301 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5302 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5303 | if (DVar.CKind != OMPC_copyprivate && DVar.CKind != OMPC_unknown && |
| 5304 | !(DVar.CKind == OMPC_private && !DVar.RefExpr)) { |
| 5305 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 5306 | << getOpenMPClauseName(DVar.CKind) |
| 5307 | << getOpenMPClauseName(OMPC_copyprivate); |
| 5308 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 5309 | continue; |
| 5310 | } |
| 5311 | |
| 5312 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 5313 | // All list items that appear in a copyprivate clause must be either |
| 5314 | // threadprivate or private in the enclosing context. |
| 5315 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5316 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5317 | if (DVar.CKind == OMPC_shared) { |
| 5318 | Diag(ELoc, diag::err_omp_required_access) |
| 5319 | << getOpenMPClauseName(OMPC_copyprivate) |
| 5320 | << "threadprivate or private in the enclosing context"; |
| 5321 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 5322 | continue; |
| 5323 | } |
| 5324 | } |
| 5325 | } |
| 5326 | |
| 5327 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 5328 | // A variable of class type (or array thereof) that appears in a |
| 5329 | // copyin clause requires an accessible, unambiguous copy assignment |
| 5330 | // operator for the class type. |
| 5331 | Type = Context.getBaseElementType(Type); |
| 5332 | CXXRecordDecl *RD = |
| 5333 | getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
| 5334 | // FIXME This code must be replaced by actual assignment of the |
| 5335 | // threadprivate variable. |
| 5336 | if (RD) { |
| 5337 | CXXMethodDecl *MD = LookupCopyingAssignment(RD, 0, false, 0); |
| 5338 | DeclAccessPair FoundDecl = DeclAccessPair::make(MD, MD->getAccess()); |
| 5339 | if (MD) { |
| 5340 | if (CheckMemberAccess(ELoc, RD, FoundDecl) == AR_inaccessible || |
| 5341 | MD->isDeleted()) { |
| 5342 | Diag(ELoc, diag::err_omp_required_method) |
| 5343 | << getOpenMPClauseName(OMPC_copyprivate) << 2; |
| 5344 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 5345 | VarDecl::DeclarationOnly; |
| 5346 | Diag(VD->getLocation(), |
| 5347 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5348 | << VD; |
| 5349 | Diag(RD->getLocation(), diag::note_previous_decl) << RD; |
| 5350 | continue; |
| 5351 | } |
| 5352 | MarkFunctionReferenced(ELoc, MD); |
| 5353 | DiagnoseUseOfDecl(MD, ELoc); |
| 5354 | } |
| 5355 | } |
| 5356 | |
| 5357 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 5358 | // implicitly private. |
| 5359 | Vars.push_back(DE); |
| 5360 | } |
| 5361 | |
| 5362 | if (Vars.empty()) |
| 5363 | return nullptr; |
| 5364 | |
| 5365 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 5366 | } |
| 5367 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5368 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 5369 | SourceLocation StartLoc, |
| 5370 | SourceLocation LParenLoc, |
| 5371 | SourceLocation EndLoc) { |
| 5372 | if (VarList.empty()) |
| 5373 | return nullptr; |
| 5374 | |
| 5375 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 5376 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5377 | |