Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 17 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 18 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 20 | #include "clang/AST/StmtCXX.h" |
| 21 | #include "clang/AST/StmtOpenMP.h" |
| 22 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 23 | #include "clang/Basic/OpenMPKinds.h" |
| 24 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 25 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 26 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Scope.h" |
| 28 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 29 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 30 | using namespace clang; |
| 31 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 32 | //===----------------------------------------------------------------------===// |
| 33 | // Stack of data-sharing attributes for variables |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | |
| 36 | namespace { |
| 37 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 38 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 39 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 40 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 41 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 42 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 43 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 44 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 45 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 46 | bool operator()(T Kind) { |
| 47 | for (auto KindEl : Arr) |
| 48 | if (KindEl == Kind) |
| 49 | return true; |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | private: |
| 54 | ArrayRef<T> Arr; |
| 55 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 56 | struct MatchesAlways { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 57 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 58 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 62 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 63 | |
| 64 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 65 | /// clauses and their data-sharing attributes. |
| 66 | class DSAStackTy { |
| 67 | public: |
| 68 | struct DSAVarData { |
| 69 | OpenMPDirectiveKind DKind; |
| 70 | OpenMPClauseKind CKind; |
| 71 | DeclRefExpr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 72 | SourceLocation ImplicitDSALoc; |
| 73 | DSAVarData() |
| 74 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 75 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 76 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 77 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 78 | private: |
| 79 | struct DSAInfo { |
| 80 | OpenMPClauseKind Attributes; |
| 81 | DeclRefExpr *RefExpr; |
| 82 | }; |
| 83 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 84 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 85 | typedef llvm::DenseSet<VarDecl *> LoopControlVariablesSetTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 86 | |
| 87 | struct SharingMapTy { |
| 88 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 89 | AlignedMapTy AlignedMap; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 90 | LoopControlVariablesSetTy LCVSet; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 91 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 92 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 93 | OpenMPDirectiveKind Directive; |
| 94 | DeclarationNameInfo DirectiveName; |
| 95 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 96 | SourceLocation ConstructLoc; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 97 | bool OrderedRegion; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 98 | unsigned CollapseNumber; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 99 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 100 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 101 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 102 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 103 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 104 | ConstructLoc(Loc), OrderedRegion(false), CollapseNumber(1), |
| 105 | InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 106 | SharingMapTy() |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 107 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 108 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 109 | ConstructLoc(), OrderedRegion(false), CollapseNumber(1), |
| 110 | InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 114 | |
| 115 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 116 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 117 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 118 | /// from current directive. |
| 119 | bool FromParent; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 120 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 121 | |
| 122 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 123 | |
| 124 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 125 | |
| 126 | /// \brief Checks if the variable is a local for OpenMP region. |
| 127 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 128 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 129 | public: |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 130 | explicit DSAStackTy(Sema &S) : Stack(1), FromParent(false), SemaRef(S) {} |
| 131 | |
| 132 | bool isFromParent() const { return FromParent; } |
| 133 | void setFromParent(bool Flag) { FromParent = Flag; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 134 | |
| 135 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 136 | Scope *CurScope, SourceLocation Loc) { |
| 137 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 138 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | void pop() { |
| 142 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 143 | Stack.pop_back(); |
| 144 | } |
| 145 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 146 | /// \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] | 147 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 148 | /// for diagnostics. |
| 149 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 150 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 151 | /// \brief Register specified variable as loop control variable. |
| 152 | void addLoopControlVariable(VarDecl *D); |
| 153 | /// \brief Check if the specified variable is a loop control variable for |
| 154 | /// current region. |
| 155 | bool isLoopControlVariable(VarDecl *D); |
| 156 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 157 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 158 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 159 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 160 | /// \brief Returns data sharing attributes from top of the stack for the |
| 161 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 162 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 163 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 164 | DSAVarData getImplicitDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 165 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 166 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 167 | /// predicate. |
| 168 | template <class ClausesPredicate, class DirectivesPredicate> |
| 169 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 170 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 171 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 172 | /// match specified \a CPred predicate in any innermost directive which |
| 173 | /// matches \a DPred predicate. |
| 174 | template <class ClausesPredicate, class DirectivesPredicate> |
| 175 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 176 | DirectivesPredicate DPred, |
| 177 | bool FromParent); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 178 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 179 | template <class NamedDirectivesPredicate> |
| 180 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 181 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 182 | /// \brief Returns currently analyzed directive. |
| 183 | OpenMPDirectiveKind getCurrentDirective() const { |
| 184 | return Stack.back().Directive; |
| 185 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 186 | /// \brief Returns parent directive. |
| 187 | OpenMPDirectiveKind getParentDirective() const { |
| 188 | if (Stack.size() > 2) |
| 189 | return Stack[Stack.size() - 2].Directive; |
| 190 | return OMPD_unknown; |
| 191 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 192 | |
| 193 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 194 | void setDefaultDSANone(SourceLocation Loc) { |
| 195 | Stack.back().DefaultAttr = DSA_none; |
| 196 | Stack.back().DefaultAttrLoc = Loc; |
| 197 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 198 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 199 | void setDefaultDSAShared(SourceLocation Loc) { |
| 200 | Stack.back().DefaultAttr = DSA_shared; |
| 201 | Stack.back().DefaultAttrLoc = Loc; |
| 202 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 203 | |
| 204 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 205 | return Stack.back().DefaultAttr; |
| 206 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 207 | SourceLocation getDefaultDSALocation() const { |
| 208 | return Stack.back().DefaultAttrLoc; |
| 209 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 210 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 211 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 212 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 213 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 214 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 217 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
| 218 | void setOrderedRegion(bool IsOrdered = true) { |
| 219 | Stack.back().OrderedRegion = IsOrdered; |
| 220 | } |
| 221 | /// \brief Returns true, if parent region is ordered (has associated |
| 222 | /// 'ordered' clause), false - otherwise. |
| 223 | bool isParentOrderedRegion() const { |
| 224 | if (Stack.size() > 2) |
| 225 | return Stack[Stack.size() - 2].OrderedRegion; |
| 226 | return false; |
| 227 | } |
| 228 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 229 | /// \brief Set collapse value for the region. |
| 230 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 231 | /// \brief Return collapse value for region. |
| 232 | unsigned getCollapseNumber() const { |
| 233 | return Stack.back().CollapseNumber; |
| 234 | } |
| 235 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 236 | /// \brief Marks current target region as one with closely nested teams |
| 237 | /// region. |
| 238 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 239 | if (Stack.size() > 2) |
| 240 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 241 | } |
| 242 | /// \brief Returns true, if current region has closely nested teams region. |
| 243 | bool hasInnerTeamsRegion() const { |
| 244 | return getInnerTeamsRegionLoc().isValid(); |
| 245 | } |
| 246 | /// \brief Returns location of the nested teams region (if any). |
| 247 | SourceLocation getInnerTeamsRegionLoc() const { |
| 248 | if (Stack.size() > 1) |
| 249 | return Stack.back().InnerTeamsRegionLoc; |
| 250 | return SourceLocation(); |
| 251 | } |
| 252 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 253 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 254 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 255 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 256 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 257 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 258 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 259 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 260 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 261 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 262 | |
| 263 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 264 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 265 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 266 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 267 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 268 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 269 | // in a region but not in construct] |
| 270 | // File-scope or namespace-scope variables referenced in called routines |
| 271 | // in the region are shared unless they appear in a threadprivate |
| 272 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 273 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 274 | DVar.CKind = OMPC_shared; |
| 275 | |
| 276 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 277 | // in a region but not in construct] |
| 278 | // Variables with static storage duration that are declared in called |
| 279 | // routines in the region are shared. |
| 280 | if (D->hasGlobalStorage()) |
| 281 | DVar.CKind = OMPC_shared; |
| 282 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 283 | return DVar; |
| 284 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 285 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 286 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 287 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 288 | // in a Construct, C/C++, predetermined, p.1] |
| 289 | // Variables with automatic storage duration that are declared in a scope |
| 290 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 291 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 292 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 293 | DVar.CKind = OMPC_private; |
| 294 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 297 | // Explicitly specified attributes and local variables with predetermined |
| 298 | // attributes. |
| 299 | if (Iter->SharingMap.count(D)) { |
| 300 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 301 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 302 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 303 | return DVar; |
| 304 | } |
| 305 | |
| 306 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 307 | // in a Construct, C/C++, implicitly determined, p.1] |
| 308 | // In a parallel or task construct, the data-sharing attributes of these |
| 309 | // variables are determined by the default clause, if present. |
| 310 | switch (Iter->DefaultAttr) { |
| 311 | case DSA_shared: |
| 312 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 313 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 314 | return DVar; |
| 315 | case DSA_none: |
| 316 | return DVar; |
| 317 | case DSA_unspecified: |
| 318 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 319 | // in a Construct, implicitly determined, p.2] |
| 320 | // In a parallel construct, if no default clause is present, these |
| 321 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 322 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 323 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 324 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 325 | DVar.CKind = OMPC_shared; |
| 326 | return DVar; |
| 327 | } |
| 328 | |
| 329 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 330 | // in a Construct, implicitly determined, p.4] |
| 331 | // In a task construct, if no default clause is present, a variable that in |
| 332 | // the enclosing context is determined to be shared by all implicit tasks |
| 333 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 334 | if (DVar.DKind == OMPD_task) { |
| 335 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 336 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 337 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 338 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 339 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 340 | // in a Construct, implicitly determined, p.6] |
| 341 | // In a task construct, if no default clause is present, a variable |
| 342 | // whose data-sharing attribute is not determined by the rules above is |
| 343 | // firstprivate. |
| 344 | DVarTemp = getDSA(I, D); |
| 345 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 346 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 347 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 348 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 349 | return DVar; |
| 350 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 351 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 352 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 353 | } |
| 354 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 355 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 356 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 357 | return DVar; |
| 358 | } |
| 359 | } |
| 360 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 361 | // in a Construct, implicitly determined, p.3] |
| 362 | // For constructs other than task, if no default clause is present, these |
| 363 | // variables inherit their data-sharing attributes from the enclosing |
| 364 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 365 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 368 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 369 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 370 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 371 | auto It = Stack.back().AlignedMap.find(D); |
| 372 | if (It == Stack.back().AlignedMap.end()) { |
| 373 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 374 | Stack.back().AlignedMap[D] = NewDE; |
| 375 | return nullptr; |
| 376 | } else { |
| 377 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 378 | return It->second; |
| 379 | } |
| 380 | return nullptr; |
| 381 | } |
| 382 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 383 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 384 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 385 | D = D->getCanonicalDecl(); |
| 386 | Stack.back().LCVSet.insert(D); |
| 387 | } |
| 388 | |
| 389 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 390 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 391 | D = D->getCanonicalDecl(); |
| 392 | return Stack.back().LCVSet.count(D) > 0; |
| 393 | } |
| 394 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 395 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 396 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 397 | if (A == OMPC_threadprivate) { |
| 398 | Stack[0].SharingMap[D].Attributes = A; |
| 399 | Stack[0].SharingMap[D].RefExpr = E; |
| 400 | } else { |
| 401 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 402 | Stack.back().SharingMap[D].Attributes = A; |
| 403 | Stack.back().SharingMap[D].RefExpr = E; |
| 404 | } |
| 405 | } |
| 406 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 407 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 408 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 409 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 410 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 411 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 412 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 413 | ++I; |
| 414 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 415 | if (I == E) |
| 416 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 417 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 418 | Scope *CurScope = getCurScope(); |
| 419 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 420 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 421 | } |
| 422 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 423 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 424 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 425 | } |
| 426 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 427 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 428 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
| 429 | StringRef Name) { |
| 430 | DeclContext *DC = SemaRef.CurContext; |
| 431 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 432 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 433 | VarDecl *Decl = |
| 434 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
| 435 | Decl->setImplicit(); |
| 436 | return Decl; |
| 437 | } |
| 438 | |
| 439 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 440 | SourceLocation Loc, |
| 441 | bool RefersToCapture = false) { |
| 442 | D->setReferenced(); |
| 443 | D->markUsed(S.Context); |
| 444 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 445 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 446 | VK_LValue); |
| 447 | } |
| 448 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 449 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 450 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 451 | DSAVarData DVar; |
| 452 | |
| 453 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 454 | // in a Construct, C/C++, predetermined, p.1] |
| 455 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 456 | if (D->getTLSKind() != VarDecl::TLS_None || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 457 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 458 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 459 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 460 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 461 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 462 | } |
| 463 | if (Stack[0].SharingMap.count(D)) { |
| 464 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 465 | DVar.CKind = OMPC_threadprivate; |
| 466 | return DVar; |
| 467 | } |
| 468 | |
| 469 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 470 | // in a Construct, C/C++, predetermined, p.1] |
| 471 | // Variables with automatic storage duration that are declared in a scope |
| 472 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 473 | OpenMPDirectiveKind Kind = |
| 474 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 475 | auto StartI = std::next(Stack.rbegin()); |
| 476 | auto EndI = std::prev(Stack.rend()); |
| 477 | if (FromParent && StartI != EndI) { |
| 478 | StartI = std::next(StartI); |
| 479 | } |
| 480 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 481 | if (isOpenMPLocal(D, StartI) && |
| 482 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 483 | D->getStorageClass() == SC_None)) || |
| 484 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 485 | DVar.CKind = OMPC_private; |
| 486 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 487 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 488 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 489 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 490 | // in a Construct, C/C++, predetermined, p.4] |
| 491 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 492 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 493 | // in a Construct, C/C++, predetermined, p.7] |
| 494 | // Variables with static storage duration that are declared in a scope |
| 495 | // inside the construct are shared. |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 496 | if (D->isStaticDataMember() || D->isStaticLocal()) { |
| 497 | DSAVarData DVarTemp = |
| 498 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 499 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 500 | return DVar; |
| 501 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 502 | DVar.CKind = OMPC_shared; |
| 503 | return DVar; |
| 504 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 508 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 509 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 510 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 511 | // in a Construct, C/C++, predetermined, p.6] |
| 512 | // Variables with const qualified type having no mutable member are |
| 513 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 514 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 515 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 516 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 517 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 518 | // Variables with const-qualified type having no mutable member may be |
| 519 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 520 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 521 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 522 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 523 | return DVar; |
| 524 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 525 | DVar.CKind = OMPC_shared; |
| 526 | return DVar; |
| 527 | } |
| 528 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 529 | // Explicitly specified attributes and local variables with predetermined |
| 530 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 531 | auto I = std::prev(StartI); |
| 532 | if (I->SharingMap.count(D)) { |
| 533 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 534 | DVar.CKind = I->SharingMap[D].Attributes; |
| 535 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | return DVar; |
| 539 | } |
| 540 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 541 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 542 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 543 | auto StartI = Stack.rbegin(); |
| 544 | auto EndI = std::prev(Stack.rend()); |
| 545 | if (FromParent && StartI != EndI) { |
| 546 | StartI = std::next(StartI); |
| 547 | } |
| 548 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 551 | template <class ClausesPredicate, class DirectivesPredicate> |
| 552 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 553 | DirectivesPredicate DPred, |
| 554 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 555 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 556 | auto StartI = std::next(Stack.rbegin()); |
| 557 | auto EndI = std::prev(Stack.rend()); |
| 558 | if (FromParent && StartI != EndI) { |
| 559 | StartI = std::next(StartI); |
| 560 | } |
| 561 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 562 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 563 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 564 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 565 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 566 | return DVar; |
| 567 | } |
| 568 | return DSAVarData(); |
| 569 | } |
| 570 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 571 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 572 | DSAStackTy::DSAVarData |
| 573 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 574 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 575 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 576 | auto StartI = std::next(Stack.rbegin()); |
| 577 | auto EndI = std::prev(Stack.rend()); |
| 578 | if (FromParent && StartI != EndI) { |
| 579 | StartI = std::next(StartI); |
| 580 | } |
| 581 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 582 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 583 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 584 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 585 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 586 | return DVar; |
| 587 | return DSAVarData(); |
| 588 | } |
| 589 | return DSAVarData(); |
| 590 | } |
| 591 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 592 | template <class NamedDirectivesPredicate> |
| 593 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 594 | auto StartI = std::next(Stack.rbegin()); |
| 595 | auto EndI = std::prev(Stack.rend()); |
| 596 | if (FromParent && StartI != EndI) { |
| 597 | StartI = std::next(StartI); |
| 598 | } |
| 599 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 600 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 601 | return true; |
| 602 | } |
| 603 | return false; |
| 604 | } |
| 605 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 606 | void Sema::InitDataSharingAttributesStack() { |
| 607 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 608 | } |
| 609 | |
| 610 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 611 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 612 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 613 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 614 | VD = VD->getCanonicalDecl(); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 615 | if (DSAStack->getCurrentDirective() != OMPD_unknown) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 616 | if (DSAStack->isLoopControlVariable(VD) || |
| 617 | (VD->hasLocalStorage() && |
| 618 | isParallelOrTaskRegion(DSAStack->getCurrentDirective()))) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 619 | return true; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 620 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isFromParent()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 621 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 622 | return true; |
| 623 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 624 | DSAStack->isFromParent()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 625 | return DVarPrivate.CKind != OMPC_unknown; |
| 626 | } |
| 627 | return false; |
| 628 | } |
| 629 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 630 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 631 | |
| 632 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 633 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 634 | Scope *CurScope, SourceLocation Loc) { |
| 635 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 636 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 637 | } |
| 638 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 639 | void Sema::StartOpenMPClauses() { |
| 640 | DSAStack->setFromParent(/*Flag=*/true); |
| 641 | } |
| 642 | |
| 643 | void Sema::EndOpenMPClauses() { |
| 644 | DSAStack->setFromParent(/*Flag=*/false); |
| 645 | } |
| 646 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 647 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 648 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 649 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 650 | // clause requires an accessible, unambiguous default constructor for the |
| 651 | // class type, unless the list item is also specified in a firstprivate |
| 652 | // clause. |
| 653 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 654 | for (auto *C : D->clauses()) { |
| 655 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 656 | SmallVector<Expr *, 8> PrivateCopies; |
| 657 | for (auto *DE : Clause->varlists()) { |
| 658 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 659 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 660 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 661 | } |
| 662 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 663 | QualType Type = VD->getType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 664 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 665 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 666 | // Generate helper private variable and initialize it with the |
| 667 | // default value. The address of the original variable is replaced |
| 668 | // by the address of the new private variable in CodeGen. This new |
| 669 | // variable is not added to IdResolver, so the code in the OpenMP |
| 670 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 671 | auto *VDPrivate = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 672 | buildVarDecl(*this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 673 | VD->getName()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 674 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 675 | if (VDPrivate->isInvalidDecl()) |
| 676 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 677 | PrivateCopies.push_back(buildDeclRefExpr( |
| 678 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 679 | } else { |
| 680 | // The variable is also a firstprivate, so initialization sequence |
| 681 | // for private copy is generated already. |
| 682 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 683 | } |
| 684 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 685 | // Set initializers to private copies if no errors were found. |
| 686 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 687 | Clause->setPrivateCopies(PrivateCopies); |
| 688 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | } |
| 692 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 693 | DSAStack->pop(); |
| 694 | DiscardCleanupsInEvaluationContext(); |
| 695 | PopExpressionEvaluationContext(); |
| 696 | } |
| 697 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 698 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 699 | Expr *NumIterations, Sema &SemaRef, |
| 700 | Scope *S); |
| 701 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 702 | namespace { |
| 703 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 704 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 705 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 706 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 707 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 708 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 709 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 710 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 711 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 712 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 713 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 714 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 715 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 716 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 717 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 718 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 719 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 720 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 721 | |
| 722 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 723 | CXXScopeSpec &ScopeSpec, |
| 724 | const DeclarationNameInfo &Id) { |
| 725 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 726 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 727 | |
| 728 | if (Lookup.isAmbiguous()) |
| 729 | return ExprError(); |
| 730 | |
| 731 | VarDecl *VD; |
| 732 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 733 | if (TypoCorrection Corrected = CorrectTypo( |
| 734 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 735 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 736 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 737 | PDiag(Lookup.empty() |
| 738 | ? diag::err_undeclared_var_use_suggest |
| 739 | : diag::err_omp_expected_var_arg_suggest) |
| 740 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 741 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 742 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 743 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 744 | : diag::err_omp_expected_var_arg) |
| 745 | << Id.getName(); |
| 746 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 747 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 748 | } else { |
| 749 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 750 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 751 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 752 | return ExprError(); |
| 753 | } |
| 754 | } |
| 755 | Lookup.suppressDiagnostics(); |
| 756 | |
| 757 | // OpenMP [2.9.2, Syntax, C/C++] |
| 758 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 759 | if (!VD->hasGlobalStorage()) { |
| 760 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 761 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 762 | bool IsDecl = |
| 763 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 764 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 765 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 766 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 767 | return ExprError(); |
| 768 | } |
| 769 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 770 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 771 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 772 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 773 | // A threadprivate directive for file-scope variables must appear outside |
| 774 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 775 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 776 | !getCurLexicalContext()->isTranslationUnit()) { |
| 777 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 778 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 779 | bool IsDecl = |
| 780 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 781 | Diag(VD->getLocation(), |
| 782 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 783 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 784 | return ExprError(); |
| 785 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 786 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 787 | // A threadprivate directive for static class member variables must appear |
| 788 | // in the class definition, in the same scope in which the member |
| 789 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 790 | if (CanonicalVD->isStaticDataMember() && |
| 791 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 792 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 793 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 794 | bool IsDecl = |
| 795 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 796 | Diag(VD->getLocation(), |
| 797 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 798 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 799 | return ExprError(); |
| 800 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 801 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 802 | // A threadprivate directive for namespace-scope variables must appear |
| 803 | // outside any definition or declaration other than the namespace |
| 804 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 805 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 806 | (!getCurLexicalContext()->isFileContext() || |
| 807 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 808 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 809 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 810 | bool IsDecl = |
| 811 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 812 | Diag(VD->getLocation(), |
| 813 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 814 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 815 | return ExprError(); |
| 816 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 817 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 818 | // A threadprivate directive for static block-scope variables must appear |
| 819 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 820 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 821 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 822 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 823 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 824 | bool IsDecl = |
| 825 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 826 | Diag(VD->getLocation(), |
| 827 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 828 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 829 | return ExprError(); |
| 830 | } |
| 831 | |
| 832 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 833 | // A threadprivate directive must lexically precede all references to any |
| 834 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 835 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 836 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 837 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 838 | return ExprError(); |
| 839 | } |
| 840 | |
| 841 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 842 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 843 | return DE; |
| 844 | } |
| 845 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 846 | Sema::DeclGroupPtrTy |
| 847 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 848 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 849 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 850 | CurContext->addDecl(D); |
| 851 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 852 | } |
| 853 | return DeclGroupPtrTy(); |
| 854 | } |
| 855 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 856 | namespace { |
| 857 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 858 | Sema &SemaRef; |
| 859 | |
| 860 | public: |
| 861 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 862 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 863 | if (VD->hasLocalStorage()) { |
| 864 | SemaRef.Diag(E->getLocStart(), |
| 865 | diag::err_omp_local_var_in_threadprivate_init) |
| 866 | << E->getSourceRange(); |
| 867 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 868 | << VD << VD->getSourceRange(); |
| 869 | return true; |
| 870 | } |
| 871 | } |
| 872 | return false; |
| 873 | } |
| 874 | bool VisitStmt(const Stmt *S) { |
| 875 | for (auto Child : S->children()) { |
| 876 | if (Child && Visit(Child)) |
| 877 | return true; |
| 878 | } |
| 879 | return false; |
| 880 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 881 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 882 | }; |
| 883 | } // namespace |
| 884 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 885 | OMPThreadPrivateDecl * |
| 886 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 887 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 888 | for (auto &RefExpr : VarList) { |
| 889 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 890 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 891 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 892 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 893 | QualType QType = VD->getType(); |
| 894 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 895 | // It will be analyzed later. |
| 896 | Vars.push_back(DE); |
| 897 | continue; |
| 898 | } |
| 899 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 900 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 901 | // A threadprivate variable must not have an incomplete type. |
| 902 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 903 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 904 | continue; |
| 905 | } |
| 906 | |
| 907 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 908 | // A threadprivate variable must not have a reference type. |
| 909 | if (VD->getType()->isReferenceType()) { |
| 910 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 911 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 912 | bool IsDecl = |
| 913 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 914 | Diag(VD->getLocation(), |
| 915 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 916 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 917 | continue; |
| 918 | } |
| 919 | |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 920 | // Check if this is a TLS variable. |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 921 | if (VD->getTLSKind() != VarDecl::TLS_None || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 922 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 923 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 924 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 925 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 926 | bool IsDecl = |
| 927 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 928 | Diag(VD->getLocation(), |
| 929 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 930 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 931 | continue; |
| 932 | } |
| 933 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 934 | // Check if initial value of threadprivate variable reference variable with |
| 935 | // local storage (it is not supported by runtime). |
| 936 | if (auto Init = VD->getAnyInitializer()) { |
| 937 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 938 | if (Checker.Visit(Init)) |
| 939 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 942 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 943 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 944 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 945 | Context, SourceRange(Loc, Loc))); |
| 946 | if (auto *ML = Context.getASTMutationListener()) |
| 947 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 948 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 949 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 950 | if (!Vars.empty()) { |
| 951 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 952 | Vars); |
| 953 | D->setAccess(AS_public); |
| 954 | } |
| 955 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 956 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 957 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 958 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 959 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 960 | bool IsLoopIterVar = false) { |
| 961 | if (DVar.RefExpr) { |
| 962 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 963 | << getOpenMPClauseName(DVar.CKind); |
| 964 | return; |
| 965 | } |
| 966 | enum { |
| 967 | PDSA_StaticMemberShared, |
| 968 | PDSA_StaticLocalVarShared, |
| 969 | PDSA_LoopIterVarPrivate, |
| 970 | PDSA_LoopIterVarLinear, |
| 971 | PDSA_LoopIterVarLastprivate, |
| 972 | PDSA_ConstVarShared, |
| 973 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 974 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 975 | PDSA_LocalVarPrivate, |
| 976 | PDSA_Implicit |
| 977 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 978 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 979 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 980 | if (IsLoopIterVar) { |
| 981 | if (DVar.CKind == OMPC_private) |
| 982 | Reason = PDSA_LoopIterVarPrivate; |
| 983 | else if (DVar.CKind == OMPC_lastprivate) |
| 984 | Reason = PDSA_LoopIterVarLastprivate; |
| 985 | else |
| 986 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 987 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 988 | Reason = PDSA_TaskVarFirstprivate; |
| 989 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 990 | } else if (VD->isStaticLocal()) |
| 991 | Reason = PDSA_StaticLocalVarShared; |
| 992 | else if (VD->isStaticDataMember()) |
| 993 | Reason = PDSA_StaticMemberShared; |
| 994 | else if (VD->isFileVarDecl()) |
| 995 | Reason = PDSA_GlobalVarShared; |
| 996 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 997 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 998 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 999 | ReportHint = true; |
| 1000 | Reason = PDSA_LocalVarPrivate; |
| 1001 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1002 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1003 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1004 | << Reason << ReportHint |
| 1005 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1006 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1007 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1008 | << getOpenMPClauseName(DVar.CKind); |
| 1009 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1012 | namespace { |
| 1013 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1014 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1015 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1016 | bool ErrorFound; |
| 1017 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1018 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1019 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1020 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1021 | public: |
| 1022 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1023 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1024 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1025 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1026 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1027 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1028 | auto DVar = Stack->getTopDSA(VD, false); |
| 1029 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1030 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1031 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1032 | auto ELoc = E->getExprLoc(); |
| 1033 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1034 | // The default(none) clause requires that each variable that is referenced |
| 1035 | // in the construct, and does not have a predetermined data-sharing |
| 1036 | // attribute, must have its data-sharing attribute explicitly determined |
| 1037 | // by being listed in a data-sharing attribute clause. |
| 1038 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1039 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1040 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1041 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1042 | return; |
| 1043 | } |
| 1044 | |
| 1045 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1046 | // A list item that appears in a reduction clause of the innermost |
| 1047 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1048 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1049 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1050 | [](OpenMPDirectiveKind K) -> bool { |
| 1051 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1052 | isOpenMPWorksharingDirective(K) || |
| 1053 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1054 | }, |
| 1055 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1056 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1057 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1058 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1059 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1060 | return; |
| 1061 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1062 | |
| 1063 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1064 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1065 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1066 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1067 | } |
| 1068 | } |
| 1069 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1070 | for (auto *C : S->clauses()) { |
| 1071 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1072 | // for task directives. |
| 1073 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1074 | for (auto *CC : C->children()) { |
| 1075 | if (CC) |
| 1076 | Visit(CC); |
| 1077 | } |
| 1078 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1079 | } |
| 1080 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1081 | for (auto *C : S->children()) { |
| 1082 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1083 | Visit(C); |
| 1084 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1085 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1086 | |
| 1087 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1088 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1089 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1090 | return VarsWithInheritedDSA; |
| 1091 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1092 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1093 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1094 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1095 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1096 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1097 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1098 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1099 | switch (DKind) { |
| 1100 | case OMPD_parallel: { |
| 1101 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1102 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1103 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1104 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1105 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1106 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1107 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1108 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1109 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1110 | break; |
| 1111 | } |
| 1112 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1113 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1114 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1115 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1116 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1117 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1118 | break; |
| 1119 | } |
| 1120 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1121 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1122 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1123 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1124 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1125 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1128 | case OMPD_for_simd: { |
| 1129 | Sema::CapturedParamNameType Params[] = { |
| 1130 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1131 | }; |
| 1132 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1133 | Params); |
| 1134 | break; |
| 1135 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1136 | case OMPD_sections: { |
| 1137 | Sema::CapturedParamNameType Params[] = { |
| 1138 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1139 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1140 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1141 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1142 | break; |
| 1143 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1144 | case OMPD_section: { |
| 1145 | Sema::CapturedParamNameType Params[] = { |
| 1146 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1147 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1148 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1149 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1150 | break; |
| 1151 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1152 | case OMPD_single: { |
| 1153 | Sema::CapturedParamNameType Params[] = { |
| 1154 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1155 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1156 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1157 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1158 | break; |
| 1159 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1160 | case OMPD_master: { |
| 1161 | Sema::CapturedParamNameType Params[] = { |
| 1162 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1163 | }; |
| 1164 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1165 | Params); |
| 1166 | break; |
| 1167 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1168 | case OMPD_critical: { |
| 1169 | Sema::CapturedParamNameType Params[] = { |
| 1170 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1171 | }; |
| 1172 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1173 | Params); |
| 1174 | break; |
| 1175 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1176 | case OMPD_parallel_for: { |
| 1177 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1178 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1179 | Sema::CapturedParamNameType Params[] = { |
| 1180 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1181 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1182 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1183 | }; |
| 1184 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1185 | Params); |
| 1186 | break; |
| 1187 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1188 | case OMPD_parallel_for_simd: { |
| 1189 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1190 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1191 | Sema::CapturedParamNameType Params[] = { |
| 1192 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1193 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1194 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1195 | }; |
| 1196 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1197 | Params); |
| 1198 | break; |
| 1199 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1200 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1201 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1202 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1203 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1204 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1205 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1206 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1207 | }; |
| 1208 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1209 | Params); |
| 1210 | break; |
| 1211 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1212 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1213 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1214 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1215 | FunctionProtoType::ExtProtoInfo EPI; |
| 1216 | EPI.Variadic = true; |
| 1217 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1218 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1219 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1220 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1221 | std::make_pair(".privates.", |
| 1222 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1223 | std::make_pair( |
| 1224 | ".copy_fn.", |
| 1225 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1226 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1227 | }; |
| 1228 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1229 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1230 | // Mark this captured region as inlined, because we don't use outlined |
| 1231 | // function directly. |
| 1232 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1233 | AlwaysInlineAttr::CreateImplicit( |
| 1234 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1235 | break; |
| 1236 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1237 | case OMPD_ordered: { |
| 1238 | Sema::CapturedParamNameType Params[] = { |
| 1239 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1240 | }; |
| 1241 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1242 | Params); |
| 1243 | break; |
| 1244 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1245 | case OMPD_atomic: { |
| 1246 | Sema::CapturedParamNameType Params[] = { |
| 1247 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1248 | }; |
| 1249 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1250 | Params); |
| 1251 | break; |
| 1252 | } |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1253 | case OMPD_target: { |
| 1254 | Sema::CapturedParamNameType Params[] = { |
| 1255 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1256 | }; |
| 1257 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1258 | Params); |
| 1259 | break; |
| 1260 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1261 | case OMPD_teams: { |
| 1262 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1263 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1264 | Sema::CapturedParamNameType Params[] = { |
| 1265 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1266 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1267 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1268 | }; |
| 1269 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1270 | Params); |
| 1271 | break; |
| 1272 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1273 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1274 | case OMPD_taskyield: |
| 1275 | case OMPD_barrier: |
| 1276 | case OMPD_taskwait: |
| 1277 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1278 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1279 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1280 | llvm_unreachable("Unknown OpenMP directive"); |
| 1281 | } |
| 1282 | } |
| 1283 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1284 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1285 | ArrayRef<OMPClause *> Clauses) { |
| 1286 | if (!S.isUsable()) { |
| 1287 | ActOnCapturedRegionError(); |
| 1288 | return StmtError(); |
| 1289 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1290 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1291 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1292 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
| 1293 | Clause->getClauseKind() == OMPC_copyprivate) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1294 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1295 | for (auto *VarRef : Clause->children()) { |
| 1296 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1297 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1298 | } |
| 1299 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1300 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1301 | Clause->getClauseKind() == OMPC_schedule) { |
| 1302 | // Mark all variables in private list clauses as used in inner region. |
| 1303 | // Required for proper codegen of combined directives. |
| 1304 | // TODO: add processing for other clauses. |
| 1305 | if (auto *E = cast_or_null<Expr>( |
| 1306 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1307 | MarkDeclarationsReferencedInExpr(E); |
| 1308 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | return ActOnCapturedRegionEnd(S.get()); |
| 1312 | } |
| 1313 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1314 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1315 | OpenMPDirectiveKind CurrentRegion, |
| 1316 | const DeclarationNameInfo &CurrentName, |
| 1317 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1318 | // Allowed nesting of constructs |
| 1319 | // +------------------+-----------------+------------------------------------+ |
| 1320 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1321 | // +------------------+-----------------+------------------------------------+ |
| 1322 | // | parallel | parallel | * | |
| 1323 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1324 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1325 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1326 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1327 | // | parallel | simd | * | |
| 1328 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1329 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1330 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1331 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1332 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1333 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1334 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1335 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1336 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1337 | // | parallel | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1338 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1339 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1340 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1341 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1342 | // | parallel | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1343 | // +------------------+-----------------+------------------------------------+ |
| 1344 | // | for | parallel | * | |
| 1345 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1346 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1347 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1348 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1349 | // | for | simd | * | |
| 1350 | // | for | sections | + | |
| 1351 | // | for | section | + | |
| 1352 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1353 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1354 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1355 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1356 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1357 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1358 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1359 | // | for | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1360 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1361 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1362 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1363 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1364 | // | for | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1365 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1366 | // | master | parallel | * | |
| 1367 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1368 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1369 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1370 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1371 | // | master | simd | * | |
| 1372 | // | master | sections | + | |
| 1373 | // | master | section | + | |
| 1374 | // | master | single | + | |
| 1375 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1376 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1377 | // | master |parallel sections| * | |
| 1378 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1379 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1380 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1381 | // | master | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1382 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1383 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1384 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1385 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1386 | // | master | teams | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1387 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1388 | // | critical | parallel | * | |
| 1389 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1390 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1391 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1392 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1393 | // | critical | simd | * | |
| 1394 | // | critical | sections | + | |
| 1395 | // | critical | section | + | |
| 1396 | // | critical | single | + | |
| 1397 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1398 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1399 | // | critical |parallel sections| * | |
| 1400 | // | critical | task | * | |
| 1401 | // | critical | taskyield | * | |
| 1402 | // | critical | barrier | + | |
| 1403 | // | critical | taskwait | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1404 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1405 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1406 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1407 | // | critical | teams | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1408 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1409 | // | simd | parallel | | |
| 1410 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1411 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1412 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1413 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1414 | // | simd | simd | | |
| 1415 | // | simd | sections | | |
| 1416 | // | simd | section | | |
| 1417 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1418 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1419 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1420 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1421 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1422 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1423 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1424 | // | simd | taskwait | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1425 | // | simd | flush | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1426 | // | simd | ordered | | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1427 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1428 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1429 | // | simd | teams | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1430 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1431 | // | for simd | parallel | | |
| 1432 | // | for simd | for | | |
| 1433 | // | for simd | for simd | | |
| 1434 | // | for simd | master | | |
| 1435 | // | for simd | critical | | |
| 1436 | // | for simd | simd | | |
| 1437 | // | for simd | sections | | |
| 1438 | // | for simd | section | | |
| 1439 | // | for simd | single | | |
| 1440 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1441 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1442 | // | for simd |parallel sections| | |
| 1443 | // | for simd | task | | |
| 1444 | // | for simd | taskyield | | |
| 1445 | // | for simd | barrier | | |
| 1446 | // | for simd | taskwait | | |
| 1447 | // | for simd | flush | | |
| 1448 | // | for simd | ordered | | |
| 1449 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1450 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1451 | // | for simd | teams | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1452 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1453 | // | parallel for simd| parallel | | |
| 1454 | // | parallel for simd| for | | |
| 1455 | // | parallel for simd| for simd | | |
| 1456 | // | parallel for simd| master | | |
| 1457 | // | parallel for simd| critical | | |
| 1458 | // | parallel for simd| simd | | |
| 1459 | // | parallel for simd| sections | | |
| 1460 | // | parallel for simd| section | | |
| 1461 | // | parallel for simd| single | | |
| 1462 | // | parallel for simd| parallel for | | |
| 1463 | // | parallel for simd|parallel for simd| | |
| 1464 | // | parallel for simd|parallel sections| | |
| 1465 | // | parallel for simd| task | | |
| 1466 | // | parallel for simd| taskyield | | |
| 1467 | // | parallel for simd| barrier | | |
| 1468 | // | parallel for simd| taskwait | | |
| 1469 | // | parallel for simd| flush | | |
| 1470 | // | parallel for simd| ordered | | |
| 1471 | // | parallel for simd| atomic | | |
| 1472 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1473 | // | parallel for simd| teams | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1474 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1475 | // | sections | parallel | * | |
| 1476 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1477 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1478 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1479 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1480 | // | sections | simd | * | |
| 1481 | // | sections | sections | + | |
| 1482 | // | sections | section | * | |
| 1483 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1484 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1485 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1486 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1487 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1488 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1489 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1490 | // | sections | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1491 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1492 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1493 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1494 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1495 | // | sections | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1496 | // +------------------+-----------------+------------------------------------+ |
| 1497 | // | section | parallel | * | |
| 1498 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1499 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1500 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1501 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1502 | // | section | simd | * | |
| 1503 | // | section | sections | + | |
| 1504 | // | section | section | + | |
| 1505 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1506 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1507 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1508 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1509 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1510 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1511 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1512 | // | section | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1513 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1514 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1515 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1516 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1517 | // | section | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1518 | // +------------------+-----------------+------------------------------------+ |
| 1519 | // | single | parallel | * | |
| 1520 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1521 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1522 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1523 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1524 | // | single | simd | * | |
| 1525 | // | single | sections | + | |
| 1526 | // | single | section | + | |
| 1527 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1528 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1529 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1530 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1531 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1532 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1533 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1534 | // | single | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1535 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1536 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1537 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1538 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1539 | // | single | teams | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1540 | // +------------------+-----------------+------------------------------------+ |
| 1541 | // | parallel for | parallel | * | |
| 1542 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1543 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1544 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1545 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1546 | // | parallel for | simd | * | |
| 1547 | // | parallel for | sections | + | |
| 1548 | // | parallel for | section | + | |
| 1549 | // | parallel for | single | + | |
| 1550 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1551 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1552 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1553 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1554 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1555 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1556 | // | parallel for | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1557 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1558 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1559 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1560 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1561 | // | parallel for | teams | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1562 | // +------------------+-----------------+------------------------------------+ |
| 1563 | // | parallel sections| parallel | * | |
| 1564 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1565 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1566 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1567 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1568 | // | parallel sections| simd | * | |
| 1569 | // | parallel sections| sections | + | |
| 1570 | // | parallel sections| section | * | |
| 1571 | // | parallel sections| single | + | |
| 1572 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1573 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1574 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1575 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1576 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1577 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1578 | // | parallel sections| taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1579 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1580 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1581 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1582 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1583 | // | parallel sections| teams | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1584 | // +------------------+-----------------+------------------------------------+ |
| 1585 | // | task | parallel | * | |
| 1586 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1587 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1588 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1589 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1590 | // | task | simd | * | |
| 1591 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1592 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1593 | // | task | single | + | |
| 1594 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1595 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1596 | // | task |parallel sections| * | |
| 1597 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1598 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1599 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1600 | // | task | taskwait | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1601 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1602 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1603 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1604 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1605 | // | task | teams | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1606 | // +------------------+-----------------+------------------------------------+ |
| 1607 | // | ordered | parallel | * | |
| 1608 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1609 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1610 | // | ordered | master | * | |
| 1611 | // | ordered | critical | * | |
| 1612 | // | ordered | simd | * | |
| 1613 | // | ordered | sections | + | |
| 1614 | // | ordered | section | + | |
| 1615 | // | ordered | single | + | |
| 1616 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1617 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1618 | // | ordered |parallel sections| * | |
| 1619 | // | ordered | task | * | |
| 1620 | // | ordered | taskyield | * | |
| 1621 | // | ordered | barrier | + | |
| 1622 | // | ordered | taskwait | * | |
| 1623 | // | ordered | flush | * | |
| 1624 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1625 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1626 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1627 | // | ordered | teams | + | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1628 | // +------------------+-----------------+------------------------------------+ |
| 1629 | // | atomic | parallel | | |
| 1630 | // | atomic | for | | |
| 1631 | // | atomic | for simd | | |
| 1632 | // | atomic | master | | |
| 1633 | // | atomic | critical | | |
| 1634 | // | atomic | simd | | |
| 1635 | // | atomic | sections | | |
| 1636 | // | atomic | section | | |
| 1637 | // | atomic | single | | |
| 1638 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1639 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1640 | // | atomic |parallel sections| | |
| 1641 | // | atomic | task | | |
| 1642 | // | atomic | taskyield | | |
| 1643 | // | atomic | barrier | | |
| 1644 | // | atomic | taskwait | | |
| 1645 | // | atomic | flush | | |
| 1646 | // | atomic | ordered | | |
| 1647 | // | atomic | atomic | | |
| 1648 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1649 | // | atomic | teams | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1650 | // +------------------+-----------------+------------------------------------+ |
| 1651 | // | target | parallel | * | |
| 1652 | // | target | for | * | |
| 1653 | // | target | for simd | * | |
| 1654 | // | target | master | * | |
| 1655 | // | target | critical | * | |
| 1656 | // | target | simd | * | |
| 1657 | // | target | sections | * | |
| 1658 | // | target | section | * | |
| 1659 | // | target | single | * | |
| 1660 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1661 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1662 | // | target |parallel sections| * | |
| 1663 | // | target | task | * | |
| 1664 | // | target | taskyield | * | |
| 1665 | // | target | barrier | * | |
| 1666 | // | target | taskwait | * | |
| 1667 | // | target | flush | * | |
| 1668 | // | target | ordered | * | |
| 1669 | // | target | atomic | * | |
| 1670 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1671 | // | target | teams | * | |
| 1672 | // +------------------+-----------------+------------------------------------+ |
| 1673 | // | teams | parallel | * | |
| 1674 | // | teams | for | + | |
| 1675 | // | teams | for simd | + | |
| 1676 | // | teams | master | + | |
| 1677 | // | teams | critical | + | |
| 1678 | // | teams | simd | + | |
| 1679 | // | teams | sections | + | |
| 1680 | // | teams | section | + | |
| 1681 | // | teams | single | + | |
| 1682 | // | teams | parallel for | * | |
| 1683 | // | teams |parallel for simd| * | |
| 1684 | // | teams |parallel sections| * | |
| 1685 | // | teams | task | + | |
| 1686 | // | teams | taskyield | + | |
| 1687 | // | teams | barrier | + | |
| 1688 | // | teams | taskwait | + | |
| 1689 | // | teams | flush | + | |
| 1690 | // | teams | ordered | + | |
| 1691 | // | teams | atomic | + | |
| 1692 | // | teams | target | + | |
| 1693 | // | teams | teams | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1694 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1695 | if (Stack->getCurScope()) { |
| 1696 | auto ParentRegion = Stack->getParentDirective(); |
| 1697 | bool NestingProhibited = false; |
| 1698 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1699 | enum { |
| 1700 | NoRecommend, |
| 1701 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1702 | ShouldBeInOrderedRegion, |
| 1703 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1704 | } Recommend = NoRecommend; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1705 | if (isOpenMPSimdDirective(ParentRegion)) { |
| 1706 | // OpenMP [2.16, Nesting of Regions] |
| 1707 | // OpenMP constructs may not be nested inside a simd region. |
| 1708 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1709 | return true; |
| 1710 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1711 | if (ParentRegion == OMPD_atomic) { |
| 1712 | // OpenMP [2.16, Nesting of Regions] |
| 1713 | // OpenMP constructs may not be nested inside an atomic region. |
| 1714 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1715 | return true; |
| 1716 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1717 | if (CurrentRegion == OMPD_section) { |
| 1718 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1719 | // Orphaned section directives are prohibited. That is, the section |
| 1720 | // directives must appear within the sections construct and must not be |
| 1721 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1722 | if (ParentRegion != OMPD_sections && |
| 1723 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1724 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1725 | << (ParentRegion != OMPD_unknown) |
| 1726 | << getOpenMPDirectiveName(ParentRegion); |
| 1727 | return true; |
| 1728 | } |
| 1729 | return false; |
| 1730 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1731 | // Allow some constructs to be orphaned (they could be used in functions, |
| 1732 | // called from OpenMP regions with the required preconditions). |
| 1733 | if (ParentRegion == OMPD_unknown) |
| 1734 | return false; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1735 | if (CurrentRegion == OMPD_master) { |
| 1736 | // OpenMP [2.16, Nesting of Regions] |
| 1737 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1738 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1739 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 1740 | ParentRegion == OMPD_task; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1741 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 1742 | // OpenMP [2.16, Nesting of Regions] |
| 1743 | // A critical region may not be nested (closely or otherwise) inside a |
| 1744 | // critical region with the same name. Note that this restriction is not |
| 1745 | // sufficient to prevent deadlock. |
| 1746 | SourceLocation PreviousCriticalLoc; |
| 1747 | bool DeadLock = |
| 1748 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 1749 | OpenMPDirectiveKind K, |
| 1750 | const DeclarationNameInfo &DNI, |
| 1751 | SourceLocation Loc) |
| 1752 | ->bool { |
| 1753 | if (K == OMPD_critical && |
| 1754 | DNI.getName() == CurrentName.getName()) { |
| 1755 | PreviousCriticalLoc = Loc; |
| 1756 | return true; |
| 1757 | } else |
| 1758 | return false; |
| 1759 | }, |
| 1760 | false /* skip top directive */); |
| 1761 | if (DeadLock) { |
| 1762 | SemaRef.Diag(StartLoc, |
| 1763 | diag::err_omp_prohibited_region_critical_same_name) |
| 1764 | << CurrentName.getName(); |
| 1765 | if (PreviousCriticalLoc.isValid()) |
| 1766 | SemaRef.Diag(PreviousCriticalLoc, |
| 1767 | diag::note_omp_previous_critical_region); |
| 1768 | return true; |
| 1769 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1770 | } else if (CurrentRegion == OMPD_barrier) { |
| 1771 | // OpenMP [2.16, Nesting of Regions] |
| 1772 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1773 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1774 | NestingProhibited = |
| 1775 | isOpenMPWorksharingDirective(ParentRegion) || |
| 1776 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1777 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1778 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1779 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1780 | // OpenMP [2.16, Nesting of Regions] |
| 1781 | // A worksharing region may not be closely nested inside a worksharing, |
| 1782 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1783 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1784 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1785 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1786 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
| 1787 | Recommend = ShouldBeInParallelRegion; |
| 1788 | } else if (CurrentRegion == OMPD_ordered) { |
| 1789 | // OpenMP [2.16, Nesting of Regions] |
| 1790 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1791 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1792 | // An ordered region must be closely nested inside a loop region (or |
| 1793 | // parallel loop region) with an ordered clause. |
| 1794 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1795 | ParentRegion == OMPD_task || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1796 | !Stack->isParentOrderedRegion(); |
| 1797 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1798 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 1799 | // OpenMP [2.16, Nesting of Regions] |
| 1800 | // If specified, a teams construct must be contained within a target |
| 1801 | // construct. |
| 1802 | NestingProhibited = ParentRegion != OMPD_target; |
| 1803 | Recommend = ShouldBeInTargetRegion; |
| 1804 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 1805 | } |
| 1806 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 1807 | // OpenMP [2.16, Nesting of Regions] |
| 1808 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 1809 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 1810 | // constructs that can be closely nested in the teams region. |
| 1811 | // TODO: add distribute directive. |
| 1812 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 1813 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1814 | } |
| 1815 | if (NestingProhibited) { |
| 1816 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1817 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 1818 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1819 | return true; |
| 1820 | } |
| 1821 | } |
| 1822 | return false; |
| 1823 | } |
| 1824 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1825 | StmtResult Sema::ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1826 | const DeclarationNameInfo &DirName, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1827 | ArrayRef<OMPClause *> Clauses, |
| 1828 | Stmt *AStmt, |
| 1829 | SourceLocation StartLoc, |
| 1830 | SourceLocation EndLoc) { |
| 1831 | StmtResult Res = StmtError(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1832 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1833 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1834 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1835 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1836 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1837 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1838 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1839 | if (AStmt) { |
| 1840 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1841 | |
| 1842 | // Check default data sharing attributes for referenced variables. |
| 1843 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 1844 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 1845 | if (DSAChecker.isErrorFound()) |
| 1846 | return StmtError(); |
| 1847 | // Generate list of implicitly defined firstprivate variables. |
| 1848 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1849 | |
| 1850 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 1851 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 1852 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 1853 | SourceLocation(), SourceLocation())) { |
| 1854 | ClausesWithImplicit.push_back(Implicit); |
| 1855 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 1856 | DSAChecker.getImplicitFirstprivate().size(); |
| 1857 | } else |
| 1858 | ErrorFound = true; |
| 1859 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1860 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1861 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1862 | switch (Kind) { |
| 1863 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1864 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1865 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1866 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1867 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1868 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 1869 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1870 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1871 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1872 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 1873 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1874 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1875 | case OMPD_for_simd: |
| 1876 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1877 | EndLoc, VarsWithInheritedDSA); |
| 1878 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1879 | case OMPD_sections: |
| 1880 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1881 | EndLoc); |
| 1882 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1883 | case OMPD_section: |
| 1884 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1885 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1886 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 1887 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1888 | case OMPD_single: |
| 1889 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1890 | EndLoc); |
| 1891 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1892 | case OMPD_master: |
| 1893 | assert(ClausesWithImplicit.empty() && |
| 1894 | "No clauses are allowed for 'omp master' directive"); |
| 1895 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 1896 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1897 | case OMPD_critical: |
| 1898 | assert(ClausesWithImplicit.empty() && |
| 1899 | "No clauses are allowed for 'omp critical' directive"); |
| 1900 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 1901 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1902 | case OMPD_parallel_for: |
| 1903 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1904 | EndLoc, VarsWithInheritedDSA); |
| 1905 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1906 | case OMPD_parallel_for_simd: |
| 1907 | Res = ActOnOpenMPParallelForSimdDirective( |
| 1908 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 1909 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1910 | case OMPD_parallel_sections: |
| 1911 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 1912 | StartLoc, EndLoc); |
| 1913 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1914 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1915 | Res = |
| 1916 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 1917 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1918 | case OMPD_taskyield: |
| 1919 | assert(ClausesWithImplicit.empty() && |
| 1920 | "No clauses are allowed for 'omp taskyield' directive"); |
| 1921 | assert(AStmt == nullptr && |
| 1922 | "No associated statement allowed for 'omp taskyield' directive"); |
| 1923 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 1924 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1925 | case OMPD_barrier: |
| 1926 | assert(ClausesWithImplicit.empty() && |
| 1927 | "No clauses are allowed for 'omp barrier' directive"); |
| 1928 | assert(AStmt == nullptr && |
| 1929 | "No associated statement allowed for 'omp barrier' directive"); |
| 1930 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 1931 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1932 | case OMPD_taskwait: |
| 1933 | assert(ClausesWithImplicit.empty() && |
| 1934 | "No clauses are allowed for 'omp taskwait' directive"); |
| 1935 | assert(AStmt == nullptr && |
| 1936 | "No associated statement allowed for 'omp taskwait' directive"); |
| 1937 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 1938 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1939 | case OMPD_flush: |
| 1940 | assert(AStmt == nullptr && |
| 1941 | "No associated statement allowed for 'omp flush' directive"); |
| 1942 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 1943 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1944 | case OMPD_ordered: |
| 1945 | assert(ClausesWithImplicit.empty() && |
| 1946 | "No clauses are allowed for 'omp ordered' directive"); |
| 1947 | Res = ActOnOpenMPOrderedDirective(AStmt, StartLoc, EndLoc); |
| 1948 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1949 | case OMPD_atomic: |
| 1950 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1951 | EndLoc); |
| 1952 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1953 | case OMPD_teams: |
| 1954 | Res = |
| 1955 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 1956 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1957 | case OMPD_target: |
| 1958 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1959 | EndLoc); |
| 1960 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1961 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1962 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1963 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1964 | llvm_unreachable("Unknown OpenMP directive"); |
| 1965 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1966 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1967 | for (auto P : VarsWithInheritedDSA) { |
| 1968 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 1969 | << P.first << P.second->getSourceRange(); |
| 1970 | } |
| 1971 | if (!VarsWithInheritedDSA.empty()) |
| 1972 | return StmtError(); |
| 1973 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1974 | if (ErrorFound) |
| 1975 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1976 | return Res; |
| 1977 | } |
| 1978 | |
| 1979 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 1980 | Stmt *AStmt, |
| 1981 | SourceLocation StartLoc, |
| 1982 | SourceLocation EndLoc) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1983 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1984 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 1985 | // 1.2.2 OpenMP Language Terminology |
| 1986 | // Structured block - An executable statement with a single entry at the |
| 1987 | // top and a single exit at the bottom. |
| 1988 | // The point of exit cannot be a branch out of the structured block. |
| 1989 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 1990 | CS->getCapturedDecl()->setNothrow(); |
| 1991 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1992 | getCurFunction()->setHasBranchProtectedScope(); |
| 1993 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 1994 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 1995 | AStmt); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 1998 | namespace { |
| 1999 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2000 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2001 | /// for IR generation. |
| 2002 | class OpenMPIterationSpaceChecker { |
| 2003 | /// \brief Reference to Sema. |
| 2004 | Sema &SemaRef; |
| 2005 | /// \brief A location for diagnostics (when there is no some better location). |
| 2006 | SourceLocation DefaultLoc; |
| 2007 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2008 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2009 | /// \brief A source location for referring to loop init later. |
| 2010 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2011 | /// \brief A source location for referring to condition later. |
| 2012 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2013 | /// \brief A source location for referring to increment later. |
| 2014 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2015 | /// \brief Loop variable. |
| 2016 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2017 | /// \brief Reference to loop variable. |
| 2018 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2019 | /// \brief Lower bound (initializer for the var). |
| 2020 | Expr *LB; |
| 2021 | /// \brief Upper bound. |
| 2022 | Expr *UB; |
| 2023 | /// \brief Loop step (increment). |
| 2024 | Expr *Step; |
| 2025 | /// \brief This flag is true when condition is one of: |
| 2026 | /// Var < UB |
| 2027 | /// Var <= UB |
| 2028 | /// UB > Var |
| 2029 | /// UB >= Var |
| 2030 | bool TestIsLessOp; |
| 2031 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2032 | bool TestIsStrictOp; |
| 2033 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2034 | bool SubtractStep; |
| 2035 | |
| 2036 | public: |
| 2037 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2038 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2039 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2040 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2041 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2042 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2043 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2044 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2045 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2046 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2047 | /// for less/greater and for strict/non-strict comparison. |
| 2048 | bool CheckCond(Expr *S); |
| 2049 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2050 | /// does not conform, otherwise save loop step (#Step). |
| 2051 | bool CheckInc(Expr *S); |
| 2052 | /// \brief Return the loop counter variable. |
| 2053 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2054 | /// \brief Return the reference expression to loop counter variable. |
| 2055 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2056 | /// \brief Source range of the loop init. |
| 2057 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2058 | /// \brief Source range of the loop condition. |
| 2059 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2060 | /// \brief Source range of the loop increment. |
| 2061 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2062 | /// \brief True if the step should be subtracted. |
| 2063 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2064 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2065 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2066 | /// \brief Build the precondition expression for the loops. |
| 2067 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2068 | /// \brief Build reference expression to the counter be used for codegen. |
| 2069 | Expr *BuildCounterVar() const; |
| 2070 | /// \brief Build initization of the counter be used for codegen. |
| 2071 | Expr *BuildCounterInit() const; |
| 2072 | /// \brief Build step of the counter be used for codegen. |
| 2073 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2074 | /// \brief Return true if any expression is dependent. |
| 2075 | bool Dependent() const; |
| 2076 | |
| 2077 | private: |
| 2078 | /// \brief Check the right-hand side of an assignment in the increment |
| 2079 | /// expression. |
| 2080 | bool CheckIncRHS(Expr *RHS); |
| 2081 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2082 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2083 | /// \brief Helper to set upper bound. |
| 2084 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR, |
| 2085 | const SourceLocation &SL); |
| 2086 | /// \brief Helper to set loop increment. |
| 2087 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2088 | }; |
| 2089 | |
| 2090 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2091 | if (!Var) { |
| 2092 | assert(!LB && !UB && !Step); |
| 2093 | return false; |
| 2094 | } |
| 2095 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2096 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2097 | } |
| 2098 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2099 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2100 | DeclRefExpr *NewVarRefExpr, |
| 2101 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2102 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2103 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2104 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2105 | if (!NewVar || !NewLB) |
| 2106 | return true; |
| 2107 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2108 | VarRef = NewVarRefExpr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2109 | LB = NewLB; |
| 2110 | return false; |
| 2111 | } |
| 2112 | |
| 2113 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| 2114 | const SourceRange &SR, |
| 2115 | const SourceLocation &SL) { |
| 2116 | // State consistency checking to ensure correct usage. |
| 2117 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2118 | !TestIsLessOp && !TestIsStrictOp); |
| 2119 | if (!NewUB) |
| 2120 | return true; |
| 2121 | UB = NewUB; |
| 2122 | TestIsLessOp = LessOp; |
| 2123 | TestIsStrictOp = StrictOp; |
| 2124 | ConditionSrcRange = SR; |
| 2125 | ConditionLoc = SL; |
| 2126 | return false; |
| 2127 | } |
| 2128 | |
| 2129 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2130 | // State consistency checking to ensure correct usage. |
| 2131 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2132 | if (!NewStep) |
| 2133 | return true; |
| 2134 | if (!NewStep->isValueDependent()) { |
| 2135 | // Check that the step is integer expression. |
| 2136 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2137 | ExprResult Val = |
| 2138 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2139 | if (Val.isInvalid()) |
| 2140 | return true; |
| 2141 | NewStep = Val.get(); |
| 2142 | |
| 2143 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2144 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2145 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2146 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2147 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2148 | // the loop. |
| 2149 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2150 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2151 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2152 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2153 | // the loop. |
| 2154 | llvm::APSInt Result; |
| 2155 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2156 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2157 | bool IsConstNeg = |
| 2158 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2159 | bool IsConstPos = |
| 2160 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2161 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2162 | if (UB && (IsConstZero || |
| 2163 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2164 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2165 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2166 | diag::err_omp_loop_incr_not_compatible) |
| 2167 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2168 | SemaRef.Diag(ConditionLoc, |
| 2169 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2170 | << TestIsLessOp << ConditionSrcRange; |
| 2171 | return true; |
| 2172 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2173 | if (TestIsLessOp == Subtract) { |
| 2174 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2175 | NewStep).get(); |
| 2176 | Subtract = !Subtract; |
| 2177 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
| 2180 | Step = NewStep; |
| 2181 | SubtractStep = Subtract; |
| 2182 | return false; |
| 2183 | } |
| 2184 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2185 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2186 | // Check init-expr for canonical loop form and save loop counter |
| 2187 | // variable - #Var and its initialization value - #LB. |
| 2188 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2189 | // var = lb |
| 2190 | // integer-type var = lb |
| 2191 | // random-access-iterator-type var = lb |
| 2192 | // pointer-type var = lb |
| 2193 | // |
| 2194 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2195 | if (EmitDiags) { |
| 2196 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2197 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2198 | return true; |
| 2199 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2200 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2201 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2202 | S = E->IgnoreParens(); |
| 2203 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2204 | if (BO->getOpcode() == BO_Assign) |
| 2205 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2206 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2207 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2208 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2209 | if (DS->isSingleDecl()) { |
| 2210 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
| 2211 | if (Var->hasInit()) { |
| 2212 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2213 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2214 | SemaRef.Diag(S->getLocStart(), |
| 2215 | diag::ext_omp_loop_not_canonical_init) |
| 2216 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2217 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2222 | if (CE->getOperator() == OO_Equal) |
| 2223 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2224 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2225 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2226 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2227 | if (EmitDiags) { |
| 2228 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2229 | << S->getSourceRange(); |
| 2230 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2231 | return true; |
| 2232 | } |
| 2233 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2234 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2235 | /// variable (which may be the loop variable) if possible. |
| 2236 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2237 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2238 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2239 | E = E->IgnoreParenImpCasts(); |
| 2240 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2241 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| 2242 | if (Ctor->isCopyConstructor() && CE->getNumArgs() == 1 && |
| 2243 | CE->getArg(0) != nullptr) |
| 2244 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2245 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2246 | if (!DRE) |
| 2247 | return nullptr; |
| 2248 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2249 | } |
| 2250 | |
| 2251 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2252 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2253 | // less/greater and for strict/non-strict comparison. |
| 2254 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2255 | // var relational-op b |
| 2256 | // b relational-op var |
| 2257 | // |
| 2258 | if (!S) { |
| 2259 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2260 | return true; |
| 2261 | } |
| 2262 | S = S->IgnoreParenImpCasts(); |
| 2263 | SourceLocation CondLoc = S->getLocStart(); |
| 2264 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2265 | if (BO->isRelationalOp()) { |
| 2266 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2267 | return SetUB(BO->getRHS(), |
| 2268 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2269 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2270 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2271 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2272 | return SetUB(BO->getLHS(), |
| 2273 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2274 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2275 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2276 | } |
| 2277 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2278 | if (CE->getNumArgs() == 2) { |
| 2279 | auto Op = CE->getOperator(); |
| 2280 | switch (Op) { |
| 2281 | case OO_Greater: |
| 2282 | case OO_GreaterEqual: |
| 2283 | case OO_Less: |
| 2284 | case OO_LessEqual: |
| 2285 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2286 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2287 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2288 | CE->getOperatorLoc()); |
| 2289 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2290 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2291 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2292 | CE->getOperatorLoc()); |
| 2293 | break; |
| 2294 | default: |
| 2295 | break; |
| 2296 | } |
| 2297 | } |
| 2298 | } |
| 2299 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2300 | << S->getSourceRange() << Var; |
| 2301 | return true; |
| 2302 | } |
| 2303 | |
| 2304 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2305 | // RHS of canonical loop form increment can be: |
| 2306 | // var + incr |
| 2307 | // incr + var |
| 2308 | // var - incr |
| 2309 | // |
| 2310 | RHS = RHS->IgnoreParenImpCasts(); |
| 2311 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2312 | if (BO->isAdditiveOp()) { |
| 2313 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2314 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2315 | return SetStep(BO->getRHS(), !IsAdd); |
| 2316 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2317 | return SetStep(BO->getLHS(), false); |
| 2318 | } |
| 2319 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2320 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2321 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2322 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2323 | return SetStep(CE->getArg(1), !IsAdd); |
| 2324 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2325 | return SetStep(CE->getArg(0), false); |
| 2326 | } |
| 2327 | } |
| 2328 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2329 | << RHS->getSourceRange() << Var; |
| 2330 | return true; |
| 2331 | } |
| 2332 | |
| 2333 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2334 | // Check incr-expr for canonical loop form and return true if it |
| 2335 | // does not conform. |
| 2336 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2337 | // ++var |
| 2338 | // var++ |
| 2339 | // --var |
| 2340 | // var-- |
| 2341 | // var += incr |
| 2342 | // var -= incr |
| 2343 | // var = var + incr |
| 2344 | // var = incr + var |
| 2345 | // var = var - incr |
| 2346 | // |
| 2347 | if (!S) { |
| 2348 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2349 | return true; |
| 2350 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2351 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2352 | S = S->IgnoreParens(); |
| 2353 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2354 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2355 | return SetStep( |
| 2356 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2357 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2358 | false); |
| 2359 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2360 | switch (BO->getOpcode()) { |
| 2361 | case BO_AddAssign: |
| 2362 | case BO_SubAssign: |
| 2363 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2364 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2365 | break; |
| 2366 | case BO_Assign: |
| 2367 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2368 | return CheckIncRHS(BO->getRHS()); |
| 2369 | break; |
| 2370 | default: |
| 2371 | break; |
| 2372 | } |
| 2373 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2374 | switch (CE->getOperator()) { |
| 2375 | case OO_PlusPlus: |
| 2376 | case OO_MinusMinus: |
| 2377 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2378 | return SetStep( |
| 2379 | SemaRef.ActOnIntegerConstant( |
| 2380 | CE->getLocStart(), |
| 2381 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2382 | false); |
| 2383 | break; |
| 2384 | case OO_PlusEqual: |
| 2385 | case OO_MinusEqual: |
| 2386 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2387 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2388 | break; |
| 2389 | case OO_Equal: |
| 2390 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2391 | return CheckIncRHS(CE->getArg(1)); |
| 2392 | break; |
| 2393 | default: |
| 2394 | break; |
| 2395 | } |
| 2396 | } |
| 2397 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2398 | << S->getSourceRange() << Var; |
| 2399 | return true; |
| 2400 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2401 | |
| 2402 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2403 | Expr * |
| 2404 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2405 | const bool LimitedType) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2406 | ExprResult Diff; |
| 2407 | if (Var->getType()->isIntegerType() || Var->getType()->isPointerType() || |
| 2408 | SemaRef.getLangOpts().CPlusPlus) { |
| 2409 | // Upper - Lower |
| 2410 | Expr *Upper = TestIsLessOp ? UB : LB; |
| 2411 | Expr *Lower = TestIsLessOp ? LB : UB; |
| 2412 | |
| 2413 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2414 | |
| 2415 | if (!Diff.isUsable() && Var->getType()->getAsCXXRecordDecl()) { |
| 2416 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2417 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2418 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2419 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2420 | return nullptr; |
| 2421 | } |
| 2422 | } |
| 2423 | |
| 2424 | if (!Diff.isUsable()) |
| 2425 | return nullptr; |
| 2426 | |
| 2427 | // Upper - Lower [- 1] |
| 2428 | if (TestIsStrictOp) |
| 2429 | Diff = SemaRef.BuildBinOp( |
| 2430 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2431 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2432 | if (!Diff.isUsable()) |
| 2433 | return nullptr; |
| 2434 | |
| 2435 | // Upper - Lower [- 1] + Step |
| 2436 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), |
| 2437 | Step->IgnoreImplicit()); |
| 2438 | if (!Diff.isUsable()) |
| 2439 | return nullptr; |
| 2440 | |
| 2441 | // Parentheses (for dumping/debugging purposes only). |
| 2442 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 2443 | if (!Diff.isUsable()) |
| 2444 | return nullptr; |
| 2445 | |
| 2446 | // (Upper - Lower [- 1] + Step) / Step |
| 2447 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), |
| 2448 | Step->IgnoreImplicit()); |
| 2449 | if (!Diff.isUsable()) |
| 2450 | return nullptr; |
| 2451 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2452 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
| 2453 | if (LimitedType) { |
| 2454 | auto &C = SemaRef.Context; |
| 2455 | QualType Type = Diff.get()->getType(); |
| 2456 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 2457 | if (NewSize != C.getTypeSize(Type)) { |
| 2458 | if (NewSize < C.getTypeSize(Type)) { |
| 2459 | assert(NewSize == 64 && "incorrect loop var size"); |
| 2460 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 2461 | << InitSrcRange << ConditionSrcRange; |
| 2462 | } |
| 2463 | QualType NewType = C.getIntTypeForBitwidth( |
| 2464 | NewSize, Type->hasSignedIntegerRepresentation()); |
| 2465 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 2466 | Sema::AA_Converting, true); |
| 2467 | if (!Diff.isUsable()) |
| 2468 | return nullptr; |
| 2469 | } |
| 2470 | } |
| 2471 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2472 | return Diff.get(); |
| 2473 | } |
| 2474 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2475 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 2476 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 2477 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 2478 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 2479 | auto CondExpr = SemaRef.BuildBinOp( |
| 2480 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 2481 | : (TestIsStrictOp ? BO_GT : BO_GE), |
| 2482 | LB, UB); |
| 2483 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 2484 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 2485 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 2486 | } |
| 2487 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2488 | /// \brief Build reference expression to the counter be used for codegen. |
| 2489 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2490 | return buildDeclRefExpr(SemaRef, Var, Var->getType(), DefaultLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | /// \brief Build initization of the counter be used for codegen. |
| 2494 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 2495 | |
| 2496 | /// \brief Build step of the counter be used for codegen. |
| 2497 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 2498 | |
| 2499 | /// \brief Iteration space of a single for loop. |
| 2500 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2501 | /// \brief Condition of the loop. |
| 2502 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2503 | /// \brief This expression calculates the number of iterations in the loop. |
| 2504 | /// It is always possible to calculate it before starting the loop. |
| 2505 | Expr *NumIterations; |
| 2506 | /// \brief The loop counter variable. |
| 2507 | Expr *CounterVar; |
| 2508 | /// \brief This is initializer for the initial value of #CounterVar. |
| 2509 | Expr *CounterInit; |
| 2510 | /// \brief This is step for the #CounterVar used to generate its update: |
| 2511 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 2512 | Expr *CounterStep; |
| 2513 | /// \brief Should step be subtracted? |
| 2514 | bool Subtract; |
| 2515 | /// \brief Source range of the loop init. |
| 2516 | SourceRange InitSrcRange; |
| 2517 | /// \brief Source range of the loop condition. |
| 2518 | SourceRange CondSrcRange; |
| 2519 | /// \brief Source range of the loop increment. |
| 2520 | SourceRange IncSrcRange; |
| 2521 | }; |
| 2522 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2523 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2524 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2525 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 2526 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 2527 | assert(Init && "Expected loop in canonical form."); |
| 2528 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 2529 | if (CollapseIteration > 0 && |
| 2530 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 2531 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 2532 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 2533 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 2534 | } |
| 2535 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 2536 | } |
| 2537 | } |
| 2538 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2539 | /// \brief Called on a for stmt to check and extract its iteration space |
| 2540 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2541 | static bool CheckOpenMPIterationSpace( |
| 2542 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 2543 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
| 2544 | Expr *NestedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2545 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 2546 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2547 | // OpenMP [2.6, Canonical Loop Form] |
| 2548 | // for (init-expr; test-expr; incr-expr) structured-block |
| 2549 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 2550 | if (!For) { |
| 2551 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2552 | << (NestedLoopCountExpr != nullptr) << getOpenMPDirectiveName(DKind) |
| 2553 | << NestedLoopCount << (CurrentNestedLoopCount > 0) |
| 2554 | << CurrentNestedLoopCount; |
| 2555 | if (NestedLoopCount > 1) |
| 2556 | SemaRef.Diag(NestedLoopCountExpr->getExprLoc(), |
| 2557 | diag::note_omp_collapse_expr) |
| 2558 | << NestedLoopCountExpr->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2559 | return true; |
| 2560 | } |
| 2561 | assert(For->getBody()); |
| 2562 | |
| 2563 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 2564 | |
| 2565 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2566 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2567 | if (ISC.CheckInit(Init)) { |
| 2568 | return true; |
| 2569 | } |
| 2570 | |
| 2571 | bool HasErrors = false; |
| 2572 | |
| 2573 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2574 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2575 | |
| 2576 | // OpenMP [2.6, Canonical Loop Form] |
| 2577 | // Var is one of the following: |
| 2578 | // A variable of signed or unsigned integer type. |
| 2579 | // For C++, a variable of a random access iterator type. |
| 2580 | // For C, a variable of a pointer type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2581 | auto VarType = Var->getType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2582 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 2583 | !VarType->isPointerType() && |
| 2584 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 2585 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 2586 | << SemaRef.getLangOpts().CPlusPlus; |
| 2587 | HasErrors = true; |
| 2588 | } |
| 2589 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2590 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 2591 | // Construct |
| 2592 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2593 | // parallel for construct is (are) private. |
| 2594 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2595 | // with just one associated for-loop is linear with a constant-linear-step |
| 2596 | // that is the increment of the associated for-loop. |
| 2597 | // Exclude loop var from the list of variables with implicitly defined data |
| 2598 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 2599 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2600 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2601 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 2602 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 2603 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2604 | // with just one associated for-loop may be listed in a linear clause with a |
| 2605 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2606 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2607 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2608 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2609 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 2610 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 2611 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2612 | auto PredeterminedCKind = |
| 2613 | isOpenMPSimdDirective(DKind) |
| 2614 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 2615 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2616 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 2617 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2618 | (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && |
| 2619 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 2620 | DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) && |
| 2621 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 2622 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2623 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2624 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 2625 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 2626 | if (DVar.RefExpr == nullptr) |
| 2627 | DVar.CKind = PredeterminedCKind; |
| 2628 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2629 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2630 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2631 | // Make the loop iteration variable private (for worksharing constructs), |
| 2632 | // linear (for simd directives with the only one associated loop) or |
| 2633 | // lastprivate (for simd directives with several collapsed loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 2634 | if (DVar.CKind == OMPC_unknown) |
| 2635 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 2636 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2637 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2638 | } |
| 2639 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2640 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2641 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2642 | // Check test-expr. |
| 2643 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 2644 | |
| 2645 | // Check incr-expr. |
| 2646 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 2647 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2648 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2649 | return HasErrors; |
| 2650 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2651 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2652 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2653 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
| 2654 | DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2655 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
| 2656 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 2657 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 2658 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 2659 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 2660 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 2661 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 2662 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2663 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 2664 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2665 | ResultIterSpace.CounterVar == nullptr || |
| 2666 | ResultIterSpace.CounterInit == nullptr || |
| 2667 | ResultIterSpace.CounterStep == nullptr); |
| 2668 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2669 | return HasErrors; |
| 2670 | } |
| 2671 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2672 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 2673 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 2674 | SourceLocation Loc, ExprResult VarRef, |
| 2675 | ExprResult Start, ExprResult Iter, |
| 2676 | ExprResult Step, bool Subtract) { |
| 2677 | // Add parentheses (for debugging purposes only). |
| 2678 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 2679 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 2680 | !Step.isUsable()) |
| 2681 | return ExprError(); |
| 2682 | |
| 2683 | ExprResult Update = SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), |
| 2684 | Step.get()->IgnoreImplicit()); |
| 2685 | if (!Update.isUsable()) |
| 2686 | return ExprError(); |
| 2687 | |
| 2688 | // Build 'VarRef = Start + Iter * Step'. |
| 2689 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
| 2690 | Start.get()->IgnoreImplicit(), Update.get()); |
| 2691 | if (!Update.isUsable()) |
| 2692 | return ExprError(); |
| 2693 | |
| 2694 | Update = SemaRef.PerformImplicitConversion( |
| 2695 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 2696 | if (!Update.isUsable()) |
| 2697 | return ExprError(); |
| 2698 | |
| 2699 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 2700 | return Update; |
| 2701 | } |
| 2702 | |
| 2703 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 2704 | /// bits. |
| 2705 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 2706 | Sema &SemaRef) { |
| 2707 | if (E == nullptr) |
| 2708 | return ExprError(); |
| 2709 | auto &C = SemaRef.Context; |
| 2710 | QualType OldType = E->getType(); |
| 2711 | unsigned HasBits = C.getTypeSize(OldType); |
| 2712 | if (HasBits >= Bits) |
| 2713 | return ExprResult(E); |
| 2714 | // OK to convert to signed, because new type has more bits than old. |
| 2715 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 2716 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 2717 | true); |
| 2718 | } |
| 2719 | |
| 2720 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 2721 | /// into \a Bits bits. |
| 2722 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 2723 | if (E == nullptr) |
| 2724 | return false; |
| 2725 | llvm::APSInt Result; |
| 2726 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 2727 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 2728 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | /// \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] | 2732 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 2733 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2734 | static unsigned |
| 2735 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *NestedLoopCountExpr, |
| 2736 | Stmt *AStmt, Sema &SemaRef, DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2737 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2738 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2739 | unsigned NestedLoopCount = 1; |
| 2740 | if (NestedLoopCountExpr) { |
| 2741 | // Found 'collapse' clause - calculate collapse number. |
| 2742 | llvm::APSInt Result; |
| 2743 | if (NestedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 2744 | NestedLoopCount = Result.getLimitedValue(); |
| 2745 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2746 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 2747 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2748 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 2749 | IterSpaces.resize(NestedLoopCount); |
| 2750 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2751 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2752 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2753 | NestedLoopCount, NestedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2754 | VarsWithImplicitDSA, IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 2755 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2756 | // 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] | 2757 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2758 | // All loops associated with the construct must be perfectly nested; that |
| 2759 | // is, there must be no intervening code nor any OpenMP directive between |
| 2760 | // any two loops. |
| 2761 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2762 | } |
| 2763 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2764 | Built.clear(/* size */ NestedLoopCount); |
| 2765 | |
| 2766 | if (SemaRef.CurContext->isDependentContext()) |
| 2767 | return NestedLoopCount; |
| 2768 | |
| 2769 | // An example of what is generated for the following code: |
| 2770 | // |
| 2771 | // #pragma omp simd collapse(2) |
| 2772 | // for (i = 0; i < NI; ++i) |
| 2773 | // for (j = J0; j < NJ; j+=2) { |
| 2774 | // <loop body> |
| 2775 | // } |
| 2776 | // |
| 2777 | // We generate the code below. |
| 2778 | // Note: the loop body may be outlined in CodeGen. |
| 2779 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 2780 | // iterations and operator+= to calculate counter value. |
| 2781 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 2782 | // or i64 is currently supported). |
| 2783 | // |
| 2784 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 2785 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 2786 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 2787 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 2788 | // // similar updates for vars in clauses (e.g. 'linear') |
| 2789 | // <loop body (using local i and j)> |
| 2790 | // } |
| 2791 | // i = NI; // assign final values of counters |
| 2792 | // j = NJ; |
| 2793 | // |
| 2794 | |
| 2795 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 2796 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2797 | // Precondition tests if there is at least one iteration (all conditions are |
| 2798 | // true). |
| 2799 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2800 | auto N0 = IterSpaces[0].NumIterations; |
| 2801 | ExprResult LastIteration32 = WidenIterationCount(32 /* Bits */, N0, SemaRef); |
| 2802 | ExprResult LastIteration64 = WidenIterationCount(64 /* Bits */, N0, SemaRef); |
| 2803 | |
| 2804 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 2805 | return NestedLoopCount; |
| 2806 | |
| 2807 | auto &C = SemaRef.Context; |
| 2808 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 2809 | |
| 2810 | Scope *CurScope = DSA.getCurScope(); |
| 2811 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2812 | if (PreCond.isUsable()) { |
| 2813 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 2814 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 2815 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2816 | auto N = IterSpaces[Cnt].NumIterations; |
| 2817 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 2818 | if (LastIteration32.isUsable()) |
| 2819 | LastIteration32 = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_Mul, |
| 2820 | LastIteration32.get(), N); |
| 2821 | if (LastIteration64.isUsable()) |
| 2822 | LastIteration64 = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_Mul, |
| 2823 | LastIteration64.get(), N); |
| 2824 | } |
| 2825 | |
| 2826 | // Choose either the 32-bit or 64-bit version. |
| 2827 | ExprResult LastIteration = LastIteration64; |
| 2828 | if (LastIteration32.isUsable() && |
| 2829 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 2830 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 2831 | FitsInto( |
| 2832 | 32 /* Bits */, |
| 2833 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 2834 | LastIteration64.get(), SemaRef))) |
| 2835 | LastIteration = LastIteration32; |
| 2836 | |
| 2837 | if (!LastIteration.isUsable()) |
| 2838 | return 0; |
| 2839 | |
| 2840 | // Save the number of iterations. |
| 2841 | ExprResult NumIterations = LastIteration; |
| 2842 | { |
| 2843 | LastIteration = SemaRef.BuildBinOp( |
| 2844 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 2845 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2846 | if (!LastIteration.isUsable()) |
| 2847 | return 0; |
| 2848 | } |
| 2849 | |
| 2850 | // Calculate the last iteration number beforehand instead of doing this on |
| 2851 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 2852 | llvm::APSInt Result; |
| 2853 | bool IsConstant = |
| 2854 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2855 | ExprResult CalcLastIteration; |
| 2856 | if (!IsConstant) { |
| 2857 | SourceLocation SaveLoc; |
| 2858 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2859 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2860 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2861 | ExprResult SaveRef = buildDeclRefExpr( |
| 2862 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2863 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 2864 | SaveRef.get(), LastIteration.get()); |
| 2865 | LastIteration = SaveRef; |
| 2866 | |
| 2867 | // Prepare SaveRef + 1. |
| 2868 | NumIterations = SemaRef.BuildBinOp( |
| 2869 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 2870 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2871 | if (!NumIterations.isUsable()) |
| 2872 | return 0; |
| 2873 | } |
| 2874 | |
| 2875 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 2876 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2877 | QualType VType = LastIteration.get()->getType(); |
| 2878 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 2879 | ExprResult LB, UB, IL, ST, EUB; |
| 2880 | if (isOpenMPWorksharingDirective(DKind)) { |
| 2881 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2882 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 2883 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2884 | SemaRef.AddInitializerToDecl( |
| 2885 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 2886 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 2887 | |
| 2888 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2889 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 2890 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2891 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 2892 | /*DirectInit*/ false, |
| 2893 | /*TypeMayContainAuto*/ false); |
| 2894 | |
| 2895 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 2896 | // This will be used to implement clause 'lastprivate'. |
| 2897 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2898 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 2899 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2900 | SemaRef.AddInitializerToDecl( |
| 2901 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 2902 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 2903 | |
| 2904 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2905 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 2906 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2907 | SemaRef.AddInitializerToDecl( |
| 2908 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 2909 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 2910 | |
| 2911 | // Build expression: UB = min(UB, LastIteration) |
| 2912 | // It is nesessary for CodeGen of directives with static scheduling. |
| 2913 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 2914 | UB.get(), LastIteration.get()); |
| 2915 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 2916 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 2917 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 2918 | CondOp.get()); |
| 2919 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 2920 | } |
| 2921 | |
| 2922 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2923 | ExprResult IV; |
| 2924 | ExprResult Init; |
| 2925 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2926 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 2927 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2928 | Expr *RHS = isOpenMPWorksharingDirective(DKind) |
| 2929 | ? LB.get() |
| 2930 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 2931 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 2932 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2935 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2936 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2937 | ExprResult Cond = |
| 2938 | isOpenMPWorksharingDirective(DKind) |
| 2939 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 2940 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 2941 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2942 | |
| 2943 | // Loop increment (IV = IV + 1) |
| 2944 | SourceLocation IncLoc; |
| 2945 | ExprResult Inc = |
| 2946 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 2947 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 2948 | if (!Inc.isUsable()) |
| 2949 | return 0; |
| 2950 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2951 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 2952 | if (!Inc.isUsable()) |
| 2953 | return 0; |
| 2954 | |
| 2955 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 2956 | // Used for directives with static scheduling. |
| 2957 | ExprResult NextLB, NextUB; |
| 2958 | if (isOpenMPWorksharingDirective(DKind)) { |
| 2959 | // LB + ST |
| 2960 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 2961 | if (!NextLB.isUsable()) |
| 2962 | return 0; |
| 2963 | // LB = LB + ST |
| 2964 | NextLB = |
| 2965 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 2966 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 2967 | if (!NextLB.isUsable()) |
| 2968 | return 0; |
| 2969 | // UB + ST |
| 2970 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 2971 | if (!NextUB.isUsable()) |
| 2972 | return 0; |
| 2973 | // UB = UB + ST |
| 2974 | NextUB = |
| 2975 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 2976 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 2977 | if (!NextUB.isUsable()) |
| 2978 | return 0; |
| 2979 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2980 | |
| 2981 | // Build updates and final values of the loop counters. |
| 2982 | bool HasErrors = false; |
| 2983 | Built.Counters.resize(NestedLoopCount); |
| 2984 | Built.Updates.resize(NestedLoopCount); |
| 2985 | Built.Finals.resize(NestedLoopCount); |
| 2986 | { |
| 2987 | ExprResult Div; |
| 2988 | // Go from inner nested loop to outer. |
| 2989 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 2990 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 2991 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 2992 | // Build: Iter = (IV / Div) % IS.NumIters |
| 2993 | // where Div is product of previous iterations' IS.NumIters. |
| 2994 | ExprResult Iter; |
| 2995 | if (Div.isUsable()) { |
| 2996 | Iter = |
| 2997 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 2998 | } else { |
| 2999 | Iter = IV; |
| 3000 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3001 | "unusable div expected on first iteration only"); |
| 3002 | } |
| 3003 | |
| 3004 | if (Cnt != 0 && Iter.isUsable()) |
| 3005 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3006 | IS.NumIterations); |
| 3007 | if (!Iter.isUsable()) { |
| 3008 | HasErrors = true; |
| 3009 | break; |
| 3010 | } |
| 3011 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3012 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3013 | auto *CounterVar = buildDeclRefExpr( |
| 3014 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3015 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3016 | /*RefersToCapture=*/true); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3017 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3018 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3019 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3020 | if (!Update.isUsable()) { |
| 3021 | HasErrors = true; |
| 3022 | break; |
| 3023 | } |
| 3024 | |
| 3025 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3026 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3027 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3028 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3029 | if (!Final.isUsable()) { |
| 3030 | HasErrors = true; |
| 3031 | break; |
| 3032 | } |
| 3033 | |
| 3034 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3035 | if (Cnt != 0) { |
| 3036 | if (Div.isUnset()) |
| 3037 | Div = IS.NumIterations; |
| 3038 | else |
| 3039 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3040 | IS.NumIterations); |
| 3041 | |
| 3042 | // Add parentheses (for debugging purposes only). |
| 3043 | if (Div.isUsable()) |
| 3044 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3045 | if (!Div.isUsable()) { |
| 3046 | HasErrors = true; |
| 3047 | break; |
| 3048 | } |
| 3049 | } |
| 3050 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3051 | HasErrors = true; |
| 3052 | break; |
| 3053 | } |
| 3054 | // Save results |
| 3055 | Built.Counters[Cnt] = IS.CounterVar; |
| 3056 | Built.Updates[Cnt] = Update.get(); |
| 3057 | Built.Finals[Cnt] = Final.get(); |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | if (HasErrors) |
| 3062 | return 0; |
| 3063 | |
| 3064 | // Save results |
| 3065 | Built.IterationVarRef = IV.get(); |
| 3066 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3067 | Built.NumIterations = NumIterations.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3068 | Built.CalcLastIteration = CalcLastIteration.get(); |
| 3069 | Built.PreCond = PreCond.get(); |
| 3070 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3071 | Built.Init = Init.get(); |
| 3072 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3073 | Built.LB = LB.get(); |
| 3074 | Built.UB = UB.get(); |
| 3075 | Built.IL = IL.get(); |
| 3076 | Built.ST = ST.get(); |
| 3077 | Built.EUB = EUB.get(); |
| 3078 | Built.NLB = NextLB.get(); |
| 3079 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3080 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3081 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3084 | static Expr *GetCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 3085 | auto &&CollapseFilter = [](const OMPClause *C) -> bool { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3086 | return C->getClauseKind() == OMPC_collapse; |
| 3087 | }; |
| 3088 | OMPExecutableDirective::filtered_clause_iterator<decltype(CollapseFilter)> I( |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 3089 | Clauses, std::move(CollapseFilter)); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3090 | if (I) |
| 3091 | return cast<OMPCollapseClause>(*I)->getNumForLoops(); |
| 3092 | return nullptr; |
| 3093 | } |
| 3094 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3095 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3096 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3097 | SourceLocation EndLoc, |
| 3098 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3099 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3100 | // In presence of clause 'collapse', it will define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3101 | unsigned NestedLoopCount = |
| 3102 | CheckOpenMPLoop(OMPD_simd, GetCollapseNumberExpr(Clauses), AStmt, *this, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3103 | *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3104 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3105 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3106 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3107 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3108 | "omp simd loop exprs were not built"); |
| 3109 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3110 | if (!CurContext->isDependentContext()) { |
| 3111 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3112 | for (auto C : Clauses) { |
| 3113 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3114 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3115 | B.NumIterations, *this, CurScope)) |
| 3116 | return StmtError(); |
| 3117 | } |
| 3118 | } |
| 3119 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3120 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3121 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3122 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3123 | } |
| 3124 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3125 | StmtResult Sema::ActOnOpenMPForDirective( |
| 3126 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3127 | SourceLocation EndLoc, |
| 3128 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3129 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3130 | // In presence of clause 'collapse', it will define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3131 | unsigned NestedLoopCount = |
| 3132 | CheckOpenMPLoop(OMPD_for, GetCollapseNumberExpr(Clauses), AStmt, *this, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3133 | *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3134 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3135 | return StmtError(); |
| 3136 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3137 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3138 | "omp for loop exprs were not built"); |
| 3139 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3140 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3141 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3142 | Clauses, AStmt, B); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3143 | } |
| 3144 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3145 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 3146 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3147 | SourceLocation EndLoc, |
| 3148 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3149 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3150 | // In presence of clause 'collapse', it will define the nested loops number. |
| 3151 | unsigned NestedLoopCount = |
| 3152 | CheckOpenMPLoop(OMPD_for_simd, GetCollapseNumberExpr(Clauses), AStmt, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3153 | *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3154 | if (NestedLoopCount == 0) |
| 3155 | return StmtError(); |
| 3156 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3157 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3158 | "omp for simd loop exprs were not built"); |
| 3159 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3160 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3161 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3162 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3165 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3166 | Stmt *AStmt, |
| 3167 | SourceLocation StartLoc, |
| 3168 | SourceLocation EndLoc) { |
| 3169 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3170 | auto BaseStmt = AStmt; |
| 3171 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3172 | BaseStmt = CS->getCapturedStmt(); |
| 3173 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3174 | auto S = C->children(); |
| 3175 | if (!S) |
| 3176 | return StmtError(); |
| 3177 | // All associated statements must be '#pragma omp section' except for |
| 3178 | // the first one. |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3179 | for (++S; S; ++S) { |
| 3180 | auto SectionStmt = *S; |
| 3181 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3182 | if (SectionStmt) |
| 3183 | Diag(SectionStmt->getLocStart(), |
| 3184 | diag::err_omp_sections_substmt_not_section); |
| 3185 | return StmtError(); |
| 3186 | } |
| 3187 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3188 | } else { |
| 3189 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 3190 | return StmtError(); |
| 3191 | } |
| 3192 | |
| 3193 | getCurFunction()->setHasBranchProtectedScope(); |
| 3194 | |
| 3195 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 3196 | AStmt); |
| 3197 | } |
| 3198 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3199 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 3200 | SourceLocation StartLoc, |
| 3201 | SourceLocation EndLoc) { |
| 3202 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3203 | |
| 3204 | getCurFunction()->setHasBranchProtectedScope(); |
| 3205 | |
| 3206 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3207 | } |
| 3208 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3209 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 3210 | Stmt *AStmt, |
| 3211 | SourceLocation StartLoc, |
| 3212 | SourceLocation EndLoc) { |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3213 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3214 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3215 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3216 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 3217 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 3218 | // The copyprivate clause must not be used with the nowait clause. |
| 3219 | OMPClause *Nowait = nullptr; |
| 3220 | OMPClause *Copyprivate = nullptr; |
| 3221 | for (auto *Clause : Clauses) { |
| 3222 | if (Clause->getClauseKind() == OMPC_nowait) |
| 3223 | Nowait = Clause; |
| 3224 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 3225 | Copyprivate = Clause; |
| 3226 | if (Copyprivate && Nowait) { |
| 3227 | Diag(Copyprivate->getLocStart(), |
| 3228 | diag::err_omp_single_copyprivate_with_nowait); |
| 3229 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 3230 | return StmtError(); |
| 3231 | } |
| 3232 | } |
| 3233 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3234 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3235 | } |
| 3236 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3237 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 3238 | SourceLocation StartLoc, |
| 3239 | SourceLocation EndLoc) { |
| 3240 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3241 | |
| 3242 | getCurFunction()->setHasBranchProtectedScope(); |
| 3243 | |
| 3244 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3245 | } |
| 3246 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3247 | StmtResult |
| 3248 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 3249 | Stmt *AStmt, SourceLocation StartLoc, |
| 3250 | SourceLocation EndLoc) { |
| 3251 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3252 | |
| 3253 | getCurFunction()->setHasBranchProtectedScope(); |
| 3254 | |
| 3255 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 3256 | AStmt); |
| 3257 | } |
| 3258 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3259 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 3260 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3261 | SourceLocation EndLoc, |
| 3262 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3263 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3264 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3265 | // 1.2.2 OpenMP Language Terminology |
| 3266 | // Structured block - An executable statement with a single entry at the |
| 3267 | // top and a single exit at the bottom. |
| 3268 | // The point of exit cannot be a branch out of the structured block. |
| 3269 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3270 | CS->getCapturedDecl()->setNothrow(); |
| 3271 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3272 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3273 | // In presence of clause 'collapse', it will define the nested loops number. |
| 3274 | unsigned NestedLoopCount = |
| 3275 | CheckOpenMPLoop(OMPD_parallel_for, GetCollapseNumberExpr(Clauses), AStmt, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3276 | *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3277 | if (NestedLoopCount == 0) |
| 3278 | return StmtError(); |
| 3279 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3280 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3281 | "omp parallel for loop exprs were not built"); |
| 3282 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3283 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3284 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 3285 | NestedLoopCount, Clauses, AStmt, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3286 | } |
| 3287 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3288 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 3289 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3290 | SourceLocation EndLoc, |
| 3291 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3292 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3293 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3294 | // 1.2.2 OpenMP Language Terminology |
| 3295 | // Structured block - An executable statement with a single entry at the |
| 3296 | // top and a single exit at the bottom. |
| 3297 | // The point of exit cannot be a branch out of the structured block. |
| 3298 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3299 | CS->getCapturedDecl()->setNothrow(); |
| 3300 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3301 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3302 | // In presence of clause 'collapse', it will define the nested loops number. |
| 3303 | unsigned NestedLoopCount = |
| 3304 | CheckOpenMPLoop(OMPD_parallel_for_simd, GetCollapseNumberExpr(Clauses), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3305 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3306 | if (NestedLoopCount == 0) |
| 3307 | return StmtError(); |
| 3308 | |
| 3309 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3310 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3311 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3312 | } |
| 3313 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3314 | StmtResult |
| 3315 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3316 | Stmt *AStmt, SourceLocation StartLoc, |
| 3317 | SourceLocation EndLoc) { |
| 3318 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3319 | auto BaseStmt = AStmt; |
| 3320 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3321 | BaseStmt = CS->getCapturedStmt(); |
| 3322 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3323 | auto S = C->children(); |
| 3324 | if (!S) |
| 3325 | return StmtError(); |
| 3326 | // All associated statements must be '#pragma omp section' except for |
| 3327 | // the first one. |
| 3328 | for (++S; S; ++S) { |
| 3329 | auto SectionStmt = *S; |
| 3330 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3331 | if (SectionStmt) |
| 3332 | Diag(SectionStmt->getLocStart(), |
| 3333 | diag::err_omp_parallel_sections_substmt_not_section); |
| 3334 | return StmtError(); |
| 3335 | } |
| 3336 | } |
| 3337 | } else { |
| 3338 | Diag(AStmt->getLocStart(), |
| 3339 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 3340 | return StmtError(); |
| 3341 | } |
| 3342 | |
| 3343 | getCurFunction()->setHasBranchProtectedScope(); |
| 3344 | |
| 3345 | return OMPParallelSectionsDirective::Create(Context, StartLoc, EndLoc, |
| 3346 | Clauses, AStmt); |
| 3347 | } |
| 3348 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3349 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 3350 | Stmt *AStmt, SourceLocation StartLoc, |
| 3351 | SourceLocation EndLoc) { |
| 3352 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3353 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3354 | // 1.2.2 OpenMP Language Terminology |
| 3355 | // Structured block - An executable statement with a single entry at the |
| 3356 | // top and a single exit at the bottom. |
| 3357 | // The point of exit cannot be a branch out of the structured block. |
| 3358 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3359 | CS->getCapturedDecl()->setNothrow(); |
| 3360 | |
| 3361 | getCurFunction()->setHasBranchProtectedScope(); |
| 3362 | |
| 3363 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3364 | } |
| 3365 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3366 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 3367 | SourceLocation EndLoc) { |
| 3368 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 3369 | } |
| 3370 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3371 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 3372 | SourceLocation EndLoc) { |
| 3373 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 3374 | } |
| 3375 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3376 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 3377 | SourceLocation EndLoc) { |
| 3378 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 3379 | } |
| 3380 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3381 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 3382 | SourceLocation StartLoc, |
| 3383 | SourceLocation EndLoc) { |
| 3384 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 3385 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 3386 | } |
| 3387 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3388 | StmtResult Sema::ActOnOpenMPOrderedDirective(Stmt *AStmt, |
| 3389 | SourceLocation StartLoc, |
| 3390 | SourceLocation EndLoc) { |
| 3391 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3392 | |
| 3393 | getCurFunction()->setHasBranchProtectedScope(); |
| 3394 | |
| 3395 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3396 | } |
| 3397 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3398 | namespace { |
| 3399 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 3400 | /// construct. |
| 3401 | class OpenMPAtomicUpdateChecker { |
| 3402 | /// \brief Error results for atomic update expressions. |
| 3403 | enum ExprAnalysisErrorCode { |
| 3404 | /// \brief A statement is not an expression statement. |
| 3405 | NotAnExpression, |
| 3406 | /// \brief Expression is not builtin binary or unary operation. |
| 3407 | NotABinaryOrUnaryExpression, |
| 3408 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 3409 | NotAnUnaryIncDecExpression, |
| 3410 | /// \brief An expression is not of scalar type. |
| 3411 | NotAScalarType, |
| 3412 | /// \brief A binary operation is not an assignment operation. |
| 3413 | NotAnAssignmentOp, |
| 3414 | /// \brief RHS part of the binary operation is not a binary expression. |
| 3415 | NotABinaryExpression, |
| 3416 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 3417 | /// expression. |
| 3418 | NotABinaryOperator, |
| 3419 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 3420 | /// part. |
| 3421 | NotAnUpdateExpression, |
| 3422 | /// \brief No errors is found. |
| 3423 | NoError |
| 3424 | }; |
| 3425 | /// \brief Reference to Sema. |
| 3426 | Sema &SemaRef; |
| 3427 | /// \brief A location for note diagnostics (when error is found). |
| 3428 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3429 | /// \brief 'x' lvalue part of the source atomic expression. |
| 3430 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3431 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 3432 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3433 | /// \brief Helper expression of the form |
| 3434 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 3435 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 3436 | Expr *UpdateExpr; |
| 3437 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 3438 | /// important for non-associative operations. |
| 3439 | bool IsXLHSInRHSPart; |
| 3440 | BinaryOperatorKind Op; |
| 3441 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3442 | /// \brief true if the source expression is a postfix unary operation, false |
| 3443 | /// if it is a prefix unary operation. |
| 3444 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3445 | |
| 3446 | public: |
| 3447 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3448 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3449 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3450 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 3451 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3452 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 3453 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3454 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 3455 | /// \param NoteId Diagnostic note for the main error message. |
| 3456 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3457 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3458 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 3459 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3460 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 3461 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3462 | /// \brief Return the update expression used in calculation of the updated |
| 3463 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 3464 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 3465 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 3466 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 3467 | /// false otherwise. |
| 3468 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 3469 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3470 | /// \brief true if the source expression is a postfix unary operation, false |
| 3471 | /// if it is a prefix unary operation. |
| 3472 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 3473 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3474 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3475 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 3476 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3477 | }; |
| 3478 | } // namespace |
| 3479 | |
| 3480 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 3481 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 3482 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 3483 | SourceLocation ErrorLoc, NoteLoc; |
| 3484 | SourceRange ErrorRange, NoteRange; |
| 3485 | // Allowed constructs are: |
| 3486 | // x = x binop expr; |
| 3487 | // x = expr binop x; |
| 3488 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 3489 | X = AtomicBinOp->getLHS(); |
| 3490 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 3491 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 3492 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 3493 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 3494 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3495 | Op = AtomicInnerBinOp->getOpcode(); |
| 3496 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3497 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 3498 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 3499 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 3500 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 3501 | /*Canonical=*/true); |
| 3502 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 3503 | /*Canonical=*/true); |
| 3504 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 3505 | /*Canonical=*/true); |
| 3506 | if (XId == LHSId) { |
| 3507 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3508 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3509 | } else if (XId == RHSId) { |
| 3510 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3511 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3512 | } else { |
| 3513 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 3514 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 3515 | NoteLoc = X->getExprLoc(); |
| 3516 | NoteRange = X->getSourceRange(); |
| 3517 | ErrorFound = NotAnUpdateExpression; |
| 3518 | } |
| 3519 | } else { |
| 3520 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 3521 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 3522 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 3523 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3524 | ErrorFound = NotABinaryOperator; |
| 3525 | } |
| 3526 | } else { |
| 3527 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 3528 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 3529 | ErrorFound = NotABinaryExpression; |
| 3530 | } |
| 3531 | } else { |
| 3532 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3533 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3534 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 3535 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3536 | ErrorFound = NotAnAssignmentOp; |
| 3537 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3538 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3539 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 3540 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 3541 | return true; |
| 3542 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3543 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3544 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3545 | } |
| 3546 | |
| 3547 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 3548 | unsigned NoteId) { |
| 3549 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 3550 | SourceLocation ErrorLoc, NoteLoc; |
| 3551 | SourceRange ErrorRange, NoteRange; |
| 3552 | // Allowed constructs are: |
| 3553 | // x++; |
| 3554 | // x--; |
| 3555 | // ++x; |
| 3556 | // --x; |
| 3557 | // x binop= expr; |
| 3558 | // x = x binop expr; |
| 3559 | // x = expr binop x; |
| 3560 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 3561 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 3562 | if (AtomicBody->getType()->isScalarType() || |
| 3563 | AtomicBody->isInstantiationDependent()) { |
| 3564 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 3565 | AtomicBody->IgnoreParenImpCasts())) { |
| 3566 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3567 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3568 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3569 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3570 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3571 | X = AtomicCompAssignOp->getLHS(); |
| 3572 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3573 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 3574 | AtomicBody->IgnoreParenImpCasts())) { |
| 3575 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3576 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 3577 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3578 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3579 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 3580 | // Check for Unary Operation |
| 3581 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3582 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3583 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 3584 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 3585 | X = AtomicUnaryOp->getSubExpr(); |
| 3586 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 3587 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3588 | } else { |
| 3589 | ErrorFound = NotAnUnaryIncDecExpression; |
| 3590 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 3591 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 3592 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 3593 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3594 | } |
| 3595 | } else { |
| 3596 | ErrorFound = NotABinaryOrUnaryExpression; |
| 3597 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 3598 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 3599 | } |
| 3600 | } else { |
| 3601 | ErrorFound = NotAScalarType; |
| 3602 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 3603 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 3604 | } |
| 3605 | } else { |
| 3606 | ErrorFound = NotAnExpression; |
| 3607 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 3608 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 3609 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3610 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3611 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 3612 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 3613 | return true; |
| 3614 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3615 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3616 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3617 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 3618 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 3619 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 3620 | auto *OVEX = new (SemaRef.getASTContext()) |
| 3621 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 3622 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 3623 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 3624 | auto Update = |
| 3625 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 3626 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 3627 | if (Update.isInvalid()) |
| 3628 | return true; |
| 3629 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 3630 | Sema::AA_Casting); |
| 3631 | if (Update.isInvalid()) |
| 3632 | return true; |
| 3633 | UpdateExpr = Update.get(); |
| 3634 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3635 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3638 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 3639 | Stmt *AStmt, |
| 3640 | SourceLocation StartLoc, |
| 3641 | SourceLocation EndLoc) { |
| 3642 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3643 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3644 | // 1.2.2 OpenMP Language Terminology |
| 3645 | // Structured block - An executable statement with a single entry at the |
| 3646 | // top and a single exit at the bottom. |
| 3647 | // The point of exit cannot be a branch out of the structured block. |
| 3648 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3649 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 3650 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3651 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3652 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3653 | C->getClauseKind() == OMPC_update || |
| 3654 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3655 | if (AtomicKind != OMPC_unknown) { |
| 3656 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 3657 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 3658 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 3659 | << getOpenMPClauseName(AtomicKind); |
| 3660 | } else { |
| 3661 | AtomicKind = C->getClauseKind(); |
| 3662 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3663 | } |
| 3664 | } |
| 3665 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3666 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3667 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 3668 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 3669 | Body = EWC->getSubExpr(); |
| 3670 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3671 | Expr *X = nullptr; |
| 3672 | Expr *V = nullptr; |
| 3673 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3674 | Expr *UE = nullptr; |
| 3675 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3676 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3677 | // OpenMP [2.12.6, atomic Construct] |
| 3678 | // In the next expressions: |
| 3679 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 3680 | // * During the execution of an atomic region, multiple syntactic |
| 3681 | // occurrences of x must designate the same storage location. |
| 3682 | // * Neither of v and expr (as applicable) may access the storage location |
| 3683 | // designated by x. |
| 3684 | // * Neither of x and expr (as applicable) may access the storage location |
| 3685 | // designated by v. |
| 3686 | // * expr is an expression with scalar type. |
| 3687 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 3688 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 3689 | // * The expression x binop expr must be numerically equivalent to x binop |
| 3690 | // (expr). This requirement is satisfied if the operators in expr have |
| 3691 | // precedence greater than binop, or by using parentheses around expr or |
| 3692 | // subexpressions of expr. |
| 3693 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 3694 | // binop x. This requirement is satisfied if the operators in expr have |
| 3695 | // precedence equal to or greater than binop, or by using parentheses around |
| 3696 | // expr or subexpressions of expr. |
| 3697 | // * For forms that allow multiple occurrences of x, the number of times |
| 3698 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3699 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3700 | enum { |
| 3701 | NotAnExpression, |
| 3702 | NotAnAssignmentOp, |
| 3703 | NotAScalarType, |
| 3704 | NotAnLValue, |
| 3705 | NoError |
| 3706 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3707 | SourceLocation ErrorLoc, NoteLoc; |
| 3708 | SourceRange ErrorRange, NoteRange; |
| 3709 | // If clause is read: |
| 3710 | // v = x; |
| 3711 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 3712 | auto AtomicBinOp = |
| 3713 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 3714 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 3715 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 3716 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 3717 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 3718 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 3719 | if (!X->isLValue() || !V->isLValue()) { |
| 3720 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 3721 | ErrorFound = NotAnLValue; |
| 3722 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3723 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3724 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 3725 | NoteRange = NotLValueExpr->getSourceRange(); |
| 3726 | } |
| 3727 | } else if (!X->isInstantiationDependent() || |
| 3728 | !V->isInstantiationDependent()) { |
| 3729 | auto NotScalarExpr = |
| 3730 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 3731 | ? V |
| 3732 | : X; |
| 3733 | ErrorFound = NotAScalarType; |
| 3734 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3735 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3736 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 3737 | NoteRange = NotScalarExpr->getSourceRange(); |
| 3738 | } |
| 3739 | } else { |
| 3740 | ErrorFound = NotAnAssignmentOp; |
| 3741 | ErrorLoc = AtomicBody->getExprLoc(); |
| 3742 | ErrorRange = AtomicBody->getSourceRange(); |
| 3743 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 3744 | : AtomicBody->getExprLoc(); |
| 3745 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 3746 | : AtomicBody->getSourceRange(); |
| 3747 | } |
| 3748 | } else { |
| 3749 | ErrorFound = NotAnExpression; |
| 3750 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 3751 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3752 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3753 | if (ErrorFound != NoError) { |
| 3754 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 3755 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3756 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 3757 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3758 | return StmtError(); |
| 3759 | } else if (CurContext->isDependentContext()) |
| 3760 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3761 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3762 | enum { |
| 3763 | NotAnExpression, |
| 3764 | NotAnAssignmentOp, |
| 3765 | NotAScalarType, |
| 3766 | NotAnLValue, |
| 3767 | NoError |
| 3768 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3769 | SourceLocation ErrorLoc, NoteLoc; |
| 3770 | SourceRange ErrorRange, NoteRange; |
| 3771 | // If clause is write: |
| 3772 | // x = expr; |
| 3773 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 3774 | auto AtomicBinOp = |
| 3775 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 3776 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 3777 | X = AtomicBinOp->getLHS(); |
| 3778 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3779 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 3780 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 3781 | if (!X->isLValue()) { |
| 3782 | ErrorFound = NotAnLValue; |
| 3783 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3784 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3785 | NoteLoc = X->getExprLoc(); |
| 3786 | NoteRange = X->getSourceRange(); |
| 3787 | } |
| 3788 | } else if (!X->isInstantiationDependent() || |
| 3789 | !E->isInstantiationDependent()) { |
| 3790 | auto NotScalarExpr = |
| 3791 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 3792 | ? E |
| 3793 | : X; |
| 3794 | ErrorFound = NotAScalarType; |
| 3795 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3796 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3797 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 3798 | NoteRange = NotScalarExpr->getSourceRange(); |
| 3799 | } |
| 3800 | } else { |
| 3801 | ErrorFound = NotAnAssignmentOp; |
| 3802 | ErrorLoc = AtomicBody->getExprLoc(); |
| 3803 | ErrorRange = AtomicBody->getSourceRange(); |
| 3804 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 3805 | : AtomicBody->getExprLoc(); |
| 3806 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 3807 | : AtomicBody->getSourceRange(); |
| 3808 | } |
| 3809 | } else { |
| 3810 | ErrorFound = NotAnExpression; |
| 3811 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 3812 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3813 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3814 | if (ErrorFound != NoError) { |
| 3815 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 3816 | << ErrorRange; |
| 3817 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 3818 | << NoteRange; |
| 3819 | return StmtError(); |
| 3820 | } else if (CurContext->isDependentContext()) |
| 3821 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3822 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3823 | // If clause is update: |
| 3824 | // x++; |
| 3825 | // x--; |
| 3826 | // ++x; |
| 3827 | // --x; |
| 3828 | // x binop= expr; |
| 3829 | // x = x binop expr; |
| 3830 | // x = expr binop x; |
| 3831 | OpenMPAtomicUpdateChecker Checker(*this); |
| 3832 | if (Checker.checkStatement( |
| 3833 | Body, (AtomicKind == OMPC_update) |
| 3834 | ? diag::err_omp_atomic_update_not_expression_statement |
| 3835 | : diag::err_omp_atomic_not_expression_statement, |
| 3836 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3837 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3838 | if (!CurContext->isDependentContext()) { |
| 3839 | E = Checker.getExpr(); |
| 3840 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3841 | UE = Checker.getUpdateExpr(); |
| 3842 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3843 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3844 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3845 | enum { |
| 3846 | NotAnAssignmentOp, |
| 3847 | NotACompoundStatement, |
| 3848 | NotTwoSubstatements, |
| 3849 | NotASpecificExpression, |
| 3850 | NoError |
| 3851 | } ErrorFound = NoError; |
| 3852 | SourceLocation ErrorLoc, NoteLoc; |
| 3853 | SourceRange ErrorRange, NoteRange; |
| 3854 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 3855 | // If clause is a capture: |
| 3856 | // v = x++; |
| 3857 | // v = x--; |
| 3858 | // v = ++x; |
| 3859 | // v = --x; |
| 3860 | // v = x binop= expr; |
| 3861 | // v = x = x binop expr; |
| 3862 | // v = x = expr binop x; |
| 3863 | auto *AtomicBinOp = |
| 3864 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 3865 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 3866 | V = AtomicBinOp->getLHS(); |
| 3867 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 3868 | OpenMPAtomicUpdateChecker Checker(*this); |
| 3869 | if (Checker.checkStatement( |
| 3870 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 3871 | diag::note_omp_atomic_update)) |
| 3872 | return StmtError(); |
| 3873 | E = Checker.getExpr(); |
| 3874 | X = Checker.getX(); |
| 3875 | UE = Checker.getUpdateExpr(); |
| 3876 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 3877 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
| 3878 | } else { |
| 3879 | ErrorLoc = AtomicBody->getExprLoc(); |
| 3880 | ErrorRange = AtomicBody->getSourceRange(); |
| 3881 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 3882 | : AtomicBody->getExprLoc(); |
| 3883 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 3884 | : AtomicBody->getSourceRange(); |
| 3885 | ErrorFound = NotAnAssignmentOp; |
| 3886 | } |
| 3887 | if (ErrorFound != NoError) { |
| 3888 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 3889 | << ErrorRange; |
| 3890 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 3891 | return StmtError(); |
| 3892 | } else if (CurContext->isDependentContext()) { |
| 3893 | UE = V = E = X = nullptr; |
| 3894 | } |
| 3895 | } else { |
| 3896 | // If clause is a capture: |
| 3897 | // { v = x; x = expr; } |
| 3898 | // { v = x; x++; } |
| 3899 | // { v = x; x--; } |
| 3900 | // { v = x; ++x; } |
| 3901 | // { v = x; --x; } |
| 3902 | // { v = x; x binop= expr; } |
| 3903 | // { v = x; x = x binop expr; } |
| 3904 | // { v = x; x = expr binop x; } |
| 3905 | // { x++; v = x; } |
| 3906 | // { x--; v = x; } |
| 3907 | // { ++x; v = x; } |
| 3908 | // { --x; v = x; } |
| 3909 | // { x binop= expr; v = x; } |
| 3910 | // { x = x binop expr; v = x; } |
| 3911 | // { x = expr binop x; v = x; } |
| 3912 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 3913 | // Check that this is { expr1; expr2; } |
| 3914 | if (CS->size() == 2) { |
| 3915 | auto *First = CS->body_front(); |
| 3916 | auto *Second = CS->body_back(); |
| 3917 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 3918 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 3919 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 3920 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 3921 | // Need to find what subexpression is 'v' and what is 'x'. |
| 3922 | OpenMPAtomicUpdateChecker Checker(*this); |
| 3923 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 3924 | BinaryOperator *BinOp = nullptr; |
| 3925 | if (IsUpdateExprFound) { |
| 3926 | BinOp = dyn_cast<BinaryOperator>(First); |
| 3927 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 3928 | } |
| 3929 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 3930 | // { v = x; x++; } |
| 3931 | // { v = x; x--; } |
| 3932 | // { v = x; ++x; } |
| 3933 | // { v = x; --x; } |
| 3934 | // { v = x; x binop= expr; } |
| 3935 | // { v = x; x = x binop expr; } |
| 3936 | // { v = x; x = expr binop x; } |
| 3937 | // Check that the first expression has form v = x. |
| 3938 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 3939 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 3940 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 3941 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 3942 | IsUpdateExprFound = XId == PossibleXId; |
| 3943 | if (IsUpdateExprFound) { |
| 3944 | V = BinOp->getLHS(); |
| 3945 | X = Checker.getX(); |
| 3946 | E = Checker.getExpr(); |
| 3947 | UE = Checker.getUpdateExpr(); |
| 3948 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3949 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3950 | } |
| 3951 | } |
| 3952 | if (!IsUpdateExprFound) { |
| 3953 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 3954 | BinOp = nullptr; |
| 3955 | if (IsUpdateExprFound) { |
| 3956 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 3957 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 3958 | } |
| 3959 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 3960 | // { x++; v = x; } |
| 3961 | // { x--; v = x; } |
| 3962 | // { ++x; v = x; } |
| 3963 | // { --x; v = x; } |
| 3964 | // { x binop= expr; v = x; } |
| 3965 | // { x = x binop expr; v = x; } |
| 3966 | // { x = expr binop x; v = x; } |
| 3967 | // Check that the second expression has form v = x. |
| 3968 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 3969 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 3970 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 3971 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 3972 | IsUpdateExprFound = XId == PossibleXId; |
| 3973 | if (IsUpdateExprFound) { |
| 3974 | V = BinOp->getLHS(); |
| 3975 | X = Checker.getX(); |
| 3976 | E = Checker.getExpr(); |
| 3977 | UE = Checker.getUpdateExpr(); |
| 3978 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3979 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3980 | } |
| 3981 | } |
| 3982 | } |
| 3983 | if (!IsUpdateExprFound) { |
| 3984 | // { v = x; x = expr; } |
| 3985 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 3986 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
| 3987 | ErrorFound = NotAnAssignmentOp; |
| 3988 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 3989 | : First->getLocStart(); |
| 3990 | NoteRange = ErrorRange = FirstBinOp |
| 3991 | ? FirstBinOp->getSourceRange() |
| 3992 | : SourceRange(ErrorLoc, ErrorLoc); |
| 3993 | } else { |
| 3994 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 3995 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 3996 | ErrorFound = NotAnAssignmentOp; |
| 3997 | NoteLoc = ErrorLoc = SecondBinOp ? SecondBinOp->getOperatorLoc() |
| 3998 | : Second->getLocStart(); |
| 3999 | NoteRange = ErrorRange = SecondBinOp |
| 4000 | ? SecondBinOp->getSourceRange() |
| 4001 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4002 | } else { |
| 4003 | auto *PossibleXRHSInFirst = |
| 4004 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4005 | auto *PossibleXLHSInSecond = |
| 4006 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4007 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 4008 | PossibleXRHSInFirst->Profile(X1Id, Context, /*Canonical=*/true); |
| 4009 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 4010 | /*Canonical=*/true); |
| 4011 | IsUpdateExprFound = X1Id == X2Id; |
| 4012 | if (IsUpdateExprFound) { |
| 4013 | V = FirstBinOp->getLHS(); |
| 4014 | X = SecondBinOp->getLHS(); |
| 4015 | E = SecondBinOp->getRHS(); |
| 4016 | UE = nullptr; |
| 4017 | IsXLHSInRHSPart = false; |
| 4018 | IsPostfixUpdate = true; |
| 4019 | } else { |
| 4020 | ErrorFound = NotASpecificExpression; |
| 4021 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 4022 | ErrorRange = FirstBinOp->getSourceRange(); |
| 4023 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 4024 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 4025 | } |
| 4026 | } |
| 4027 | } |
| 4028 | } |
| 4029 | } else { |
| 4030 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4031 | NoteRange = ErrorRange = |
| 4032 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4033 | ErrorFound = NotTwoSubstatements; |
| 4034 | } |
| 4035 | } else { |
| 4036 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4037 | NoteRange = ErrorRange = |
| 4038 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4039 | ErrorFound = NotACompoundStatement; |
| 4040 | } |
| 4041 | if (ErrorFound != NoError) { |
| 4042 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 4043 | << ErrorRange; |
| 4044 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4045 | return StmtError(); |
| 4046 | } else if (CurContext->isDependentContext()) { |
| 4047 | UE = V = E = X = nullptr; |
| 4048 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4049 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4050 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4051 | |
| 4052 | getCurFunction()->setHasBranchProtectedScope(); |
| 4053 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4054 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4055 | X, V, E, UE, IsXLHSInRHSPart, |
| 4056 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4057 | } |
| 4058 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4059 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 4060 | Stmt *AStmt, |
| 4061 | SourceLocation StartLoc, |
| 4062 | SourceLocation EndLoc) { |
| 4063 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4064 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4065 | // OpenMP [2.16, Nesting of Regions] |
| 4066 | // If specified, a teams construct must be contained within a target |
| 4067 | // construct. That target construct must contain no statements or directives |
| 4068 | // outside of the teams construct. |
| 4069 | if (DSAStack->hasInnerTeamsRegion()) { |
| 4070 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 4071 | bool OMPTeamsFound = true; |
| 4072 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 4073 | auto I = CS->body_begin(); |
| 4074 | while (I != CS->body_end()) { |
| 4075 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 4076 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 4077 | OMPTeamsFound = false; |
| 4078 | break; |
| 4079 | } |
| 4080 | ++I; |
| 4081 | } |
| 4082 | assert(I != CS->body_end() && "Not found statement"); |
| 4083 | S = *I; |
| 4084 | } |
| 4085 | if (!OMPTeamsFound) { |
| 4086 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 4087 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 4088 | diag::note_omp_nested_teams_construct_here); |
| 4089 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 4090 | << isa<OMPExecutableDirective>(S); |
| 4091 | return StmtError(); |
| 4092 | } |
| 4093 | } |
| 4094 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4095 | getCurFunction()->setHasBranchProtectedScope(); |
| 4096 | |
| 4097 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4098 | } |
| 4099 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4100 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 4101 | Stmt *AStmt, SourceLocation StartLoc, |
| 4102 | SourceLocation EndLoc) { |
| 4103 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4104 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4105 | // 1.2.2 OpenMP Language Terminology |
| 4106 | // Structured block - An executable statement with a single entry at the |
| 4107 | // top and a single exit at the bottom. |
| 4108 | // The point of exit cannot be a branch out of the structured block. |
| 4109 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4110 | CS->getCapturedDecl()->setNothrow(); |
| 4111 | |
| 4112 | getCurFunction()->setHasBranchProtectedScope(); |
| 4113 | |
| 4114 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4115 | } |
| 4116 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4117 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4118 | SourceLocation StartLoc, |
| 4119 | SourceLocation LParenLoc, |
| 4120 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4121 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4122 | switch (Kind) { |
| 4123 | case OMPC_if: |
| 4124 | Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4125 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4126 | case OMPC_final: |
| 4127 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4128 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4129 | case OMPC_num_threads: |
| 4130 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4131 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4132 | case OMPC_safelen: |
| 4133 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4134 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4135 | case OMPC_collapse: |
| 4136 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4137 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4138 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4139 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4140 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4141 | case OMPC_private: |
| 4142 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4143 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4144 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4145 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4146 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4147 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4148 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4149 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4150 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4151 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4152 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4153 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4154 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4155 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4156 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4157 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4158 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4159 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4160 | case OMPC_seq_cst: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4161 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4162 | llvm_unreachable("Clause is not allowed."); |
| 4163 | } |
| 4164 | return Res; |
| 4165 | } |
| 4166 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4167 | OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4168 | SourceLocation LParenLoc, |
| 4169 | SourceLocation EndLoc) { |
| 4170 | Expr *ValExpr = Condition; |
| 4171 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 4172 | !Condition->isInstantiationDependent() && |
| 4173 | !Condition->containsUnexpandedParameterPack()) { |
| 4174 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4175 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4176 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4177 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4178 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4179 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4180 | } |
| 4181 | |
| 4182 | return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 4183 | } |
| 4184 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4185 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 4186 | SourceLocation StartLoc, |
| 4187 | SourceLocation LParenLoc, |
| 4188 | SourceLocation EndLoc) { |
| 4189 | Expr *ValExpr = Condition; |
| 4190 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 4191 | !Condition->isInstantiationDependent() && |
| 4192 | !Condition->containsUnexpandedParameterPack()) { |
| 4193 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 4194 | Condition->getExprLoc(), Condition); |
| 4195 | if (Val.isInvalid()) |
| 4196 | return nullptr; |
| 4197 | |
| 4198 | ValExpr = Val.get(); |
| 4199 | } |
| 4200 | |
| 4201 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 4202 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4203 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 4204 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4205 | if (!Op) |
| 4206 | return ExprError(); |
| 4207 | |
| 4208 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 4209 | public: |
| 4210 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4211 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 4212 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 4213 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4214 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 4215 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4216 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 4217 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4218 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 4219 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4220 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 4221 | QualType T, |
| 4222 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4223 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 4224 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4225 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 4226 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4227 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4228 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4229 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4230 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 4231 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4232 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 4233 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4234 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 4235 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4236 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4237 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4238 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4239 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 4240 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4241 | llvm_unreachable("conversion functions are permitted"); |
| 4242 | } |
| 4243 | } ConvertDiagnoser; |
| 4244 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 4245 | } |
| 4246 | |
| 4247 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 4248 | SourceLocation StartLoc, |
| 4249 | SourceLocation LParenLoc, |
| 4250 | SourceLocation EndLoc) { |
| 4251 | Expr *ValExpr = NumThreads; |
| 4252 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4253 | !NumThreads->containsUnexpandedParameterPack()) { |
| 4254 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 4255 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4256 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4257 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4258 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4259 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4260 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4261 | |
| 4262 | // OpenMP [2.5, Restrictions] |
| 4263 | // The num_threads expression must evaluate to a positive integer value. |
| 4264 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4265 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 4266 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4267 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 4268 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4269 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4270 | } |
| 4271 | } |
| 4272 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4273 | return new (Context) |
| 4274 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4277 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 4278 | OpenMPClauseKind CKind) { |
| 4279 | if (!E) |
| 4280 | return ExprError(); |
| 4281 | if (E->isValueDependent() || E->isTypeDependent() || |
| 4282 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 4283 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4284 | llvm::APSInt Result; |
| 4285 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 4286 | if (ICE.isInvalid()) |
| 4287 | return ExprError(); |
| 4288 | if (!Result.isStrictlyPositive()) { |
| 4289 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 4290 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 4291 | return ExprError(); |
| 4292 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 4293 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 4294 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 4295 | << E->getSourceRange(); |
| 4296 | return ExprError(); |
| 4297 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4298 | if (CKind == OMPC_collapse) { |
| 4299 | DSAStack->setCollapseNumber(Result.getExtValue()); |
| 4300 | } |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4301 | return ICE; |
| 4302 | } |
| 4303 | |
| 4304 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 4305 | SourceLocation LParenLoc, |
| 4306 | SourceLocation EndLoc) { |
| 4307 | // OpenMP [2.8.1, simd construct, Description] |
| 4308 | // The parameter of the safelen clause must be a constant |
| 4309 | // positive integer expression. |
| 4310 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 4311 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4312 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4313 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4314 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4315 | } |
| 4316 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4317 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 4318 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4319 | SourceLocation LParenLoc, |
| 4320 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4321 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4322 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4323 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4324 | // The parameter of the collapse clause must be a constant |
| 4325 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4326 | ExprResult NumForLoopsResult = |
| 4327 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 4328 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4329 | return nullptr; |
| 4330 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4331 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4332 | } |
| 4333 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4334 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 4335 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 4336 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4337 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4338 | switch (Kind) { |
| 4339 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4340 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4341 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 4342 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4343 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4344 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4345 | Res = ActOnOpenMPProcBindClause( |
| 4346 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 4347 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4348 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4349 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4350 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4351 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4352 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4353 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4354 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4355 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4356 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4357 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4358 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4359 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4360 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4361 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4362 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4363 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4364 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4365 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4366 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4367 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4368 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4369 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4370 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4371 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4372 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4373 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4374 | case OMPC_seq_cst: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4375 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4376 | llvm_unreachable("Clause is not allowed."); |
| 4377 | } |
| 4378 | return Res; |
| 4379 | } |
| 4380 | |
| 4381 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 4382 | SourceLocation KindKwLoc, |
| 4383 | SourceLocation StartLoc, |
| 4384 | SourceLocation LParenLoc, |
| 4385 | SourceLocation EndLoc) { |
| 4386 | if (Kind == OMPC_DEFAULT_unknown) { |
| 4387 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4388 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 4389 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 4390 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4391 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4392 | Values += "'"; |
| 4393 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 4394 | Values += "'"; |
| 4395 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4396 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4397 | Values += " or "; |
| 4398 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4399 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4400 | break; |
| 4401 | default: |
| 4402 | Values += Sep; |
| 4403 | break; |
| 4404 | } |
| 4405 | } |
| 4406 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4407 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4408 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4409 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4410 | switch (Kind) { |
| 4411 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4412 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4413 | break; |
| 4414 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4415 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4416 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4417 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4418 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4419 | break; |
| 4420 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4421 | return new (Context) |
| 4422 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4423 | } |
| 4424 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4425 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 4426 | SourceLocation KindKwLoc, |
| 4427 | SourceLocation StartLoc, |
| 4428 | SourceLocation LParenLoc, |
| 4429 | SourceLocation EndLoc) { |
| 4430 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 4431 | std::string Values; |
| 4432 | std::string Sep(", "); |
| 4433 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 4434 | Values += "'"; |
| 4435 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 4436 | Values += "'"; |
| 4437 | switch (i) { |
| 4438 | case OMPC_PROC_BIND_unknown - 2: |
| 4439 | Values += " or "; |
| 4440 | break; |
| 4441 | case OMPC_PROC_BIND_unknown - 1: |
| 4442 | break; |
| 4443 | default: |
| 4444 | Values += Sep; |
| 4445 | break; |
| 4446 | } |
| 4447 | } |
| 4448 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4449 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4450 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4451 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4452 | return new (Context) |
| 4453 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4454 | } |
| 4455 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4456 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 4457 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 4458 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 4459 | SourceLocation ArgumentLoc, SourceLocation CommaLoc, |
| 4460 | SourceLocation EndLoc) { |
| 4461 | OMPClause *Res = nullptr; |
| 4462 | switch (Kind) { |
| 4463 | case OMPC_schedule: |
| 4464 | Res = ActOnOpenMPScheduleClause( |
| 4465 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
| 4466 | LParenLoc, ArgumentLoc, CommaLoc, EndLoc); |
| 4467 | break; |
| 4468 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4469 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4470 | case OMPC_num_threads: |
| 4471 | case OMPC_safelen: |
| 4472 | case OMPC_collapse: |
| 4473 | case OMPC_default: |
| 4474 | case OMPC_proc_bind: |
| 4475 | case OMPC_private: |
| 4476 | case OMPC_firstprivate: |
| 4477 | case OMPC_lastprivate: |
| 4478 | case OMPC_shared: |
| 4479 | case OMPC_reduction: |
| 4480 | case OMPC_linear: |
| 4481 | case OMPC_aligned: |
| 4482 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4483 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4484 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4485 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4486 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4487 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4488 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4489 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4490 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4491 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4492 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4493 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4494 | case OMPC_seq_cst: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4495 | case OMPC_unknown: |
| 4496 | llvm_unreachable("Clause is not allowed."); |
| 4497 | } |
| 4498 | return Res; |
| 4499 | } |
| 4500 | |
| 4501 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 4502 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 4503 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 4504 | SourceLocation EndLoc) { |
| 4505 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 4506 | std::string Values; |
| 4507 | std::string Sep(", "); |
| 4508 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 4509 | Values += "'"; |
| 4510 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 4511 | Values += "'"; |
| 4512 | switch (i) { |
| 4513 | case OMPC_SCHEDULE_unknown - 2: |
| 4514 | Values += " or "; |
| 4515 | break; |
| 4516 | case OMPC_SCHEDULE_unknown - 1: |
| 4517 | break; |
| 4518 | default: |
| 4519 | Values += Sep; |
| 4520 | break; |
| 4521 | } |
| 4522 | } |
| 4523 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 4524 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 4525 | return nullptr; |
| 4526 | } |
| 4527 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4528 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4529 | if (ChunkSize) { |
| 4530 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 4531 | !ChunkSize->isInstantiationDependent() && |
| 4532 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 4533 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 4534 | ExprResult Val = |
| 4535 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 4536 | if (Val.isInvalid()) |
| 4537 | return nullptr; |
| 4538 | |
| 4539 | ValExpr = Val.get(); |
| 4540 | |
| 4541 | // OpenMP [2.7.1, Restrictions] |
| 4542 | // chunk_size must be a loop invariant integer expression with a positive |
| 4543 | // value. |
| 4544 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4545 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 4546 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 4547 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 4548 | << "schedule" << ChunkSize->getSourceRange(); |
| 4549 | return nullptr; |
| 4550 | } |
| 4551 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 4552 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 4553 | ChunkSize->getType(), ".chunk."); |
| 4554 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 4555 | ChunkSize->getExprLoc(), |
| 4556 | /*RefersToCapture=*/true); |
| 4557 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4558 | } |
| 4559 | } |
| 4560 | } |
| 4561 | |
| 4562 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4563 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4564 | } |
| 4565 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4566 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 4567 | SourceLocation StartLoc, |
| 4568 | SourceLocation EndLoc) { |
| 4569 | OMPClause *Res = nullptr; |
| 4570 | switch (Kind) { |
| 4571 | case OMPC_ordered: |
| 4572 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 4573 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4574 | case OMPC_nowait: |
| 4575 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 4576 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4577 | case OMPC_untied: |
| 4578 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 4579 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4580 | case OMPC_mergeable: |
| 4581 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 4582 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4583 | case OMPC_read: |
| 4584 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 4585 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4586 | case OMPC_write: |
| 4587 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 4588 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4589 | case OMPC_update: |
| 4590 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 4591 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4592 | case OMPC_capture: |
| 4593 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 4594 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4595 | case OMPC_seq_cst: |
| 4596 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 4597 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4598 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4599 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4600 | case OMPC_num_threads: |
| 4601 | case OMPC_safelen: |
| 4602 | case OMPC_collapse: |
| 4603 | case OMPC_schedule: |
| 4604 | case OMPC_private: |
| 4605 | case OMPC_firstprivate: |
| 4606 | case OMPC_lastprivate: |
| 4607 | case OMPC_shared: |
| 4608 | case OMPC_reduction: |
| 4609 | case OMPC_linear: |
| 4610 | case OMPC_aligned: |
| 4611 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4612 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4613 | case OMPC_default: |
| 4614 | case OMPC_proc_bind: |
| 4615 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4616 | case OMPC_flush: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4617 | case OMPC_unknown: |
| 4618 | llvm_unreachable("Clause is not allowed."); |
| 4619 | } |
| 4620 | return Res; |
| 4621 | } |
| 4622 | |
| 4623 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 4624 | SourceLocation EndLoc) { |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4625 | DSAStack->setOrderedRegion(); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4626 | return new (Context) OMPOrderedClause(StartLoc, EndLoc); |
| 4627 | } |
| 4628 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4629 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 4630 | SourceLocation EndLoc) { |
| 4631 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 4632 | } |
| 4633 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4634 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 4635 | SourceLocation EndLoc) { |
| 4636 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 4637 | } |
| 4638 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4639 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 4640 | SourceLocation EndLoc) { |
| 4641 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 4642 | } |
| 4643 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4644 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 4645 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4646 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 4647 | } |
| 4648 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4649 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 4650 | SourceLocation EndLoc) { |
| 4651 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 4652 | } |
| 4653 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4654 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 4655 | SourceLocation EndLoc) { |
| 4656 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 4657 | } |
| 4658 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4659 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 4660 | SourceLocation EndLoc) { |
| 4661 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 4662 | } |
| 4663 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4664 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 4665 | SourceLocation EndLoc) { |
| 4666 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 4667 | } |
| 4668 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4669 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 4670 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 4671 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 4672 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
| 4673 | const DeclarationNameInfo &ReductionId) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4674 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4675 | switch (Kind) { |
| 4676 | case OMPC_private: |
| 4677 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4678 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4679 | case OMPC_firstprivate: |
| 4680 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4681 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4682 | case OMPC_lastprivate: |
| 4683 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4684 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4685 | case OMPC_shared: |
| 4686 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4687 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4688 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4689 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 4690 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4691 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4692 | case OMPC_linear: |
| 4693 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 4694 | ColonLoc, EndLoc); |
| 4695 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4696 | case OMPC_aligned: |
| 4697 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 4698 | ColonLoc, EndLoc); |
| 4699 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4700 | case OMPC_copyin: |
| 4701 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4702 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4703 | case OMPC_copyprivate: |
| 4704 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4705 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4706 | case OMPC_flush: |
| 4707 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4708 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4709 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4710 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4711 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4712 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4713 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4714 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4715 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4716 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4717 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4718 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4719 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4720 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4721 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4722 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4723 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4724 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4725 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4726 | case OMPC_seq_cst: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4727 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4728 | llvm_unreachable("Clause is not allowed."); |
| 4729 | } |
| 4730 | return Res; |
| 4731 | } |
| 4732 | |
| 4733 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 4734 | SourceLocation StartLoc, |
| 4735 | SourceLocation LParenLoc, |
| 4736 | SourceLocation EndLoc) { |
| 4737 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4738 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4739 | for (auto &RefExpr : VarList) { |
| 4740 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 4741 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4742 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4743 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4744 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4745 | continue; |
| 4746 | } |
| 4747 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4748 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4749 | // OpenMP [2.1, C/C++] |
| 4750 | // A list item is a variable name. |
| 4751 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 4752 | // A variable that is part of another variable (as an array or |
| 4753 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4754 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4755 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4756 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4757 | continue; |
| 4758 | } |
| 4759 | Decl *D = DE->getDecl(); |
| 4760 | VarDecl *VD = cast<VarDecl>(D); |
| 4761 | |
| 4762 | QualType Type = VD->getType(); |
| 4763 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 4764 | // It will be analyzed later. |
| 4765 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4766 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4767 | continue; |
| 4768 | } |
| 4769 | |
| 4770 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 4771 | // A variable that appears in a private clause must not have an incomplete |
| 4772 | // type or a reference type. |
| 4773 | if (RequireCompleteType(ELoc, Type, |
| 4774 | diag::err_omp_private_incomplete_type)) { |
| 4775 | continue; |
| 4776 | } |
| 4777 | if (Type->isReferenceType()) { |
| 4778 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4779 | << getOpenMPClauseName(OMPC_private) << Type; |
| 4780 | bool IsDecl = |
| 4781 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4782 | Diag(VD->getLocation(), |
| 4783 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4784 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4785 | continue; |
| 4786 | } |
| 4787 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4788 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4789 | // in a Construct] |
| 4790 | // Variables with the predetermined data-sharing attributes may not be |
| 4791 | // listed in data-sharing attributes clauses, except for the cases |
| 4792 | // listed below. For these exceptions only, listing a predetermined |
| 4793 | // variable in a data-sharing attribute clause is allowed and overrides |
| 4794 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4795 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4796 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4797 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 4798 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4799 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4800 | continue; |
| 4801 | } |
| 4802 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 4803 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 4804 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 4805 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 4806 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 4807 | << getOpenMPClauseName(OMPC_private) << Type |
| 4808 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 4809 | bool IsDecl = |
| 4810 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4811 | Diag(VD->getLocation(), |
| 4812 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4813 | << VD; |
| 4814 | continue; |
| 4815 | } |
| 4816 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 4817 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 4818 | // A variable of class type (or array thereof) that appears in a private |
| 4819 | // clause requires an accessible, unambiguous default constructor for the |
| 4820 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4821 | // Generate helper private variable and initialize it with the default |
| 4822 | // value. The address of the original variable is replaced by the address of |
| 4823 | // the new private variable in CodeGen. This new variable is not added to |
| 4824 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 4825 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 4826 | Type = Type.getUnqualifiedType(); |
| 4827 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4828 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4829 | if (VDPrivate->isInvalidDecl()) |
| 4830 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 4831 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 4832 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4833 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4834 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4835 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4836 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4839 | if (Vars.empty()) |
| 4840 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4841 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4842 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 4843 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4844 | } |
| 4845 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4846 | namespace { |
| 4847 | class DiagsUninitializedSeveretyRAII { |
| 4848 | private: |
| 4849 | DiagnosticsEngine &Diags; |
| 4850 | SourceLocation SavedLoc; |
| 4851 | bool IsIgnored; |
| 4852 | |
| 4853 | public: |
| 4854 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 4855 | bool IsIgnored) |
| 4856 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 4857 | if (!IsIgnored) { |
| 4858 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 4859 | /*Map*/ diag::Severity::Ignored, Loc); |
| 4860 | } |
| 4861 | } |
| 4862 | ~DiagsUninitializedSeveretyRAII() { |
| 4863 | if (!IsIgnored) |
| 4864 | Diags.popMappings(SavedLoc); |
| 4865 | } |
| 4866 | }; |
| 4867 | } |
| 4868 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4869 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 4870 | SourceLocation StartLoc, |
| 4871 | SourceLocation LParenLoc, |
| 4872 | SourceLocation EndLoc) { |
| 4873 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4874 | SmallVector<Expr *, 8> PrivateCopies; |
| 4875 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4876 | bool IsImplicitClause = |
| 4877 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 4878 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 4879 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4880 | for (auto &RefExpr : VarList) { |
| 4881 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 4882 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4883 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4884 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4885 | PrivateCopies.push_back(nullptr); |
| 4886 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4887 | continue; |
| 4888 | } |
| 4889 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4890 | SourceLocation ELoc = |
| 4891 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4892 | // OpenMP [2.1, C/C++] |
| 4893 | // A list item is a variable name. |
| 4894 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 4895 | // A variable that is part of another variable (as an array or |
| 4896 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4897 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4898 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4899 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4900 | continue; |
| 4901 | } |
| 4902 | Decl *D = DE->getDecl(); |
| 4903 | VarDecl *VD = cast<VarDecl>(D); |
| 4904 | |
| 4905 | QualType Type = VD->getType(); |
| 4906 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 4907 | // It will be analyzed later. |
| 4908 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 4909 | PrivateCopies.push_back(nullptr); |
| 4910 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4911 | continue; |
| 4912 | } |
| 4913 | |
| 4914 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 4915 | // A variable that appears in a private clause must not have an incomplete |
| 4916 | // type or a reference type. |
| 4917 | if (RequireCompleteType(ELoc, Type, |
| 4918 | diag::err_omp_firstprivate_incomplete_type)) { |
| 4919 | continue; |
| 4920 | } |
| 4921 | if (Type->isReferenceType()) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4922 | if (IsImplicitClause) { |
| 4923 | Diag(ImplicitClauseLoc, |
| 4924 | diag::err_omp_task_predetermined_firstprivate_ref_type_arg) |
| 4925 | << Type; |
| 4926 | Diag(RefExpr->getExprLoc(), diag::note_used_here); |
| 4927 | } else { |
| 4928 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 4929 | << getOpenMPClauseName(OMPC_firstprivate) << Type; |
| 4930 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4931 | bool IsDecl = |
| 4932 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4933 | Diag(VD->getLocation(), |
| 4934 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4935 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4936 | continue; |
| 4937 | } |
| 4938 | |
| 4939 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 4940 | // 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] | 4941 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4942 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 4943 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4944 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4945 | // If an implicit firstprivate variable found it was checked already. |
| 4946 | if (!IsImplicitClause) { |
| 4947 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 4948 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4949 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 4950 | // A list item that specifies a given variable may not appear in more |
| 4951 | // than one clause on the same directive, except that a variable may be |
| 4952 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4953 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4954 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4955 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4956 | << getOpenMPClauseName(DVar.CKind) |
| 4957 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4958 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4959 | continue; |
| 4960 | } |
| 4961 | |
| 4962 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4963 | // in a Construct] |
| 4964 | // Variables with the predetermined data-sharing attributes may not be |
| 4965 | // listed in data-sharing attributes clauses, except for the cases |
| 4966 | // listed below. For these exceptions only, listing a predetermined |
| 4967 | // variable in a data-sharing attribute clause is allowed and overrides |
| 4968 | // the variable's predetermined data-sharing attributes. |
| 4969 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4970 | // in a Construct, C/C++, p.2] |
| 4971 | // Variables with const-qualified type having no mutable member may be |
| 4972 | // listed in a firstprivate clause, even if they are static data members. |
| 4973 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 4974 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 4975 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4976 | << getOpenMPClauseName(DVar.CKind) |
| 4977 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4978 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4979 | continue; |
| 4980 | } |
| 4981 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4982 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4983 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 4984 | // A list item that is private within a parallel region must not appear |
| 4985 | // in a firstprivate clause on a worksharing construct if any of the |
| 4986 | // worksharing regions arising from the worksharing construct ever bind |
| 4987 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 4988 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 4989 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4990 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 4991 | if (DVar.CKind != OMPC_shared && |
| 4992 | (isOpenMPParallelDirective(DVar.DKind) || |
| 4993 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4994 | Diag(ELoc, diag::err_omp_required_access) |
| 4995 | << getOpenMPClauseName(OMPC_firstprivate) |
| 4996 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4997 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4998 | continue; |
| 4999 | } |
| 5000 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5001 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 5002 | // A list item that appears in a reduction clause of a parallel construct |
| 5003 | // must not appear in a firstprivate clause on a worksharing or task |
| 5004 | // construct if any of the worksharing or task regions arising from the |
| 5005 | // worksharing or task construct ever bind to any of the parallel regions |
| 5006 | // arising from the parallel construct. |
| 5007 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 5008 | // A list item that appears in a reduction clause in worksharing |
| 5009 | // construct must not appear in a firstprivate clause in a task construct |
| 5010 | // encountered during execution of any of the worksharing regions arising |
| 5011 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5012 | if (CurrDir == OMPD_task) { |
| 5013 | DVar = |
| 5014 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 5015 | [](OpenMPDirectiveKind K) -> bool { |
| 5016 | return isOpenMPParallelDirective(K) || |
| 5017 | isOpenMPWorksharingDirective(K); |
| 5018 | }, |
| 5019 | false); |
| 5020 | if (DVar.CKind == OMPC_reduction && |
| 5021 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5022 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 5023 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 5024 | << getOpenMPDirectiveName(DVar.DKind); |
| 5025 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 5026 | continue; |
| 5027 | } |
| 5028 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5029 | } |
| 5030 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5031 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5032 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5033 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5034 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5035 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 5036 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5037 | bool IsDecl = |
| 5038 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5039 | Diag(VD->getLocation(), |
| 5040 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5041 | << VD; |
| 5042 | continue; |
| 5043 | } |
| 5044 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5045 | Type = Type.getUnqualifiedType(); |
| 5046 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName()); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5047 | // Generate helper private variable and initialize it with the value of the |
| 5048 | // original variable. The address of the original variable is replaced by |
| 5049 | // the address of the new private variable in the CodeGen. This new variable |
| 5050 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 5051 | // original variable for proper diagnostics and variable capturing. |
| 5052 | Expr *VDInitRefExpr = nullptr; |
| 5053 | // For arrays generate initializer for single element and replace it by the |
| 5054 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5055 | if (Type->isArrayType()) { |
| 5056 | auto VDInit = |
| 5057 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 5058 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5059 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5060 | ElemType = ElemType.getUnqualifiedType(); |
| 5061 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 5062 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5063 | InitializedEntity Entity = |
| 5064 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5065 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 5066 | |
| 5067 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 5068 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 5069 | if (Result.isInvalid()) |
| 5070 | VDPrivate->setInvalidDecl(); |
| 5071 | else |
| 5072 | VDPrivate->setInit(Result.getAs<Expr>()); |
| 5073 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5074 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5075 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5076 | VDInitRefExpr = |
| 5077 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5078 | AddInitializerToDecl(VDPrivate, |
| 5079 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 5080 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5081 | } |
| 5082 | if (VDPrivate->isInvalidDecl()) { |
| 5083 | if (IsImplicitClause) { |
| 5084 | Diag(DE->getExprLoc(), |
| 5085 | diag::note_omp_task_predetermined_firstprivate_here); |
| 5086 | } |
| 5087 | continue; |
| 5088 | } |
| 5089 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5090 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5091 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5092 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 5093 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5094 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 5095 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5098 | if (Vars.empty()) |
| 5099 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5100 | |
| 5101 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5102 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5103 | } |
| 5104 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5105 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 5106 | SourceLocation StartLoc, |
| 5107 | SourceLocation LParenLoc, |
| 5108 | SourceLocation EndLoc) { |
| 5109 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5110 | SmallVector<Expr *, 8> SrcExprs; |
| 5111 | SmallVector<Expr *, 8> DstExprs; |
| 5112 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5113 | for (auto &RefExpr : VarList) { |
| 5114 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 5115 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5116 | // It will be analyzed later. |
| 5117 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5118 | SrcExprs.push_back(nullptr); |
| 5119 | DstExprs.push_back(nullptr); |
| 5120 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5121 | continue; |
| 5122 | } |
| 5123 | |
| 5124 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 5125 | // OpenMP [2.1, C/C++] |
| 5126 | // A list item is a variable name. |
| 5127 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 5128 | // A variable that is part of another variable (as an array or structure |
| 5129 | // element) cannot appear in a lastprivate clause. |
| 5130 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 5131 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5132 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 5133 | continue; |
| 5134 | } |
| 5135 | Decl *D = DE->getDecl(); |
| 5136 | VarDecl *VD = cast<VarDecl>(D); |
| 5137 | |
| 5138 | QualType Type = VD->getType(); |
| 5139 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5140 | // It will be analyzed later. |
| 5141 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5142 | SrcExprs.push_back(nullptr); |
| 5143 | DstExprs.push_back(nullptr); |
| 5144 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5145 | continue; |
| 5146 | } |
| 5147 | |
| 5148 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 5149 | // A variable that appears in a lastprivate clause must not have an |
| 5150 | // incomplete type or a reference type. |
| 5151 | if (RequireCompleteType(ELoc, Type, |
| 5152 | diag::err_omp_lastprivate_incomplete_type)) { |
| 5153 | continue; |
| 5154 | } |
| 5155 | if (Type->isReferenceType()) { |
| 5156 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 5157 | << getOpenMPClauseName(OMPC_lastprivate) << Type; |
| 5158 | bool IsDecl = |
| 5159 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5160 | Diag(VD->getLocation(), |
| 5161 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5162 | << VD; |
| 5163 | continue; |
| 5164 | } |
| 5165 | |
| 5166 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5167 | // in a Construct] |
| 5168 | // Variables with the predetermined data-sharing attributes may not be |
| 5169 | // listed in data-sharing attributes clauses, except for the cases |
| 5170 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5171 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5172 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 5173 | DVar.CKind != OMPC_firstprivate && |
| 5174 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 5175 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 5176 | << getOpenMPClauseName(DVar.CKind) |
| 5177 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5178 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5179 | continue; |
| 5180 | } |
| 5181 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5182 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 5183 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 5184 | // A list item that is private within a parallel region, or that appears in |
| 5185 | // the reduction clause of a parallel construct, must not appear in a |
| 5186 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 5187 | // worksharing regions ever binds to any of the corresponding parallel |
| 5188 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5189 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5190 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5191 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5192 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5193 | if (DVar.CKind != OMPC_shared) { |
| 5194 | Diag(ELoc, diag::err_omp_required_access) |
| 5195 | << getOpenMPClauseName(OMPC_lastprivate) |
| 5196 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5197 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5198 | continue; |
| 5199 | } |
| 5200 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5201 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5202 | // A variable of class type (or array thereof) that appears in a |
| 5203 | // lastprivate clause requires an accessible, unambiguous default |
| 5204 | // constructor for the class type, unless the list item is also specified |
| 5205 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5206 | // A variable of class type (or array thereof) that appears in a |
| 5207 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 5208 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5209 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5210 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5211 | Type.getUnqualifiedType(), ".lastprivate.src"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5212 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 5213 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5214 | auto *DstVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5215 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst"); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5216 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5217 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5218 | // For arrays generate assignment operation for single element and replace |
| 5219 | // it by the original array element in CodeGen. |
| 5220 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 5221 | PseudoDstExpr, PseudoSrcExpr); |
| 5222 | if (AssignmentOp.isInvalid()) |
| 5223 | continue; |
| 5224 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 5225 | /*DiscardedValue=*/true); |
| 5226 | if (AssignmentOp.isInvalid()) |
| 5227 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5228 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5229 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5230 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5231 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5232 | SrcExprs.push_back(PseudoSrcExpr); |
| 5233 | DstExprs.push_back(PseudoDstExpr); |
| 5234 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
| 5237 | if (Vars.empty()) |
| 5238 | return nullptr; |
| 5239 | |
| 5240 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5241 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5244 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 5245 | SourceLocation StartLoc, |
| 5246 | SourceLocation LParenLoc, |
| 5247 | SourceLocation EndLoc) { |
| 5248 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5249 | for (auto &RefExpr : VarList) { |
| 5250 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 5251 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5252 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5253 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5254 | continue; |
| 5255 | } |
| 5256 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5257 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5258 | // OpenMP [2.1, C/C++] |
| 5259 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 5260 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 5261 | // A variable that is part of another variable (as an array or structure |
| 5262 | // element) cannot appear in a shared unless it is a static data member |
| 5263 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5264 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5265 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5266 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5267 | continue; |
| 5268 | } |
| 5269 | Decl *D = DE->getDecl(); |
| 5270 | VarDecl *VD = cast<VarDecl>(D); |
| 5271 | |
| 5272 | QualType Type = VD->getType(); |
| 5273 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5274 | // It will be analyzed later. |
| 5275 | Vars.push_back(DE); |
| 5276 | continue; |
| 5277 | } |
| 5278 | |
| 5279 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5280 | // in a Construct] |
| 5281 | // Variables with the predetermined data-sharing attributes may not be |
| 5282 | // listed in data-sharing attributes clauses, except for the cases |
| 5283 | // listed below. For these exceptions only, listing a predetermined |
| 5284 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5285 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5286 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5287 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 5288 | DVar.RefExpr) { |
| 5289 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5290 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5291 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5292 | continue; |
| 5293 | } |
| 5294 | |
| 5295 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 5296 | Vars.push_back(DE); |
| 5297 | } |
| 5298 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5299 | if (Vars.empty()) |
| 5300 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5301 | |
| 5302 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 5303 | } |
| 5304 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5305 | namespace { |
| 5306 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 5307 | DSAStackTy *Stack; |
| 5308 | |
| 5309 | public: |
| 5310 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 5311 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5312 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5313 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 5314 | return false; |
| 5315 | if (DVar.CKind != OMPC_unknown) |
| 5316 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5317 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5318 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5319 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5320 | return true; |
| 5321 | return false; |
| 5322 | } |
| 5323 | return false; |
| 5324 | } |
| 5325 | bool VisitStmt(Stmt *S) { |
| 5326 | for (auto Child : S->children()) { |
| 5327 | if (Child && Visit(Child)) |
| 5328 | return true; |
| 5329 | } |
| 5330 | return false; |
| 5331 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5332 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5333 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5334 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5335 | |
| 5336 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 5337 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 5338 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 5339 | CXXScopeSpec &ReductionIdScopeSpec, |
| 5340 | const DeclarationNameInfo &ReductionId) { |
| 5341 | // TODO: Allow scope specification search when 'declare reduction' is |
| 5342 | // supported. |
| 5343 | assert(ReductionIdScopeSpec.isEmpty() && |
| 5344 | "No support for scoped reduction identifiers yet."); |
| 5345 | |
| 5346 | auto DN = ReductionId.getName(); |
| 5347 | auto OOK = DN.getCXXOverloadedOperator(); |
| 5348 | BinaryOperatorKind BOK = BO_Comma; |
| 5349 | |
| 5350 | // OpenMP [2.14.3.6, reduction clause] |
| 5351 | // C |
| 5352 | // reduction-identifier is either an identifier or one of the following |
| 5353 | // operators: +, -, *, &, |, ^, && and || |
| 5354 | // C++ |
| 5355 | // reduction-identifier is either an id-expression or one of the following |
| 5356 | // operators: +, -, *, &, |, ^, && and || |
| 5357 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 5358 | switch (OOK) { |
| 5359 | case OO_Plus: |
| 5360 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5361 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5362 | break; |
| 5363 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5364 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5365 | break; |
| 5366 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5367 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5368 | break; |
| 5369 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5370 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5371 | break; |
| 5372 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5373 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5374 | break; |
| 5375 | case OO_AmpAmp: |
| 5376 | BOK = BO_LAnd; |
| 5377 | break; |
| 5378 | case OO_PipePipe: |
| 5379 | BOK = BO_LOr; |
| 5380 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5381 | case OO_New: |
| 5382 | case OO_Delete: |
| 5383 | case OO_Array_New: |
| 5384 | case OO_Array_Delete: |
| 5385 | case OO_Slash: |
| 5386 | case OO_Percent: |
| 5387 | case OO_Tilde: |
| 5388 | case OO_Exclaim: |
| 5389 | case OO_Equal: |
| 5390 | case OO_Less: |
| 5391 | case OO_Greater: |
| 5392 | case OO_LessEqual: |
| 5393 | case OO_GreaterEqual: |
| 5394 | case OO_PlusEqual: |
| 5395 | case OO_MinusEqual: |
| 5396 | case OO_StarEqual: |
| 5397 | case OO_SlashEqual: |
| 5398 | case OO_PercentEqual: |
| 5399 | case OO_CaretEqual: |
| 5400 | case OO_AmpEqual: |
| 5401 | case OO_PipeEqual: |
| 5402 | case OO_LessLess: |
| 5403 | case OO_GreaterGreater: |
| 5404 | case OO_LessLessEqual: |
| 5405 | case OO_GreaterGreaterEqual: |
| 5406 | case OO_EqualEqual: |
| 5407 | case OO_ExclaimEqual: |
| 5408 | case OO_PlusPlus: |
| 5409 | case OO_MinusMinus: |
| 5410 | case OO_Comma: |
| 5411 | case OO_ArrowStar: |
| 5412 | case OO_Arrow: |
| 5413 | case OO_Call: |
| 5414 | case OO_Subscript: |
| 5415 | case OO_Conditional: |
| 5416 | case NUM_OVERLOADED_OPERATORS: |
| 5417 | llvm_unreachable("Unexpected reduction identifier"); |
| 5418 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5419 | if (auto II = DN.getAsIdentifierInfo()) { |
| 5420 | if (II->isStr("max")) |
| 5421 | BOK = BO_GT; |
| 5422 | else if (II->isStr("min")) |
| 5423 | BOK = BO_LT; |
| 5424 | } |
| 5425 | break; |
| 5426 | } |
| 5427 | SourceRange ReductionIdRange; |
| 5428 | if (ReductionIdScopeSpec.isValid()) { |
| 5429 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 5430 | } |
| 5431 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 5432 | if (BOK == BO_Comma) { |
| 5433 | // Not allowed reduction identifier is found. |
| 5434 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 5435 | << ReductionIdRange; |
| 5436 | return nullptr; |
| 5437 | } |
| 5438 | |
| 5439 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5440 | SmallVector<Expr *, 8> LHSs; |
| 5441 | SmallVector<Expr *, 8> RHSs; |
| 5442 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5443 | for (auto RefExpr : VarList) { |
| 5444 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 5445 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5446 | // It will be analyzed later. |
| 5447 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5448 | LHSs.push_back(nullptr); |
| 5449 | RHSs.push_back(nullptr); |
| 5450 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5451 | continue; |
| 5452 | } |
| 5453 | |
| 5454 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 5455 | RefExpr->isInstantiationDependent() || |
| 5456 | RefExpr->containsUnexpandedParameterPack()) { |
| 5457 | // It will be analyzed later. |
| 5458 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5459 | LHSs.push_back(nullptr); |
| 5460 | RHSs.push_back(nullptr); |
| 5461 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5462 | continue; |
| 5463 | } |
| 5464 | |
| 5465 | auto ELoc = RefExpr->getExprLoc(); |
| 5466 | auto ERange = RefExpr->getSourceRange(); |
| 5467 | // OpenMP [2.1, C/C++] |
| 5468 | // A list item is a variable or array section, subject to the restrictions |
| 5469 | // specified in Section 2.4 on page 42 and in each of the sections |
| 5470 | // describing clauses and directives for which a list appears. |
| 5471 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 5472 | // A variable that is part of another variable (as an array or |
| 5473 | // structure element) cannot appear in a private clause. |
| 5474 | auto DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 5475 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5476 | Diag(ELoc, diag::err_omp_expected_var_name) << ERange; |
| 5477 | continue; |
| 5478 | } |
| 5479 | auto D = DE->getDecl(); |
| 5480 | auto VD = cast<VarDecl>(D); |
| 5481 | auto Type = VD->getType(); |
| 5482 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5483 | // A variable that appears in a private clause must not have an incomplete |
| 5484 | // type or a reference type. |
| 5485 | if (RequireCompleteType(ELoc, Type, |
| 5486 | diag::err_omp_reduction_incomplete_type)) |
| 5487 | continue; |
| 5488 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5489 | // Arrays may not appear in a reduction clause. |
| 5490 | if (Type.getNonReferenceType()->isArrayType()) { |
| 5491 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
| 5492 | bool IsDecl = |
| 5493 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5494 | Diag(VD->getLocation(), |
| 5495 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5496 | << VD; |
| 5497 | continue; |
| 5498 | } |
| 5499 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5500 | // A list item that appears in a reduction clause must not be |
| 5501 | // const-qualified. |
| 5502 | if (Type.getNonReferenceType().isConstant(Context)) { |
| 5503 | Diag(ELoc, diag::err_omp_const_variable) |
| 5504 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
| 5505 | bool IsDecl = |
| 5506 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5507 | Diag(VD->getLocation(), |
| 5508 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5509 | << VD; |
| 5510 | continue; |
| 5511 | } |
| 5512 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 5513 | // If a list-item is a reference type then it must bind to the same object |
| 5514 | // for all threads of the team. |
| 5515 | VarDecl *VDDef = VD->getDefinition(); |
| 5516 | if (Type->isReferenceType() && VDDef) { |
| 5517 | DSARefChecker Check(DSAStack); |
| 5518 | if (Check.Visit(VDDef->getInit())) { |
| 5519 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 5520 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 5521 | continue; |
| 5522 | } |
| 5523 | } |
| 5524 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5525 | // The type of a list item that appears in a reduction clause must be valid |
| 5526 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 5527 | // of the list item must be an allowed arithmetic data type: char, int, |
| 5528 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 5529 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 5530 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 5531 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 5532 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 5533 | !(Type->isScalarType() || |
| 5534 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 5535 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 5536 | << getLangOpts().CPlusPlus; |
| 5537 | bool IsDecl = |
| 5538 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5539 | Diag(VD->getLocation(), |
| 5540 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5541 | << VD; |
| 5542 | continue; |
| 5543 | } |
| 5544 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 5545 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 5546 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 5547 | bool IsDecl = |
| 5548 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5549 | Diag(VD->getLocation(), |
| 5550 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5551 | << VD; |
| 5552 | continue; |
| 5553 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5554 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5555 | // in a Construct] |
| 5556 | // Variables with the predetermined data-sharing attributes may not be |
| 5557 | // listed in data-sharing attributes clauses, except for the cases |
| 5558 | // listed below. For these exceptions only, listing a predetermined |
| 5559 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5560 | // the variable's predetermined data-sharing attributes. |
| 5561 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 5562 | // Any number of reduction clauses can be specified on the directive, |
| 5563 | // but a list item can appear only once in the reduction clauses for that |
| 5564 | // directive. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5565 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5566 | if (DVar.CKind == OMPC_reduction) { |
| 5567 | Diag(ELoc, diag::err_omp_once_referenced) |
| 5568 | << getOpenMPClauseName(OMPC_reduction); |
| 5569 | if (DVar.RefExpr) { |
| 5570 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 5571 | } |
| 5572 | } else if (DVar.CKind != OMPC_unknown) { |
| 5573 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 5574 | << getOpenMPClauseName(DVar.CKind) |
| 5575 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5576 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5577 | continue; |
| 5578 | } |
| 5579 | |
| 5580 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 5581 | // A list item that appears in a reduction clause of a worksharing |
| 5582 | // construct must be shared in the parallel regions to which any of the |
| 5583 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5584 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5585 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5586 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5587 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5588 | if (DVar.CKind != OMPC_shared) { |
| 5589 | Diag(ELoc, diag::err_omp_required_access) |
| 5590 | << getOpenMPClauseName(OMPC_reduction) |
| 5591 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5592 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5593 | continue; |
| 5594 | } |
| 5595 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5596 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5597 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs"); |
| 5598 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5599 | // Add initializer for private variable. |
| 5600 | Expr *Init = nullptr; |
| 5601 | switch (BOK) { |
| 5602 | case BO_Add: |
| 5603 | case BO_Xor: |
| 5604 | case BO_Or: |
| 5605 | case BO_LOr: |
| 5606 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 5607 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 5608 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5609 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5610 | break; |
| 5611 | case BO_Mul: |
| 5612 | case BO_LAnd: |
| 5613 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 5614 | // '*' and '&&' reduction ops - initializer is '1'. |
| 5615 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 5616 | } |
| 5617 | break; |
| 5618 | case BO_And: { |
| 5619 | // '&' reduction op - initializer is '~0'. |
| 5620 | QualType OrigType = Type; |
| 5621 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 5622 | Type = ComplexTy->getElementType(); |
| 5623 | } |
| 5624 | if (Type->isRealFloatingType()) { |
| 5625 | llvm::APFloat InitValue = |
| 5626 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 5627 | /*isIEEE=*/true); |
| 5628 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 5629 | Type, ELoc); |
| 5630 | } else if (Type->isScalarType()) { |
| 5631 | auto Size = Context.getTypeSize(Type); |
| 5632 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 5633 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 5634 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 5635 | } |
| 5636 | if (Init && OrigType->isAnyComplexType()) { |
| 5637 | // Init = 0xFFFF + 0xFFFFi; |
| 5638 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 5639 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 5640 | } |
| 5641 | Type = OrigType; |
| 5642 | break; |
| 5643 | } |
| 5644 | case BO_LT: |
| 5645 | case BO_GT: { |
| 5646 | // 'min' reduction op - initializer is 'Largest representable number in |
| 5647 | // the reduction list item type'. |
| 5648 | // 'max' reduction op - initializer is 'Least representable number in |
| 5649 | // the reduction list item type'. |
| 5650 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 5651 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 5652 | auto Size = Context.getTypeSize(Type); |
| 5653 | QualType IntTy = |
| 5654 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 5655 | llvm::APInt InitValue = |
| 5656 | (BOK != BO_LT) |
| 5657 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 5658 | : llvm::APInt::getMinValue(Size) |
| 5659 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 5660 | : llvm::APInt::getMaxValue(Size); |
| 5661 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 5662 | if (Type->isPointerType()) { |
| 5663 | // Cast to pointer type. |
| 5664 | auto CastExpr = BuildCStyleCastExpr( |
| 5665 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 5666 | SourceLocation(), Init); |
| 5667 | if (CastExpr.isInvalid()) |
| 5668 | continue; |
| 5669 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5670 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5671 | } else if (Type->isRealFloatingType()) { |
| 5672 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 5673 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 5674 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 5675 | Type, ELoc); |
| 5676 | } |
| 5677 | break; |
| 5678 | } |
| 5679 | case BO_PtrMemD: |
| 5680 | case BO_PtrMemI: |
| 5681 | case BO_MulAssign: |
| 5682 | case BO_Div: |
| 5683 | case BO_Rem: |
| 5684 | case BO_Sub: |
| 5685 | case BO_Shl: |
| 5686 | case BO_Shr: |
| 5687 | case BO_LE: |
| 5688 | case BO_GE: |
| 5689 | case BO_EQ: |
| 5690 | case BO_NE: |
| 5691 | case BO_AndAssign: |
| 5692 | case BO_XorAssign: |
| 5693 | case BO_OrAssign: |
| 5694 | case BO_Assign: |
| 5695 | case BO_AddAssign: |
| 5696 | case BO_SubAssign: |
| 5697 | case BO_DivAssign: |
| 5698 | case BO_RemAssign: |
| 5699 | case BO_ShlAssign: |
| 5700 | case BO_ShrAssign: |
| 5701 | case BO_Comma: |
| 5702 | llvm_unreachable("Unexpected reduction operation"); |
| 5703 | } |
| 5704 | if (Init) { |
| 5705 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 5706 | /*TypeMayContainAuto=*/false); |
| 5707 | } else { |
| 5708 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
| 5709 | } |
| 5710 | if (!RHSVD->hasInit()) { |
| 5711 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 5712 | << ReductionIdRange; |
| 5713 | bool IsDecl = |
| 5714 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5715 | Diag(VD->getLocation(), |
| 5716 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5717 | << VD; |
| 5718 | continue; |
| 5719 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5720 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 5721 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5722 | ExprResult ReductionOp = |
| 5723 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 5724 | LHSDRE, RHSDRE); |
| 5725 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 5726 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5727 | ReductionOp = |
| 5728 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 5729 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 5730 | } else { |
| 5731 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 5732 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 5733 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 5734 | ReductionOp = |
| 5735 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 5736 | BO_Assign, LHSDRE, ConditionalOp); |
| 5737 | } |
| 5738 | if (ReductionOp.isUsable()) { |
| 5739 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5740 | } |
| 5741 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5742 | if (ReductionOp.isInvalid()) |
| 5743 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5744 | |
| 5745 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 5746 | Vars.push_back(DE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5747 | LHSs.push_back(LHSDRE); |
| 5748 | RHSs.push_back(RHSDRE); |
| 5749 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5750 | } |
| 5751 | |
| 5752 | if (Vars.empty()) |
| 5753 | return nullptr; |
| 5754 | |
| 5755 | return OMPReductionClause::Create( |
| 5756 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5757 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, LHSs, |
| 5758 | RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5759 | } |
| 5760 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5761 | OMPClause *Sema::ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 5762 | SourceLocation StartLoc, |
| 5763 | SourceLocation LParenLoc, |
| 5764 | SourceLocation ColonLoc, |
| 5765 | SourceLocation EndLoc) { |
| 5766 | SmallVector<Expr *, 8> Vars; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5767 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5768 | for (auto &RefExpr : VarList) { |
| 5769 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 5770 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5771 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5772 | Vars.push_back(RefExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5773 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5774 | continue; |
| 5775 | } |
| 5776 | |
| 5777 | // OpenMP [2.14.3.7, linear clause] |
| 5778 | // A list item that appears in a linear clause is subject to the private |
| 5779 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 5780 | // noted. In addition, the value of the new list item on each iteration |
| 5781 | // of the associated loop(s) corresponds to the value of the original |
| 5782 | // list item before entering the construct plus the logical number of |
| 5783 | // the iteration times linear-step. |
| 5784 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5785 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5786 | // OpenMP [2.1, C/C++] |
| 5787 | // A list item is a variable name. |
| 5788 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 5789 | // A variable that is part of another variable (as an array or |
| 5790 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5791 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5792 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5793 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5794 | continue; |
| 5795 | } |
| 5796 | |
| 5797 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 5798 | |
| 5799 | // OpenMP [2.14.3.7, linear clause] |
| 5800 | // A list-item cannot appear in more than one linear clause. |
| 5801 | // A list-item that appears in a linear clause cannot appear in any |
| 5802 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5803 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5804 | if (DVar.RefExpr) { |
| 5805 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5806 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5807 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5808 | continue; |
| 5809 | } |
| 5810 | |
| 5811 | QualType QType = VD->getType(); |
| 5812 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 5813 | // It will be analyzed later. |
| 5814 | Vars.push_back(DE); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5815 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5816 | continue; |
| 5817 | } |
| 5818 | |
| 5819 | // A variable must not have an incomplete type or a reference type. |
| 5820 | if (RequireCompleteType(ELoc, QType, |
| 5821 | diag::err_omp_linear_incomplete_type)) { |
| 5822 | continue; |
| 5823 | } |
| 5824 | if (QType->isReferenceType()) { |
| 5825 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 5826 | << getOpenMPClauseName(OMPC_linear) << QType; |
| 5827 | bool IsDecl = |
| 5828 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5829 | Diag(VD->getLocation(), |
| 5830 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5831 | << VD; |
| 5832 | continue; |
| 5833 | } |
| 5834 | |
| 5835 | // A list item must not be const-qualified. |
| 5836 | if (QType.isConstant(Context)) { |
| 5837 | Diag(ELoc, diag::err_omp_const_variable) |
| 5838 | << getOpenMPClauseName(OMPC_linear); |
| 5839 | bool IsDecl = |
| 5840 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5841 | Diag(VD->getLocation(), |
| 5842 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5843 | << VD; |
| 5844 | continue; |
| 5845 | } |
| 5846 | |
| 5847 | // A list item must be of integral or pointer type. |
| 5848 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 5849 | const Type *Ty = QType.getTypePtrOrNull(); |
| 5850 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 5851 | !Ty->isPointerType())) { |
| 5852 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 5853 | bool IsDecl = |
| 5854 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5855 | Diag(VD->getLocation(), |
| 5856 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5857 | << VD; |
| 5858 | continue; |
| 5859 | } |
| 5860 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5861 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5862 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5863 | AddInitializerToDecl(Init, DefaultLvalueConversion(DE).get(), |
| 5864 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5865 | auto InitRef = buildDeclRefExpr( |
| 5866 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5867 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 5868 | Vars.push_back(DE); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5869 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5870 | } |
| 5871 | |
| 5872 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5873 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5874 | |
| 5875 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5876 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5877 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 5878 | !Step->isInstantiationDependent() && |
| 5879 | !Step->containsUnexpandedParameterPack()) { |
| 5880 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5881 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5882 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5883 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5884 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5885 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5886 | // Build var to save the step value. |
| 5887 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5888 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5889 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5890 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5891 | ExprResult CalcStep = |
| 5892 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
| 5893 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5894 | // Warn about zero linear step (it would be probably better specified as |
| 5895 | // making corresponding variables 'const'). |
| 5896 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5897 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 5898 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5899 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 5900 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5901 | if (!IsConstant && CalcStep.isUsable()) { |
| 5902 | // Calculate the step beforehand instead of doing this on each iteration. |
| 5903 | // (This is not used if the number of iterations may be kfold-ed). |
| 5904 | CalcStepExpr = CalcStep.get(); |
| 5905 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5906 | } |
| 5907 | |
| 5908 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, ColonLoc, EndLoc, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5909 | Vars, Inits, StepExpr, CalcStepExpr); |
| 5910 | } |
| 5911 | |
| 5912 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 5913 | Expr *NumIterations, Sema &SemaRef, |
| 5914 | Scope *S) { |
| 5915 | // Walk the vars and build update/final expressions for the CodeGen. |
| 5916 | SmallVector<Expr *, 8> Updates; |
| 5917 | SmallVector<Expr *, 8> Finals; |
| 5918 | Expr *Step = Clause.getStep(); |
| 5919 | Expr *CalcStep = Clause.getCalcStep(); |
| 5920 | // OpenMP [2.14.3.7, linear clause] |
| 5921 | // If linear-step is not specified it is assumed to be 1. |
| 5922 | if (Step == nullptr) |
| 5923 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 5924 | else if (CalcStep) |
| 5925 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 5926 | bool HasErrors = false; |
| 5927 | auto CurInit = Clause.inits().begin(); |
| 5928 | for (auto &RefExpr : Clause.varlists()) { |
| 5929 | Expr *InitExpr = *CurInit; |
| 5930 | |
| 5931 | // Build privatized reference to the current linear var. |
| 5932 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5933 | auto PrivateRef = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5934 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 5935 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 5936 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5937 | |
| 5938 | // Build update: Var = InitExpr + IV * Step |
| 5939 | ExprResult Update = |
| 5940 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), PrivateRef, |
| 5941 | InitExpr, IV, Step, /* Subtract */ false); |
| 5942 | Update = SemaRef.ActOnFinishFullExpr(Update.get()); |
| 5943 | |
| 5944 | // Build final: Var = InitExpr + NumIterations * Step |
| 5945 | ExprResult Final = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5946 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), PrivateRef, |
| 5947 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5948 | Final = SemaRef.ActOnFinishFullExpr(Final.get()); |
| 5949 | if (!Update.isUsable() || !Final.isUsable()) { |
| 5950 | Updates.push_back(nullptr); |
| 5951 | Finals.push_back(nullptr); |
| 5952 | HasErrors = true; |
| 5953 | } else { |
| 5954 | Updates.push_back(Update.get()); |
| 5955 | Finals.push_back(Final.get()); |
| 5956 | } |
| 5957 | ++CurInit; |
| 5958 | } |
| 5959 | Clause.setUpdates(Updates); |
| 5960 | Clause.setFinals(Finals); |
| 5961 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5962 | } |
| 5963 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5964 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 5965 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 5966 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 5967 | |
| 5968 | SmallVector<Expr *, 8> Vars; |
| 5969 | for (auto &RefExpr : VarList) { |
| 5970 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 5971 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5972 | // It will be analyzed later. |
| 5973 | Vars.push_back(RefExpr); |
| 5974 | continue; |
| 5975 | } |
| 5976 | |
| 5977 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 5978 | // OpenMP [2.1, C/C++] |
| 5979 | // A list item is a variable name. |
| 5980 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 5981 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5982 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 5983 | continue; |
| 5984 | } |
| 5985 | |
| 5986 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 5987 | |
| 5988 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 5989 | // The type of list items appearing in the aligned clause must be |
| 5990 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5991 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5992 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5993 | const Type *Ty = QType.getTypePtrOrNull(); |
| 5994 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 5995 | !Ty->isPointerType())) { |
| 5996 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 5997 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 5998 | bool IsDecl = |
| 5999 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6000 | Diag(VD->getLocation(), |
| 6001 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6002 | << VD; |
| 6003 | continue; |
| 6004 | } |
| 6005 | |
| 6006 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6007 | // A list-item cannot appear in more than one aligned clause. |
| 6008 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 6009 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 6010 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 6011 | << getOpenMPClauseName(OMPC_aligned); |
| 6012 | continue; |
| 6013 | } |
| 6014 | |
| 6015 | Vars.push_back(DE); |
| 6016 | } |
| 6017 | |
| 6018 | // OpenMP [2.8.1, simd construct, Description] |
| 6019 | // The parameter of the aligned clause, alignment, must be a constant |
| 6020 | // positive integer expression. |
| 6021 | // If no optional parameter is specified, implementation-defined default |
| 6022 | // alignments for SIMD instructions on the target platforms are assumed. |
| 6023 | if (Alignment != nullptr) { |
| 6024 | ExprResult AlignResult = |
| 6025 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 6026 | if (AlignResult.isInvalid()) |
| 6027 | return nullptr; |
| 6028 | Alignment = AlignResult.get(); |
| 6029 | } |
| 6030 | if (Vars.empty()) |
| 6031 | return nullptr; |
| 6032 | |
| 6033 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 6034 | EndLoc, Vars, Alignment); |
| 6035 | } |
| 6036 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6037 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 6038 | SourceLocation StartLoc, |
| 6039 | SourceLocation LParenLoc, |
| 6040 | SourceLocation EndLoc) { |
| 6041 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6042 | SmallVector<Expr *, 8> SrcExprs; |
| 6043 | SmallVector<Expr *, 8> DstExprs; |
| 6044 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6045 | for (auto &RefExpr : VarList) { |
| 6046 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 6047 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6048 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6049 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6050 | SrcExprs.push_back(nullptr); |
| 6051 | DstExprs.push_back(nullptr); |
| 6052 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6053 | continue; |
| 6054 | } |
| 6055 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6056 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6057 | // OpenMP [2.1, C/C++] |
| 6058 | // A list item is a variable name. |
| 6059 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6060 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6061 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6062 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6063 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6064 | continue; |
| 6065 | } |
| 6066 | |
| 6067 | Decl *D = DE->getDecl(); |
| 6068 | VarDecl *VD = cast<VarDecl>(D); |
| 6069 | |
| 6070 | QualType Type = VD->getType(); |
| 6071 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6072 | // It will be analyzed later. |
| 6073 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6074 | SrcExprs.push_back(nullptr); |
| 6075 | DstExprs.push_back(nullptr); |
| 6076 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6077 | continue; |
| 6078 | } |
| 6079 | |
| 6080 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 6081 | // A list item that appears in a copyin clause must be threadprivate. |
| 6082 | if (!DSAStack->isThreadPrivate(VD)) { |
| 6083 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6084 | << getOpenMPClauseName(OMPC_copyin) |
| 6085 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6086 | continue; |
| 6087 | } |
| 6088 | |
| 6089 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6090 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6091 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6092 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6093 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6094 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6095 | ElemType.getUnqualifiedType(), ".copyin.src"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6096 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6097 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 6098 | auto *DstVD = |
| 6099 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst"); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6100 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6101 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6102 | // For arrays generate assignment operation for single element and replace |
| 6103 | // it by the original array element in CodeGen. |
| 6104 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6105 | PseudoDstExpr, PseudoSrcExpr); |
| 6106 | if (AssignmentOp.isInvalid()) |
| 6107 | continue; |
| 6108 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6109 | /*DiscardedValue=*/true); |
| 6110 | if (AssignmentOp.isInvalid()) |
| 6111 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6112 | |
| 6113 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 6114 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6115 | SrcExprs.push_back(PseudoSrcExpr); |
| 6116 | DstExprs.push_back(PseudoDstExpr); |
| 6117 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6118 | } |
| 6119 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6120 | if (Vars.empty()) |
| 6121 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6122 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6123 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6124 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6127 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 6128 | SourceLocation StartLoc, |
| 6129 | SourceLocation LParenLoc, |
| 6130 | SourceLocation EndLoc) { |
| 6131 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6132 | SmallVector<Expr *, 8> SrcExprs; |
| 6133 | SmallVector<Expr *, 8> DstExprs; |
| 6134 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6135 | for (auto &RefExpr : VarList) { |
| 6136 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 6137 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6138 | // It will be analyzed later. |
| 6139 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6140 | SrcExprs.push_back(nullptr); |
| 6141 | DstExprs.push_back(nullptr); |
| 6142 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6143 | continue; |
| 6144 | } |
| 6145 | |
| 6146 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6147 | // OpenMP [2.1, C/C++] |
| 6148 | // A list item is a variable name. |
| 6149 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6150 | // A list item that appears in a copyin clause must be threadprivate. |
| 6151 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6152 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6153 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6154 | continue; |
| 6155 | } |
| 6156 | |
| 6157 | Decl *D = DE->getDecl(); |
| 6158 | VarDecl *VD = cast<VarDecl>(D); |
| 6159 | |
| 6160 | QualType Type = VD->getType(); |
| 6161 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6162 | // It will be analyzed later. |
| 6163 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6164 | SrcExprs.push_back(nullptr); |
| 6165 | DstExprs.push_back(nullptr); |
| 6166 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6167 | continue; |
| 6168 | } |
| 6169 | |
| 6170 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 6171 | // A list item that appears in a copyprivate clause may not appear in a |
| 6172 | // private or firstprivate clause on the single construct. |
| 6173 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6174 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6175 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 6176 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6177 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6178 | << getOpenMPClauseName(DVar.CKind) |
| 6179 | << getOpenMPClauseName(OMPC_copyprivate); |
| 6180 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6181 | continue; |
| 6182 | } |
| 6183 | |
| 6184 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 6185 | // All list items that appear in a copyprivate clause must be either |
| 6186 | // threadprivate or private in the enclosing context. |
| 6187 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6188 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6189 | if (DVar.CKind == OMPC_shared) { |
| 6190 | Diag(ELoc, diag::err_omp_required_access) |
| 6191 | << getOpenMPClauseName(OMPC_copyprivate) |
| 6192 | << "threadprivate or private in the enclosing context"; |
| 6193 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6194 | continue; |
| 6195 | } |
| 6196 | } |
| 6197 | } |
| 6198 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6199 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6200 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6201 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6202 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 6203 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6204 | bool IsDecl = |
| 6205 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6206 | Diag(VD->getLocation(), |
| 6207 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6208 | << VD; |
| 6209 | continue; |
| 6210 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6211 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6212 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6213 | // A variable of class type (or array thereof) that appears in a |
| 6214 | // copyin clause requires an accessible, unambiguous copy assignment |
| 6215 | // operator for the class type. |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6216 | Type = Context.getBaseElementType(Type).getUnqualifiedType(); |
| 6217 | auto *SrcVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6218 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src"); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6219 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6220 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6221 | auto *DstVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6222 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst"); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6223 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6224 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6225 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6226 | PseudoDstExpr, PseudoSrcExpr); |
| 6227 | if (AssignmentOp.isInvalid()) |
| 6228 | continue; |
| 6229 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6230 | /*DiscardedValue=*/true); |
| 6231 | if (AssignmentOp.isInvalid()) |
| 6232 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6233 | |
| 6234 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 6235 | // implicitly private. |
| 6236 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6237 | SrcExprs.push_back(PseudoSrcExpr); |
| 6238 | DstExprs.push_back(PseudoDstExpr); |
| 6239 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6240 | } |
| 6241 | |
| 6242 | if (Vars.empty()) |
| 6243 | return nullptr; |
| 6244 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6245 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 6246 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6247 | } |
| 6248 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6249 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 6250 | SourceLocation StartLoc, |
| 6251 | SourceLocation LParenLoc, |
| 6252 | SourceLocation EndLoc) { |
| 6253 | if (VarList.empty()) |
| 6254 | return nullptr; |
| 6255 | |
| 6256 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 6257 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6258 | |