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