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 | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 98 | bool NowaitRegion; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 99 | unsigned CollapseNumber; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 100 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 101 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 102 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 103 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 104 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 105 | ConstructLoc(Loc), OrderedRegion(false), NowaitRegion(false), |
| 106 | CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 107 | SharingMapTy() |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 108 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 109 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 110 | ConstructLoc(), OrderedRegion(false), NowaitRegion(false), |
| 111 | CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 115 | |
| 116 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 117 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 118 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 119 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 120 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 121 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 122 | |
| 123 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 124 | |
| 125 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 126 | |
| 127 | /// \brief Checks if the variable is a local for OpenMP region. |
| 128 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 129 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 130 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 131 | explicit DSAStackTy(Sema &S) |
| 132 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 133 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 134 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 135 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 136 | |
| 137 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 138 | Scope *CurScope, SourceLocation Loc) { |
| 139 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 140 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | void pop() { |
| 144 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 145 | Stack.pop_back(); |
| 146 | } |
| 147 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 148 | /// \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] | 149 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 150 | /// for diagnostics. |
| 151 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 152 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 153 | /// \brief Register specified variable as loop control variable. |
| 154 | void addLoopControlVariable(VarDecl *D); |
| 155 | /// \brief Check if the specified variable is a loop control variable for |
| 156 | /// current region. |
| 157 | bool isLoopControlVariable(VarDecl *D); |
| 158 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 159 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 160 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 161 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 162 | /// \brief Returns data sharing attributes from top of the stack for the |
| 163 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 164 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 165 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 166 | DSAVarData getImplicitDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 167 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 168 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 169 | /// predicate. |
| 170 | template <class ClausesPredicate, class DirectivesPredicate> |
| 171 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 172 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 173 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 174 | /// match specified \a CPred predicate in any innermost directive which |
| 175 | /// matches \a DPred predicate. |
| 176 | template <class ClausesPredicate, class DirectivesPredicate> |
| 177 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 178 | DirectivesPredicate DPred, |
| 179 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 180 | /// \brief Checks if the specified variables has explicit data-sharing |
| 181 | /// attributes which match specified \a CPred predicate at the specified |
| 182 | /// OpenMP region. |
| 183 | bool hasExplicitDSA(VarDecl *D, |
| 184 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 185 | unsigned Level); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 186 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 187 | template <class NamedDirectivesPredicate> |
| 188 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 189 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 190 | /// \brief Returns currently analyzed directive. |
| 191 | OpenMPDirectiveKind getCurrentDirective() const { |
| 192 | return Stack.back().Directive; |
| 193 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 194 | /// \brief Returns parent directive. |
| 195 | OpenMPDirectiveKind getParentDirective() const { |
| 196 | if (Stack.size() > 2) |
| 197 | return Stack[Stack.size() - 2].Directive; |
| 198 | return OMPD_unknown; |
| 199 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 200 | |
| 201 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 202 | void setDefaultDSANone(SourceLocation Loc) { |
| 203 | Stack.back().DefaultAttr = DSA_none; |
| 204 | Stack.back().DefaultAttrLoc = Loc; |
| 205 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 206 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 207 | void setDefaultDSAShared(SourceLocation Loc) { |
| 208 | Stack.back().DefaultAttr = DSA_shared; |
| 209 | Stack.back().DefaultAttrLoc = Loc; |
| 210 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 211 | |
| 212 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 213 | return Stack.back().DefaultAttr; |
| 214 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 215 | SourceLocation getDefaultDSALocation() const { |
| 216 | return Stack.back().DefaultAttrLoc; |
| 217 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 218 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 219 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 220 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 221 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 222 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 225 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
| 226 | void setOrderedRegion(bool IsOrdered = true) { |
| 227 | Stack.back().OrderedRegion = IsOrdered; |
| 228 | } |
| 229 | /// \brief Returns true, if parent region is ordered (has associated |
| 230 | /// 'ordered' clause), false - otherwise. |
| 231 | bool isParentOrderedRegion() const { |
| 232 | if (Stack.size() > 2) |
| 233 | return Stack[Stack.size() - 2].OrderedRegion; |
| 234 | return false; |
| 235 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 236 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 237 | void setNowaitRegion(bool IsNowait = true) { |
| 238 | Stack.back().NowaitRegion = IsNowait; |
| 239 | } |
| 240 | /// \brief Returns true, if parent region is nowait (has associated |
| 241 | /// 'nowait' clause), false - otherwise. |
| 242 | bool isParentNowaitRegion() const { |
| 243 | if (Stack.size() > 2) |
| 244 | return Stack[Stack.size() - 2].NowaitRegion; |
| 245 | return false; |
| 246 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 247 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 248 | /// \brief Set collapse value for the region. |
| 249 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 250 | /// \brief Return collapse value for region. |
| 251 | unsigned getCollapseNumber() const { |
| 252 | return Stack.back().CollapseNumber; |
| 253 | } |
| 254 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 255 | /// \brief Marks current target region as one with closely nested teams |
| 256 | /// region. |
| 257 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 258 | if (Stack.size() > 2) |
| 259 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 260 | } |
| 261 | /// \brief Returns true, if current region has closely nested teams region. |
| 262 | bool hasInnerTeamsRegion() const { |
| 263 | return getInnerTeamsRegionLoc().isValid(); |
| 264 | } |
| 265 | /// \brief Returns location of the nested teams region (if any). |
| 266 | SourceLocation getInnerTeamsRegionLoc() const { |
| 267 | if (Stack.size() > 1) |
| 268 | return Stack.back().InnerTeamsRegionLoc; |
| 269 | return SourceLocation(); |
| 270 | } |
| 271 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 272 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 273 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 274 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 275 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 276 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 277 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 278 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 279 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 280 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 281 | |
| 282 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 283 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 284 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 285 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 286 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 287 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 288 | // in a region but not in construct] |
| 289 | // File-scope or namespace-scope variables referenced in called routines |
| 290 | // in the region are shared unless they appear in a threadprivate |
| 291 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 292 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 293 | DVar.CKind = OMPC_shared; |
| 294 | |
| 295 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 296 | // in a region but not in construct] |
| 297 | // Variables with static storage duration that are declared in called |
| 298 | // routines in the region are shared. |
| 299 | if (D->hasGlobalStorage()) |
| 300 | DVar.CKind = OMPC_shared; |
| 301 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 302 | return DVar; |
| 303 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 304 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 305 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 306 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 307 | // in a Construct, C/C++, predetermined, p.1] |
| 308 | // Variables with automatic storage duration that are declared in a scope |
| 309 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 310 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 311 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 312 | DVar.CKind = OMPC_private; |
| 313 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 316 | // Explicitly specified attributes and local variables with predetermined |
| 317 | // attributes. |
| 318 | if (Iter->SharingMap.count(D)) { |
| 319 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 320 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 321 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 322 | return DVar; |
| 323 | } |
| 324 | |
| 325 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 326 | // in a Construct, C/C++, implicitly determined, p.1] |
| 327 | // In a parallel or task construct, the data-sharing attributes of these |
| 328 | // variables are determined by the default clause, if present. |
| 329 | switch (Iter->DefaultAttr) { |
| 330 | case DSA_shared: |
| 331 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 332 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 333 | return DVar; |
| 334 | case DSA_none: |
| 335 | return DVar; |
| 336 | case DSA_unspecified: |
| 337 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 338 | // in a Construct, implicitly determined, p.2] |
| 339 | // In a parallel construct, if no default clause is present, these |
| 340 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 341 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 342 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 343 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 344 | DVar.CKind = OMPC_shared; |
| 345 | return DVar; |
| 346 | } |
| 347 | |
| 348 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 349 | // in a Construct, implicitly determined, p.4] |
| 350 | // In a task construct, if no default clause is present, a variable that in |
| 351 | // the enclosing context is determined to be shared by all implicit tasks |
| 352 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 353 | if (DVar.DKind == OMPD_task) { |
| 354 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 355 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 356 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 357 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 358 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 359 | // in a Construct, implicitly determined, p.6] |
| 360 | // In a task construct, if no default clause is present, a variable |
| 361 | // whose data-sharing attribute is not determined by the rules above is |
| 362 | // firstprivate. |
| 363 | DVarTemp = getDSA(I, D); |
| 364 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 365 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 366 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 367 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 368 | return DVar; |
| 369 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 370 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 371 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 372 | } |
| 373 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 374 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 375 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 376 | return DVar; |
| 377 | } |
| 378 | } |
| 379 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 380 | // in a Construct, implicitly determined, p.3] |
| 381 | // For constructs other than task, if no default clause is present, these |
| 382 | // variables inherit their data-sharing attributes from the enclosing |
| 383 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 384 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 387 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 388 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 389 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 390 | auto It = Stack.back().AlignedMap.find(D); |
| 391 | if (It == Stack.back().AlignedMap.end()) { |
| 392 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 393 | Stack.back().AlignedMap[D] = NewDE; |
| 394 | return nullptr; |
| 395 | } else { |
| 396 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 397 | return It->second; |
| 398 | } |
| 399 | return nullptr; |
| 400 | } |
| 401 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 402 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 403 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 404 | D = D->getCanonicalDecl(); |
| 405 | Stack.back().LCVSet.insert(D); |
| 406 | } |
| 407 | |
| 408 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 409 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 410 | D = D->getCanonicalDecl(); |
| 411 | return Stack.back().LCVSet.count(D) > 0; |
| 412 | } |
| 413 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 414 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 415 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 416 | if (A == OMPC_threadprivate) { |
| 417 | Stack[0].SharingMap[D].Attributes = A; |
| 418 | Stack[0].SharingMap[D].RefExpr = E; |
| 419 | } else { |
| 420 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 421 | Stack.back().SharingMap[D].Attributes = A; |
| 422 | Stack.back().SharingMap[D].RefExpr = E; |
| 423 | } |
| 424 | } |
| 425 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 426 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 427 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 428 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 429 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 430 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 431 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 432 | ++I; |
| 433 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 434 | if (I == E) |
| 435 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 436 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 437 | Scope *CurScope = getCurScope(); |
| 438 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 439 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 440 | } |
| 441 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 442 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 443 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 446 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 447 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
| 448 | StringRef Name) { |
| 449 | DeclContext *DC = SemaRef.CurContext; |
| 450 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 451 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 452 | VarDecl *Decl = |
| 453 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
| 454 | Decl->setImplicit(); |
| 455 | return Decl; |
| 456 | } |
| 457 | |
| 458 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 459 | SourceLocation Loc, |
| 460 | bool RefersToCapture = false) { |
| 461 | D->setReferenced(); |
| 462 | D->markUsed(S.Context); |
| 463 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 464 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 465 | VK_LValue); |
| 466 | } |
| 467 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 468 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 469 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 470 | DSAVarData DVar; |
| 471 | |
| 472 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 473 | // in a Construct, C/C++, predetermined, p.1] |
| 474 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 475 | if (D->getTLSKind() != VarDecl::TLS_None || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 476 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 477 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 478 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 479 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 480 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 481 | } |
| 482 | if (Stack[0].SharingMap.count(D)) { |
| 483 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 484 | DVar.CKind = OMPC_threadprivate; |
| 485 | return DVar; |
| 486 | } |
| 487 | |
| 488 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 489 | // in a Construct, C/C++, predetermined, p.1] |
| 490 | // Variables with automatic storage duration that are declared in a scope |
| 491 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 492 | OpenMPDirectiveKind Kind = |
| 493 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 494 | auto StartI = std::next(Stack.rbegin()); |
| 495 | auto EndI = std::prev(Stack.rend()); |
| 496 | if (FromParent && StartI != EndI) { |
| 497 | StartI = std::next(StartI); |
| 498 | } |
| 499 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 500 | if (isOpenMPLocal(D, StartI) && |
| 501 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 502 | D->getStorageClass() == SC_None)) || |
| 503 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 504 | DVar.CKind = OMPC_private; |
| 505 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 506 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 507 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 508 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 509 | // in a Construct, C/C++, predetermined, p.4] |
| 510 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 511 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 512 | // in a Construct, C/C++, predetermined, p.7] |
| 513 | // Variables with static storage duration that are declared in a scope |
| 514 | // inside the construct are shared. |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 515 | if (D->isStaticDataMember() || D->isStaticLocal()) { |
| 516 | DSAVarData DVarTemp = |
| 517 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 518 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 519 | return DVar; |
| 520 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 521 | DVar.CKind = OMPC_shared; |
| 522 | return DVar; |
| 523 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 527 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 528 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 529 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 530 | // in a Construct, C/C++, predetermined, p.6] |
| 531 | // Variables with const qualified type having no mutable member are |
| 532 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 533 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 534 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 535 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 536 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 537 | // Variables with const-qualified type having no mutable member may be |
| 538 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 539 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 540 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 541 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 542 | return DVar; |
| 543 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 544 | DVar.CKind = OMPC_shared; |
| 545 | return DVar; |
| 546 | } |
| 547 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 548 | // Explicitly specified attributes and local variables with predetermined |
| 549 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 550 | auto I = std::prev(StartI); |
| 551 | if (I->SharingMap.count(D)) { |
| 552 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 553 | DVar.CKind = I->SharingMap[D].Attributes; |
| 554 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | return DVar; |
| 558 | } |
| 559 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 560 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 561 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 562 | auto StartI = Stack.rbegin(); |
| 563 | auto EndI = std::prev(Stack.rend()); |
| 564 | if (FromParent && StartI != EndI) { |
| 565 | StartI = std::next(StartI); |
| 566 | } |
| 567 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 570 | template <class ClausesPredicate, class DirectivesPredicate> |
| 571 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 572 | DirectivesPredicate DPred, |
| 573 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 574 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 575 | auto StartI = std::next(Stack.rbegin()); |
| 576 | auto EndI = std::prev(Stack.rend()); |
| 577 | if (FromParent && StartI != EndI) { |
| 578 | StartI = std::next(StartI); |
| 579 | } |
| 580 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 581 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 582 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 583 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 584 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 585 | return DVar; |
| 586 | } |
| 587 | return DSAVarData(); |
| 588 | } |
| 589 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 590 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 591 | DSAStackTy::DSAVarData |
| 592 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 593 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 594 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 595 | auto StartI = std::next(Stack.rbegin()); |
| 596 | auto EndI = std::prev(Stack.rend()); |
| 597 | if (FromParent && StartI != EndI) { |
| 598 | StartI = std::next(StartI); |
| 599 | } |
| 600 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 601 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 602 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 603 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 604 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 605 | return DVar; |
| 606 | return DSAVarData(); |
| 607 | } |
| 608 | return DSAVarData(); |
| 609 | } |
| 610 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 611 | bool DSAStackTy::hasExplicitDSA( |
| 612 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 613 | unsigned Level) { |
| 614 | if (CPred(ClauseKindMode)) |
| 615 | return true; |
| 616 | if (isClauseParsingMode()) |
| 617 | ++Level; |
| 618 | D = D->getCanonicalDecl(); |
| 619 | auto StartI = Stack.rbegin(); |
| 620 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 621 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 622 | return false; |
| 623 | std::advance(StartI, Level); |
| 624 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 625 | CPred(StartI->SharingMap[D].Attributes); |
| 626 | } |
| 627 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 628 | template <class NamedDirectivesPredicate> |
| 629 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 630 | auto StartI = std::next(Stack.rbegin()); |
| 631 | auto EndI = std::prev(Stack.rend()); |
| 632 | if (FromParent && StartI != EndI) { |
| 633 | StartI = std::next(StartI); |
| 634 | } |
| 635 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 636 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 637 | return true; |
| 638 | } |
| 639 | return false; |
| 640 | } |
| 641 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 642 | void Sema::InitDataSharingAttributesStack() { |
| 643 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 644 | } |
| 645 | |
| 646 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 647 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 648 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 649 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 650 | VD = VD->getCanonicalDecl(); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 651 | if (DSAStack->getCurrentDirective() != OMPD_unknown) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 652 | if (DSAStack->isLoopControlVariable(VD) || |
| 653 | (VD->hasLocalStorage() && |
| 654 | isParallelOrTaskRegion(DSAStack->getCurrentDirective()))) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 655 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 656 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 657 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 658 | return true; |
| 659 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 660 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 661 | return DVarPrivate.CKind != OMPC_unknown; |
| 662 | } |
| 663 | return false; |
| 664 | } |
| 665 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 666 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 667 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 668 | return DSAStack->hasExplicitDSA( |
| 669 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 670 | } |
| 671 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 672 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 673 | |
| 674 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 675 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 676 | Scope *CurScope, SourceLocation Loc) { |
| 677 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 678 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 679 | } |
| 680 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 681 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 682 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 683 | } |
| 684 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 685 | void Sema::EndOpenMPClause() { |
| 686 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 689 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 690 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 691 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 692 | // clause requires an accessible, unambiguous default constructor for the |
| 693 | // class type, unless the list item is also specified in a firstprivate |
| 694 | // clause. |
| 695 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 696 | for (auto *C : D->clauses()) { |
| 697 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 698 | SmallVector<Expr *, 8> PrivateCopies; |
| 699 | for (auto *DE : Clause->varlists()) { |
| 700 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 701 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 702 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 703 | } |
| 704 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 705 | QualType Type = VD->getType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 706 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 707 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 708 | // Generate helper private variable and initialize it with the |
| 709 | // default value. The address of the original variable is replaced |
| 710 | // by the address of the new private variable in CodeGen. This new |
| 711 | // variable is not added to IdResolver, so the code in the OpenMP |
| 712 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 713 | auto *VDPrivate = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 714 | buildVarDecl(*this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 715 | VD->getName()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 716 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 717 | if (VDPrivate->isInvalidDecl()) |
| 718 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 719 | PrivateCopies.push_back(buildDeclRefExpr( |
| 720 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 721 | } else { |
| 722 | // The variable is also a firstprivate, so initialization sequence |
| 723 | // for private copy is generated already. |
| 724 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 725 | } |
| 726 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 727 | // Set initializers to private copies if no errors were found. |
| 728 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 729 | Clause->setPrivateCopies(PrivateCopies); |
| 730 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | } |
| 734 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 735 | DSAStack->pop(); |
| 736 | DiscardCleanupsInEvaluationContext(); |
| 737 | PopExpressionEvaluationContext(); |
| 738 | } |
| 739 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 740 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 741 | Expr *NumIterations, Sema &SemaRef, |
| 742 | Scope *S); |
| 743 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 744 | namespace { |
| 745 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 746 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 747 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 748 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 749 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 750 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 751 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 752 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 753 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 754 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 755 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 756 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 757 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 758 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 759 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 760 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 761 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 762 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 763 | |
| 764 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 765 | CXXScopeSpec &ScopeSpec, |
| 766 | const DeclarationNameInfo &Id) { |
| 767 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 768 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 769 | |
| 770 | if (Lookup.isAmbiguous()) |
| 771 | return ExprError(); |
| 772 | |
| 773 | VarDecl *VD; |
| 774 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 775 | if (TypoCorrection Corrected = CorrectTypo( |
| 776 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 777 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 778 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 779 | PDiag(Lookup.empty() |
| 780 | ? diag::err_undeclared_var_use_suggest |
| 781 | : diag::err_omp_expected_var_arg_suggest) |
| 782 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 783 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 784 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 785 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 786 | : diag::err_omp_expected_var_arg) |
| 787 | << Id.getName(); |
| 788 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 789 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 790 | } else { |
| 791 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 792 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 793 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 794 | return ExprError(); |
| 795 | } |
| 796 | } |
| 797 | Lookup.suppressDiagnostics(); |
| 798 | |
| 799 | // OpenMP [2.9.2, Syntax, C/C++] |
| 800 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 801 | if (!VD->hasGlobalStorage()) { |
| 802 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 803 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 804 | bool IsDecl = |
| 805 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 806 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 807 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 808 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 809 | return ExprError(); |
| 810 | } |
| 811 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 812 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 813 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 814 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 815 | // A threadprivate directive for file-scope variables must appear outside |
| 816 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 817 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 818 | !getCurLexicalContext()->isTranslationUnit()) { |
| 819 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 820 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 821 | bool IsDecl = |
| 822 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 823 | Diag(VD->getLocation(), |
| 824 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 825 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 826 | return ExprError(); |
| 827 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 828 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 829 | // A threadprivate directive for static class member variables must appear |
| 830 | // in the class definition, in the same scope in which the member |
| 831 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 832 | if (CanonicalVD->isStaticDataMember() && |
| 833 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 834 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 835 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 836 | bool IsDecl = |
| 837 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 838 | Diag(VD->getLocation(), |
| 839 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 840 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 841 | return ExprError(); |
| 842 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 843 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 844 | // A threadprivate directive for namespace-scope variables must appear |
| 845 | // outside any definition or declaration other than the namespace |
| 846 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 847 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 848 | (!getCurLexicalContext()->isFileContext() || |
| 849 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 850 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 851 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 852 | bool IsDecl = |
| 853 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 854 | Diag(VD->getLocation(), |
| 855 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 856 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 857 | return ExprError(); |
| 858 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 859 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 860 | // A threadprivate directive for static block-scope variables must appear |
| 861 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 862 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 863 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 864 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 865 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 866 | bool IsDecl = |
| 867 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 868 | Diag(VD->getLocation(), |
| 869 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 870 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 871 | return ExprError(); |
| 872 | } |
| 873 | |
| 874 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 875 | // A threadprivate directive must lexically precede all references to any |
| 876 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 877 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 878 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 879 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 880 | return ExprError(); |
| 881 | } |
| 882 | |
| 883 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 884 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 885 | return DE; |
| 886 | } |
| 887 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 888 | Sema::DeclGroupPtrTy |
| 889 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 890 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 891 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 892 | CurContext->addDecl(D); |
| 893 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 894 | } |
| 895 | return DeclGroupPtrTy(); |
| 896 | } |
| 897 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 898 | namespace { |
| 899 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 900 | Sema &SemaRef; |
| 901 | |
| 902 | public: |
| 903 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 904 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 905 | if (VD->hasLocalStorage()) { |
| 906 | SemaRef.Diag(E->getLocStart(), |
| 907 | diag::err_omp_local_var_in_threadprivate_init) |
| 908 | << E->getSourceRange(); |
| 909 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 910 | << VD << VD->getSourceRange(); |
| 911 | return true; |
| 912 | } |
| 913 | } |
| 914 | return false; |
| 915 | } |
| 916 | bool VisitStmt(const Stmt *S) { |
| 917 | for (auto Child : S->children()) { |
| 918 | if (Child && Visit(Child)) |
| 919 | return true; |
| 920 | } |
| 921 | return false; |
| 922 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 923 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 924 | }; |
| 925 | } // namespace |
| 926 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 927 | OMPThreadPrivateDecl * |
| 928 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 929 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 930 | for (auto &RefExpr : VarList) { |
| 931 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 932 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 933 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 934 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 935 | QualType QType = VD->getType(); |
| 936 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 937 | // It will be analyzed later. |
| 938 | Vars.push_back(DE); |
| 939 | continue; |
| 940 | } |
| 941 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 942 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 943 | // A threadprivate variable must not have an incomplete type. |
| 944 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 945 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 946 | continue; |
| 947 | } |
| 948 | |
| 949 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 950 | // A threadprivate variable must not have a reference type. |
| 951 | if (VD->getType()->isReferenceType()) { |
| 952 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 953 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 954 | bool IsDecl = |
| 955 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 956 | Diag(VD->getLocation(), |
| 957 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 958 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 959 | continue; |
| 960 | } |
| 961 | |
Richard Smith | fd3834f | 2013-04-13 02:43:54 +0000 | [diff] [blame] | 962 | // Check if this is a TLS variable. |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 963 | if (VD->getTLSKind() != VarDecl::TLS_None || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 964 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 965 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 966 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 967 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 968 | bool IsDecl = |
| 969 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 970 | Diag(VD->getLocation(), |
| 971 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 972 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 973 | continue; |
| 974 | } |
| 975 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 976 | // Check if initial value of threadprivate variable reference variable with |
| 977 | // local storage (it is not supported by runtime). |
| 978 | if (auto Init = VD->getAnyInitializer()) { |
| 979 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 980 | if (Checker.Visit(Init)) |
| 981 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 984 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 985 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 986 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 987 | Context, SourceRange(Loc, Loc))); |
| 988 | if (auto *ML = Context.getASTMutationListener()) |
| 989 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 990 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 991 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 992 | if (!Vars.empty()) { |
| 993 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 994 | Vars); |
| 995 | D->setAccess(AS_public); |
| 996 | } |
| 997 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 998 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 999 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1000 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1001 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1002 | bool IsLoopIterVar = false) { |
| 1003 | if (DVar.RefExpr) { |
| 1004 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1005 | << getOpenMPClauseName(DVar.CKind); |
| 1006 | return; |
| 1007 | } |
| 1008 | enum { |
| 1009 | PDSA_StaticMemberShared, |
| 1010 | PDSA_StaticLocalVarShared, |
| 1011 | PDSA_LoopIterVarPrivate, |
| 1012 | PDSA_LoopIterVarLinear, |
| 1013 | PDSA_LoopIterVarLastprivate, |
| 1014 | PDSA_ConstVarShared, |
| 1015 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1016 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1017 | PDSA_LocalVarPrivate, |
| 1018 | PDSA_Implicit |
| 1019 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1020 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1021 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1022 | if (IsLoopIterVar) { |
| 1023 | if (DVar.CKind == OMPC_private) |
| 1024 | Reason = PDSA_LoopIterVarPrivate; |
| 1025 | else if (DVar.CKind == OMPC_lastprivate) |
| 1026 | Reason = PDSA_LoopIterVarLastprivate; |
| 1027 | else |
| 1028 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1029 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1030 | Reason = PDSA_TaskVarFirstprivate; |
| 1031 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1032 | } else if (VD->isStaticLocal()) |
| 1033 | Reason = PDSA_StaticLocalVarShared; |
| 1034 | else if (VD->isStaticDataMember()) |
| 1035 | Reason = PDSA_StaticMemberShared; |
| 1036 | else if (VD->isFileVarDecl()) |
| 1037 | Reason = PDSA_GlobalVarShared; |
| 1038 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1039 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1040 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1041 | ReportHint = true; |
| 1042 | Reason = PDSA_LocalVarPrivate; |
| 1043 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1044 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1045 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1046 | << Reason << ReportHint |
| 1047 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1048 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1049 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1050 | << getOpenMPClauseName(DVar.CKind); |
| 1051 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1054 | namespace { |
| 1055 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1056 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1057 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1058 | bool ErrorFound; |
| 1059 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1060 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1061 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1062 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1063 | public: |
| 1064 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1065 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1066 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1067 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1068 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1069 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1070 | auto DVar = Stack->getTopDSA(VD, false); |
| 1071 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1072 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1073 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1074 | auto ELoc = E->getExprLoc(); |
| 1075 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1076 | // The default(none) clause requires that each variable that is referenced |
| 1077 | // in the construct, and does not have a predetermined data-sharing |
| 1078 | // attribute, must have its data-sharing attribute explicitly determined |
| 1079 | // by being listed in a data-sharing attribute clause. |
| 1080 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1081 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1082 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1083 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1084 | return; |
| 1085 | } |
| 1086 | |
| 1087 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1088 | // A list item that appears in a reduction clause of the innermost |
| 1089 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1090 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1091 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1092 | [](OpenMPDirectiveKind K) -> bool { |
| 1093 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1094 | isOpenMPWorksharingDirective(K) || |
| 1095 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1096 | }, |
| 1097 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1098 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1099 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1100 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1101 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1102 | return; |
| 1103 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1104 | |
| 1105 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1106 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1107 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1108 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1112 | for (auto *C : S->clauses()) { |
| 1113 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1114 | // for task directives. |
| 1115 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1116 | for (auto *CC : C->children()) { |
| 1117 | if (CC) |
| 1118 | Visit(CC); |
| 1119 | } |
| 1120 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1121 | } |
| 1122 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1123 | for (auto *C : S->children()) { |
| 1124 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1125 | Visit(C); |
| 1126 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1127 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1128 | |
| 1129 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1130 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1131 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1132 | return VarsWithInheritedDSA; |
| 1133 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1134 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1135 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1136 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1137 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1138 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1139 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1140 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1141 | switch (DKind) { |
| 1142 | case OMPD_parallel: { |
| 1143 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1144 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1145 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1146 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1147 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1148 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1149 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1150 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1151 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1152 | break; |
| 1153 | } |
| 1154 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1155 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1156 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1157 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1158 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1159 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1160 | break; |
| 1161 | } |
| 1162 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1163 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1164 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1165 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1166 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1167 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1168 | break; |
| 1169 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1170 | case OMPD_for_simd: { |
| 1171 | Sema::CapturedParamNameType Params[] = { |
| 1172 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1173 | }; |
| 1174 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1175 | Params); |
| 1176 | break; |
| 1177 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1178 | case OMPD_sections: { |
| 1179 | Sema::CapturedParamNameType Params[] = { |
| 1180 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1181 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1182 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1183 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1184 | break; |
| 1185 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1186 | case OMPD_section: { |
| 1187 | Sema::CapturedParamNameType Params[] = { |
| 1188 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1189 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1190 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1191 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1192 | break; |
| 1193 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1194 | case OMPD_single: { |
| 1195 | Sema::CapturedParamNameType Params[] = { |
| 1196 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1197 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1198 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1199 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1200 | break; |
| 1201 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1202 | case OMPD_master: { |
| 1203 | Sema::CapturedParamNameType Params[] = { |
| 1204 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1205 | }; |
| 1206 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1207 | Params); |
| 1208 | break; |
| 1209 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1210 | case OMPD_critical: { |
| 1211 | Sema::CapturedParamNameType Params[] = { |
| 1212 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1213 | }; |
| 1214 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1215 | Params); |
| 1216 | break; |
| 1217 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1218 | case OMPD_parallel_for: { |
| 1219 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1220 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1221 | Sema::CapturedParamNameType Params[] = { |
| 1222 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1223 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1224 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1225 | }; |
| 1226 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1227 | Params); |
| 1228 | break; |
| 1229 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1230 | case OMPD_parallel_for_simd: { |
| 1231 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1232 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1233 | Sema::CapturedParamNameType Params[] = { |
| 1234 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1235 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1236 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1237 | }; |
| 1238 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1239 | Params); |
| 1240 | break; |
| 1241 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1242 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1243 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1244 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1245 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1246 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1247 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1248 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1249 | }; |
| 1250 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1251 | Params); |
| 1252 | break; |
| 1253 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1254 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1255 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1256 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1257 | FunctionProtoType::ExtProtoInfo EPI; |
| 1258 | EPI.Variadic = true; |
| 1259 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1260 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1261 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1262 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1263 | std::make_pair(".privates.", |
| 1264 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1265 | std::make_pair( |
| 1266 | ".copy_fn.", |
| 1267 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1268 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1269 | }; |
| 1270 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1271 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1272 | // Mark this captured region as inlined, because we don't use outlined |
| 1273 | // function directly. |
| 1274 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1275 | AlwaysInlineAttr::CreateImplicit( |
| 1276 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1277 | break; |
| 1278 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1279 | case OMPD_ordered: { |
| 1280 | Sema::CapturedParamNameType Params[] = { |
| 1281 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1282 | }; |
| 1283 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1284 | Params); |
| 1285 | break; |
| 1286 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1287 | case OMPD_atomic: { |
| 1288 | Sema::CapturedParamNameType Params[] = { |
| 1289 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1290 | }; |
| 1291 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1292 | Params); |
| 1293 | break; |
| 1294 | } |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1295 | case OMPD_target: { |
| 1296 | Sema::CapturedParamNameType Params[] = { |
| 1297 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1298 | }; |
| 1299 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1300 | Params); |
| 1301 | break; |
| 1302 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1303 | case OMPD_teams: { |
| 1304 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1305 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1306 | Sema::CapturedParamNameType Params[] = { |
| 1307 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1308 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1309 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1310 | }; |
| 1311 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1312 | Params); |
| 1313 | break; |
| 1314 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1315 | case OMPD_taskgroup: { |
| 1316 | Sema::CapturedParamNameType Params[] = { |
| 1317 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1318 | }; |
| 1319 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1320 | Params); |
| 1321 | break; |
| 1322 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1323 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1324 | case OMPD_taskyield: |
| 1325 | case OMPD_barrier: |
| 1326 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1327 | case OMPD_cancellation_point: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1328 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1329 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1330 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1331 | llvm_unreachable("Unknown OpenMP directive"); |
| 1332 | } |
| 1333 | } |
| 1334 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1335 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1336 | ArrayRef<OMPClause *> Clauses) { |
| 1337 | if (!S.isUsable()) { |
| 1338 | ActOnCapturedRegionError(); |
| 1339 | return StmtError(); |
| 1340 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1341 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1342 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1343 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
| 1344 | Clause->getClauseKind() == OMPC_copyprivate) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1345 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1346 | for (auto *VarRef : Clause->children()) { |
| 1347 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1348 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1349 | } |
| 1350 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1351 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1352 | Clause->getClauseKind() == OMPC_schedule) { |
| 1353 | // Mark all variables in private list clauses as used in inner region. |
| 1354 | // Required for proper codegen of combined directives. |
| 1355 | // TODO: add processing for other clauses. |
| 1356 | if (auto *E = cast_or_null<Expr>( |
| 1357 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1358 | MarkDeclarationsReferencedInExpr(E); |
| 1359 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1360 | } |
| 1361 | } |
| 1362 | return ActOnCapturedRegionEnd(S.get()); |
| 1363 | } |
| 1364 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1365 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1366 | OpenMPDirectiveKind CurrentRegion, |
| 1367 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1368 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1369 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1370 | // Allowed nesting of constructs |
| 1371 | // +------------------+-----------------+------------------------------------+ |
| 1372 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1373 | // +------------------+-----------------+------------------------------------+ |
| 1374 | // | parallel | parallel | * | |
| 1375 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1376 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1377 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1378 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1379 | // | parallel | simd | * | |
| 1380 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1381 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1382 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1383 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1384 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1385 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1386 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1387 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1388 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1389 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1390 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1391 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1392 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1393 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1394 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1395 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1396 | // | parallel | cancellation | | |
| 1397 | // | | point | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1398 | // +------------------+-----------------+------------------------------------+ |
| 1399 | // | for | parallel | * | |
| 1400 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1401 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1402 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1403 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1404 | // | for | simd | * | |
| 1405 | // | for | sections | + | |
| 1406 | // | for | section | + | |
| 1407 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1408 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1409 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1410 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1411 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1412 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1413 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1414 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1415 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1416 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1417 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1418 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1419 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1420 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1421 | // | for | cancellation | | |
| 1422 | // | | point | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1423 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1424 | // | master | parallel | * | |
| 1425 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1426 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1427 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1428 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1429 | // | master | simd | * | |
| 1430 | // | master | sections | + | |
| 1431 | // | master | section | + | |
| 1432 | // | master | single | + | |
| 1433 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1434 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1435 | // | master |parallel sections| * | |
| 1436 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1437 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1438 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1439 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1440 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1441 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1442 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1443 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1444 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1445 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1446 | // | master | cancellation | | |
| 1447 | // | | point | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1448 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1449 | // | critical | parallel | * | |
| 1450 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1451 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1452 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1453 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1454 | // | critical | simd | * | |
| 1455 | // | critical | sections | + | |
| 1456 | // | critical | section | + | |
| 1457 | // | critical | single | + | |
| 1458 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1459 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1460 | // | critical |parallel sections| * | |
| 1461 | // | critical | task | * | |
| 1462 | // | critical | taskyield | * | |
| 1463 | // | critical | barrier | + | |
| 1464 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1465 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1466 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1467 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1468 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1469 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1470 | // | critical | cancellation | | |
| 1471 | // | | point | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1472 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1473 | // | simd | parallel | | |
| 1474 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1475 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1476 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1477 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1478 | // | simd | simd | | |
| 1479 | // | simd | sections | | |
| 1480 | // | simd | section | | |
| 1481 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1482 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1483 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1484 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1485 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1486 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1487 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1488 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1489 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1490 | // | simd | flush | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1491 | // | simd | ordered | | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1492 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1493 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1494 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1495 | // | simd | cancellation | | |
| 1496 | // | | point | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1497 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1498 | // | for simd | parallel | | |
| 1499 | // | for simd | for | | |
| 1500 | // | for simd | for simd | | |
| 1501 | // | for simd | master | | |
| 1502 | // | for simd | critical | | |
| 1503 | // | for simd | simd | | |
| 1504 | // | for simd | sections | | |
| 1505 | // | for simd | section | | |
| 1506 | // | for simd | single | | |
| 1507 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1508 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1509 | // | for simd |parallel sections| | |
| 1510 | // | for simd | task | | |
| 1511 | // | for simd | taskyield | | |
| 1512 | // | for simd | barrier | | |
| 1513 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1514 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1515 | // | for simd | flush | | |
| 1516 | // | for simd | ordered | | |
| 1517 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1518 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1519 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1520 | // | for simd | cancellation | | |
| 1521 | // | | point | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1522 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1523 | // | parallel for simd| parallel | | |
| 1524 | // | parallel for simd| for | | |
| 1525 | // | parallel for simd| for simd | | |
| 1526 | // | parallel for simd| master | | |
| 1527 | // | parallel for simd| critical | | |
| 1528 | // | parallel for simd| simd | | |
| 1529 | // | parallel for simd| sections | | |
| 1530 | // | parallel for simd| section | | |
| 1531 | // | parallel for simd| single | | |
| 1532 | // | parallel for simd| parallel for | | |
| 1533 | // | parallel for simd|parallel for simd| | |
| 1534 | // | parallel for simd|parallel sections| | |
| 1535 | // | parallel for simd| task | | |
| 1536 | // | parallel for simd| taskyield | | |
| 1537 | // | parallel for simd| barrier | | |
| 1538 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1539 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1540 | // | parallel for simd| flush | | |
| 1541 | // | parallel for simd| ordered | | |
| 1542 | // | parallel for simd| atomic | | |
| 1543 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1544 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1545 | // | parallel for simd| cancellation | | |
| 1546 | // | | point | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1547 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1548 | // | sections | parallel | * | |
| 1549 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1550 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1551 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1552 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1553 | // | sections | simd | * | |
| 1554 | // | sections | sections | + | |
| 1555 | // | sections | section | * | |
| 1556 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1557 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1558 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1559 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1560 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1561 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1562 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1563 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1564 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1565 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1566 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1567 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1568 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1569 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1570 | // | sections | cancellation | | |
| 1571 | // | | point | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1572 | // +------------------+-----------------+------------------------------------+ |
| 1573 | // | section | parallel | * | |
| 1574 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1575 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1576 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1577 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1578 | // | section | simd | * | |
| 1579 | // | section | sections | + | |
| 1580 | // | section | section | + | |
| 1581 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1582 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1583 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1584 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1585 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1586 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1587 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1588 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1589 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1590 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1591 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1592 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1593 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1594 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1595 | // | section | cancellation | | |
| 1596 | // | | point | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1597 | // +------------------+-----------------+------------------------------------+ |
| 1598 | // | single | parallel | * | |
| 1599 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1600 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1601 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1602 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1603 | // | single | simd | * | |
| 1604 | // | single | sections | + | |
| 1605 | // | single | section | + | |
| 1606 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1607 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1608 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1609 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1610 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1611 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1612 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1613 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1614 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1615 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1616 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1617 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1618 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1619 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1620 | // | single | cancellation | | |
| 1621 | // | | point | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1622 | // +------------------+-----------------+------------------------------------+ |
| 1623 | // | parallel for | parallel | * | |
| 1624 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1625 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1626 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1627 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1628 | // | parallel for | simd | * | |
| 1629 | // | parallel for | sections | + | |
| 1630 | // | parallel for | section | + | |
| 1631 | // | parallel for | single | + | |
| 1632 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1633 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1634 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1635 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1636 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1637 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1638 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1639 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1640 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1641 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1642 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1643 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1644 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1645 | // | parallel for | cancellation | | |
| 1646 | // | | point | ! | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1647 | // +------------------+-----------------+------------------------------------+ |
| 1648 | // | parallel sections| parallel | * | |
| 1649 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1650 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1651 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1652 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1653 | // | parallel sections| simd | * | |
| 1654 | // | parallel sections| sections | + | |
| 1655 | // | parallel sections| section | * | |
| 1656 | // | parallel sections| single | + | |
| 1657 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1658 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1659 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1660 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1661 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1662 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1663 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1664 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1665 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1666 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1667 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1668 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1669 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1670 | // | parallel sections| cancellation | | |
| 1671 | // | | point | ! | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1672 | // +------------------+-----------------+------------------------------------+ |
| 1673 | // | task | parallel | * | |
| 1674 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1675 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1676 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1677 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1678 | // | task | simd | * | |
| 1679 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1680 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1681 | // | task | single | + | |
| 1682 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1683 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1684 | // | task |parallel sections| * | |
| 1685 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1686 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1687 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1688 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1689 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1690 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1691 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1692 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1693 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1694 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1695 | // | task | cancellation | | |
| 1696 | // | | point | ! | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1697 | // +------------------+-----------------+------------------------------------+ |
| 1698 | // | ordered | parallel | * | |
| 1699 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1700 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1701 | // | ordered | master | * | |
| 1702 | // | ordered | critical | * | |
| 1703 | // | ordered | simd | * | |
| 1704 | // | ordered | sections | + | |
| 1705 | // | ordered | section | + | |
| 1706 | // | ordered | single | + | |
| 1707 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1708 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1709 | // | ordered |parallel sections| * | |
| 1710 | // | ordered | task | * | |
| 1711 | // | ordered | taskyield | * | |
| 1712 | // | ordered | barrier | + | |
| 1713 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1714 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1715 | // | ordered | flush | * | |
| 1716 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1717 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1718 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1719 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1720 | // | ordered | cancellation | | |
| 1721 | // | | point | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1722 | // +------------------+-----------------+------------------------------------+ |
| 1723 | // | atomic | parallel | | |
| 1724 | // | atomic | for | | |
| 1725 | // | atomic | for simd | | |
| 1726 | // | atomic | master | | |
| 1727 | // | atomic | critical | | |
| 1728 | // | atomic | simd | | |
| 1729 | // | atomic | sections | | |
| 1730 | // | atomic | section | | |
| 1731 | // | atomic | single | | |
| 1732 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1733 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1734 | // | atomic |parallel sections| | |
| 1735 | // | atomic | task | | |
| 1736 | // | atomic | taskyield | | |
| 1737 | // | atomic | barrier | | |
| 1738 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1739 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1740 | // | atomic | flush | | |
| 1741 | // | atomic | ordered | | |
| 1742 | // | atomic | atomic | | |
| 1743 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1744 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1745 | // | atomic | cancellation | | |
| 1746 | // | | point | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1747 | // +------------------+-----------------+------------------------------------+ |
| 1748 | // | target | parallel | * | |
| 1749 | // | target | for | * | |
| 1750 | // | target | for simd | * | |
| 1751 | // | target | master | * | |
| 1752 | // | target | critical | * | |
| 1753 | // | target | simd | * | |
| 1754 | // | target | sections | * | |
| 1755 | // | target | section | * | |
| 1756 | // | target | single | * | |
| 1757 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1758 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1759 | // | target |parallel sections| * | |
| 1760 | // | target | task | * | |
| 1761 | // | target | taskyield | * | |
| 1762 | // | target | barrier | * | |
| 1763 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1764 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1765 | // | target | flush | * | |
| 1766 | // | target | ordered | * | |
| 1767 | // | target | atomic | * | |
| 1768 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1769 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1770 | // | target | cancellation | | |
| 1771 | // | | point | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1772 | // +------------------+-----------------+------------------------------------+ |
| 1773 | // | teams | parallel | * | |
| 1774 | // | teams | for | + | |
| 1775 | // | teams | for simd | + | |
| 1776 | // | teams | master | + | |
| 1777 | // | teams | critical | + | |
| 1778 | // | teams | simd | + | |
| 1779 | // | teams | sections | + | |
| 1780 | // | teams | section | + | |
| 1781 | // | teams | single | + | |
| 1782 | // | teams | parallel for | * | |
| 1783 | // | teams |parallel for simd| * | |
| 1784 | // | teams |parallel sections| * | |
| 1785 | // | teams | task | + | |
| 1786 | // | teams | taskyield | + | |
| 1787 | // | teams | barrier | + | |
| 1788 | // | teams | taskwait | + | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1789 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1790 | // | teams | flush | + | |
| 1791 | // | teams | ordered | + | |
| 1792 | // | teams | atomic | + | |
| 1793 | // | teams | target | + | |
| 1794 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1795 | // | teams | cancellation | | |
| 1796 | // | | point | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1797 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1798 | if (Stack->getCurScope()) { |
| 1799 | auto ParentRegion = Stack->getParentDirective(); |
| 1800 | bool NestingProhibited = false; |
| 1801 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1802 | enum { |
| 1803 | NoRecommend, |
| 1804 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1805 | ShouldBeInOrderedRegion, |
| 1806 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1807 | } Recommend = NoRecommend; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1808 | if (isOpenMPSimdDirective(ParentRegion)) { |
| 1809 | // OpenMP [2.16, Nesting of Regions] |
| 1810 | // OpenMP constructs may not be nested inside a simd region. |
| 1811 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1812 | return true; |
| 1813 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1814 | if (ParentRegion == OMPD_atomic) { |
| 1815 | // OpenMP [2.16, Nesting of Regions] |
| 1816 | // OpenMP constructs may not be nested inside an atomic region. |
| 1817 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1818 | return true; |
| 1819 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1820 | if (CurrentRegion == OMPD_section) { |
| 1821 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1822 | // Orphaned section directives are prohibited. That is, the section |
| 1823 | // directives must appear within the sections construct and must not be |
| 1824 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1825 | if (ParentRegion != OMPD_sections && |
| 1826 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1827 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1828 | << (ParentRegion != OMPD_unknown) |
| 1829 | << getOpenMPDirectiveName(ParentRegion); |
| 1830 | return true; |
| 1831 | } |
| 1832 | return false; |
| 1833 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1834 | // Allow some constructs to be orphaned (they could be used in functions, |
| 1835 | // called from OpenMP regions with the required preconditions). |
| 1836 | if (ParentRegion == OMPD_unknown) |
| 1837 | return false; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1838 | if (CurrentRegion == OMPD_cancellation_point) { |
| 1839 | // OpenMP [2.16, Nesting of Regions] |
| 1840 | // A cancellation point construct for which construct-type-clause is |
| 1841 | // taskgroup must be nested inside a task construct. A cancellation |
| 1842 | // point construct for which construct-type-clause is not taskgroup must |
| 1843 | // be closely nested inside an OpenMP construct that matches the type |
| 1844 | // specified in construct-type-clause. |
| 1845 | NestingProhibited = |
| 1846 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
| 1847 | (CancelRegion == OMPD_for && ParentRegion == OMPD_for) || |
| 1848 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 1849 | (CancelRegion == OMPD_sections && |
| 1850 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections))); |
| 1851 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1852 | // OpenMP [2.16, Nesting of Regions] |
| 1853 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1854 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1855 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 1856 | ParentRegion == OMPD_task; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1857 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 1858 | // OpenMP [2.16, Nesting of Regions] |
| 1859 | // A critical region may not be nested (closely or otherwise) inside a |
| 1860 | // critical region with the same name. Note that this restriction is not |
| 1861 | // sufficient to prevent deadlock. |
| 1862 | SourceLocation PreviousCriticalLoc; |
| 1863 | bool DeadLock = |
| 1864 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 1865 | OpenMPDirectiveKind K, |
| 1866 | const DeclarationNameInfo &DNI, |
| 1867 | SourceLocation Loc) |
| 1868 | ->bool { |
| 1869 | if (K == OMPD_critical && |
| 1870 | DNI.getName() == CurrentName.getName()) { |
| 1871 | PreviousCriticalLoc = Loc; |
| 1872 | return true; |
| 1873 | } else |
| 1874 | return false; |
| 1875 | }, |
| 1876 | false /* skip top directive */); |
| 1877 | if (DeadLock) { |
| 1878 | SemaRef.Diag(StartLoc, |
| 1879 | diag::err_omp_prohibited_region_critical_same_name) |
| 1880 | << CurrentName.getName(); |
| 1881 | if (PreviousCriticalLoc.isValid()) |
| 1882 | SemaRef.Diag(PreviousCriticalLoc, |
| 1883 | diag::note_omp_previous_critical_region); |
| 1884 | return true; |
| 1885 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1886 | } else if (CurrentRegion == OMPD_barrier) { |
| 1887 | // OpenMP [2.16, Nesting of Regions] |
| 1888 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1889 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1890 | NestingProhibited = |
| 1891 | isOpenMPWorksharingDirective(ParentRegion) || |
| 1892 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1893 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1894 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1895 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1896 | // OpenMP [2.16, Nesting of Regions] |
| 1897 | // A worksharing region may not be closely nested inside a worksharing, |
| 1898 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1899 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1900 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1901 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1902 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
| 1903 | Recommend = ShouldBeInParallelRegion; |
| 1904 | } else if (CurrentRegion == OMPD_ordered) { |
| 1905 | // OpenMP [2.16, Nesting of Regions] |
| 1906 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1907 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1908 | // An ordered region must be closely nested inside a loop region (or |
| 1909 | // parallel loop region) with an ordered clause. |
| 1910 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1911 | ParentRegion == OMPD_task || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1912 | !Stack->isParentOrderedRegion(); |
| 1913 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1914 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 1915 | // OpenMP [2.16, Nesting of Regions] |
| 1916 | // If specified, a teams construct must be contained within a target |
| 1917 | // construct. |
| 1918 | NestingProhibited = ParentRegion != OMPD_target; |
| 1919 | Recommend = ShouldBeInTargetRegion; |
| 1920 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 1921 | } |
| 1922 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 1923 | // OpenMP [2.16, Nesting of Regions] |
| 1924 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 1925 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 1926 | // constructs that can be closely nested in the teams region. |
| 1927 | // TODO: add distribute directive. |
| 1928 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 1929 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1930 | } |
| 1931 | if (NestingProhibited) { |
| 1932 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1933 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 1934 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1935 | return true; |
| 1936 | } |
| 1937 | } |
| 1938 | return false; |
| 1939 | } |
| 1940 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1941 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 1942 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 1943 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 1944 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1945 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 1946 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 1947 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1948 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1949 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1950 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1951 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1952 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1953 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1954 | if (AStmt) { |
| 1955 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 1956 | |
| 1957 | // Check default data sharing attributes for referenced variables. |
| 1958 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 1959 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 1960 | if (DSAChecker.isErrorFound()) |
| 1961 | return StmtError(); |
| 1962 | // Generate list of implicitly defined firstprivate variables. |
| 1963 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1964 | |
| 1965 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 1966 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 1967 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 1968 | SourceLocation(), SourceLocation())) { |
| 1969 | ClausesWithImplicit.push_back(Implicit); |
| 1970 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 1971 | DSAChecker.getImplicitFirstprivate().size(); |
| 1972 | } else |
| 1973 | ErrorFound = true; |
| 1974 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1975 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1976 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1977 | switch (Kind) { |
| 1978 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1979 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1980 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1981 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1982 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1983 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 1984 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1985 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1986 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1987 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 1988 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1989 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1990 | case OMPD_for_simd: |
| 1991 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1992 | EndLoc, VarsWithInheritedDSA); |
| 1993 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1994 | case OMPD_sections: |
| 1995 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 1996 | EndLoc); |
| 1997 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1998 | case OMPD_section: |
| 1999 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2000 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2001 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2002 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2003 | case OMPD_single: |
| 2004 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2005 | EndLoc); |
| 2006 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2007 | case OMPD_master: |
| 2008 | assert(ClausesWithImplicit.empty() && |
| 2009 | "No clauses are allowed for 'omp master' directive"); |
| 2010 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2011 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2012 | case OMPD_critical: |
| 2013 | assert(ClausesWithImplicit.empty() && |
| 2014 | "No clauses are allowed for 'omp critical' directive"); |
| 2015 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2016 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2017 | case OMPD_parallel_for: |
| 2018 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2019 | EndLoc, VarsWithInheritedDSA); |
| 2020 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2021 | case OMPD_parallel_for_simd: |
| 2022 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2023 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2024 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2025 | case OMPD_parallel_sections: |
| 2026 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2027 | StartLoc, EndLoc); |
| 2028 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2029 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2030 | Res = |
| 2031 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2032 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2033 | case OMPD_taskyield: |
| 2034 | assert(ClausesWithImplicit.empty() && |
| 2035 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2036 | assert(AStmt == nullptr && |
| 2037 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2038 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2039 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2040 | case OMPD_barrier: |
| 2041 | assert(ClausesWithImplicit.empty() && |
| 2042 | "No clauses are allowed for 'omp barrier' directive"); |
| 2043 | assert(AStmt == nullptr && |
| 2044 | "No associated statement allowed for 'omp barrier' directive"); |
| 2045 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2046 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2047 | case OMPD_taskwait: |
| 2048 | assert(ClausesWithImplicit.empty() && |
| 2049 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2050 | assert(AStmt == nullptr && |
| 2051 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2052 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2053 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2054 | case OMPD_taskgroup: |
| 2055 | assert(ClausesWithImplicit.empty() && |
| 2056 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2057 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2058 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2059 | case OMPD_flush: |
| 2060 | assert(AStmt == nullptr && |
| 2061 | "No associated statement allowed for 'omp flush' directive"); |
| 2062 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2063 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2064 | case OMPD_ordered: |
| 2065 | assert(ClausesWithImplicit.empty() && |
| 2066 | "No clauses are allowed for 'omp ordered' directive"); |
| 2067 | Res = ActOnOpenMPOrderedDirective(AStmt, StartLoc, EndLoc); |
| 2068 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2069 | case OMPD_atomic: |
| 2070 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2071 | EndLoc); |
| 2072 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2073 | case OMPD_teams: |
| 2074 | Res = |
| 2075 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2076 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2077 | case OMPD_target: |
| 2078 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2079 | EndLoc); |
| 2080 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 2081 | case OMPD_cancellation_point: |
| 2082 | assert(ClausesWithImplicit.empty() && |
| 2083 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2084 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2085 | "cancellation point' directive"); |
| 2086 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2087 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2088 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2089 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2090 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2091 | llvm_unreachable("Unknown OpenMP directive"); |
| 2092 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2093 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2094 | for (auto P : VarsWithInheritedDSA) { |
| 2095 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2096 | << P.first << P.second->getSourceRange(); |
| 2097 | } |
| 2098 | if (!VarsWithInheritedDSA.empty()) |
| 2099 | return StmtError(); |
| 2100 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2101 | if (ErrorFound) |
| 2102 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2103 | return Res; |
| 2104 | } |
| 2105 | |
| 2106 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2107 | Stmt *AStmt, |
| 2108 | SourceLocation StartLoc, |
| 2109 | SourceLocation EndLoc) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2110 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2111 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2112 | // 1.2.2 OpenMP Language Terminology |
| 2113 | // Structured block - An executable statement with a single entry at the |
| 2114 | // top and a single exit at the bottom. |
| 2115 | // The point of exit cannot be a branch out of the structured block. |
| 2116 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2117 | CS->getCapturedDecl()->setNothrow(); |
| 2118 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2119 | getCurFunction()->setHasBranchProtectedScope(); |
| 2120 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2121 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 2122 | AStmt); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2125 | namespace { |
| 2126 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2127 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2128 | /// for IR generation. |
| 2129 | class OpenMPIterationSpaceChecker { |
| 2130 | /// \brief Reference to Sema. |
| 2131 | Sema &SemaRef; |
| 2132 | /// \brief A location for diagnostics (when there is no some better location). |
| 2133 | SourceLocation DefaultLoc; |
| 2134 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2135 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2136 | /// \brief A source location for referring to loop init later. |
| 2137 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2138 | /// \brief A source location for referring to condition later. |
| 2139 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2140 | /// \brief A source location for referring to increment later. |
| 2141 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2142 | /// \brief Loop variable. |
| 2143 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2144 | /// \brief Reference to loop variable. |
| 2145 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2146 | /// \brief Lower bound (initializer for the var). |
| 2147 | Expr *LB; |
| 2148 | /// \brief Upper bound. |
| 2149 | Expr *UB; |
| 2150 | /// \brief Loop step (increment). |
| 2151 | Expr *Step; |
| 2152 | /// \brief This flag is true when condition is one of: |
| 2153 | /// Var < UB |
| 2154 | /// Var <= UB |
| 2155 | /// UB > Var |
| 2156 | /// UB >= Var |
| 2157 | bool TestIsLessOp; |
| 2158 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2159 | bool TestIsStrictOp; |
| 2160 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2161 | bool SubtractStep; |
| 2162 | |
| 2163 | public: |
| 2164 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2165 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2166 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2167 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2168 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2169 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2170 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2171 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2172 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2173 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2174 | /// for less/greater and for strict/non-strict comparison. |
| 2175 | bool CheckCond(Expr *S); |
| 2176 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2177 | /// does not conform, otherwise save loop step (#Step). |
| 2178 | bool CheckInc(Expr *S); |
| 2179 | /// \brief Return the loop counter variable. |
| 2180 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2181 | /// \brief Return the reference expression to loop counter variable. |
| 2182 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2183 | /// \brief Source range of the loop init. |
| 2184 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2185 | /// \brief Source range of the loop condition. |
| 2186 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2187 | /// \brief Source range of the loop increment. |
| 2188 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2189 | /// \brief True if the step should be subtracted. |
| 2190 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2191 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2192 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2193 | /// \brief Build the precondition expression for the loops. |
| 2194 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2195 | /// \brief Build reference expression to the counter be used for codegen. |
| 2196 | Expr *BuildCounterVar() const; |
| 2197 | /// \brief Build initization of the counter be used for codegen. |
| 2198 | Expr *BuildCounterInit() const; |
| 2199 | /// \brief Build step of the counter be used for codegen. |
| 2200 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2201 | /// \brief Return true if any expression is dependent. |
| 2202 | bool Dependent() const; |
| 2203 | |
| 2204 | private: |
| 2205 | /// \brief Check the right-hand side of an assignment in the increment |
| 2206 | /// expression. |
| 2207 | bool CheckIncRHS(Expr *RHS); |
| 2208 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2209 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2210 | /// \brief Helper to set upper bound. |
| 2211 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR, |
| 2212 | const SourceLocation &SL); |
| 2213 | /// \brief Helper to set loop increment. |
| 2214 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2215 | }; |
| 2216 | |
| 2217 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2218 | if (!Var) { |
| 2219 | assert(!LB && !UB && !Step); |
| 2220 | return false; |
| 2221 | } |
| 2222 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2223 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2224 | } |
| 2225 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2226 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2227 | DeclRefExpr *NewVarRefExpr, |
| 2228 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2229 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2230 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2231 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2232 | if (!NewVar || !NewLB) |
| 2233 | return true; |
| 2234 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2235 | VarRef = NewVarRefExpr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2236 | LB = NewLB; |
| 2237 | return false; |
| 2238 | } |
| 2239 | |
| 2240 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| 2241 | const SourceRange &SR, |
| 2242 | const SourceLocation &SL) { |
| 2243 | // State consistency checking to ensure correct usage. |
| 2244 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2245 | !TestIsLessOp && !TestIsStrictOp); |
| 2246 | if (!NewUB) |
| 2247 | return true; |
| 2248 | UB = NewUB; |
| 2249 | TestIsLessOp = LessOp; |
| 2250 | TestIsStrictOp = StrictOp; |
| 2251 | ConditionSrcRange = SR; |
| 2252 | ConditionLoc = SL; |
| 2253 | return false; |
| 2254 | } |
| 2255 | |
| 2256 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2257 | // State consistency checking to ensure correct usage. |
| 2258 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2259 | if (!NewStep) |
| 2260 | return true; |
| 2261 | if (!NewStep->isValueDependent()) { |
| 2262 | // Check that the step is integer expression. |
| 2263 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2264 | ExprResult Val = |
| 2265 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2266 | if (Val.isInvalid()) |
| 2267 | return true; |
| 2268 | NewStep = Val.get(); |
| 2269 | |
| 2270 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2271 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2272 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2273 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2274 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2275 | // the loop. |
| 2276 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2277 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2278 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2279 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2280 | // the loop. |
| 2281 | llvm::APSInt Result; |
| 2282 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2283 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2284 | bool IsConstNeg = |
| 2285 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2286 | bool IsConstPos = |
| 2287 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2288 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2289 | if (UB && (IsConstZero || |
| 2290 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2291 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2292 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2293 | diag::err_omp_loop_incr_not_compatible) |
| 2294 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2295 | SemaRef.Diag(ConditionLoc, |
| 2296 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2297 | << TestIsLessOp << ConditionSrcRange; |
| 2298 | return true; |
| 2299 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2300 | if (TestIsLessOp == Subtract) { |
| 2301 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2302 | NewStep).get(); |
| 2303 | Subtract = !Subtract; |
| 2304 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | Step = NewStep; |
| 2308 | SubtractStep = Subtract; |
| 2309 | return false; |
| 2310 | } |
| 2311 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2312 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2313 | // Check init-expr for canonical loop form and save loop counter |
| 2314 | // variable - #Var and its initialization value - #LB. |
| 2315 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2316 | // var = lb |
| 2317 | // integer-type var = lb |
| 2318 | // random-access-iterator-type var = lb |
| 2319 | // pointer-type var = lb |
| 2320 | // |
| 2321 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2322 | if (EmitDiags) { |
| 2323 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2324 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2325 | return true; |
| 2326 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2327 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2328 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2329 | S = E->IgnoreParens(); |
| 2330 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2331 | if (BO->getOpcode() == BO_Assign) |
| 2332 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2333 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2334 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2335 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2336 | if (DS->isSingleDecl()) { |
| 2337 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
| 2338 | if (Var->hasInit()) { |
| 2339 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2340 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2341 | SemaRef.Diag(S->getLocStart(), |
| 2342 | diag::ext_omp_loop_not_canonical_init) |
| 2343 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2344 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2345 | } |
| 2346 | } |
| 2347 | } |
| 2348 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2349 | if (CE->getOperator() == OO_Equal) |
| 2350 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2351 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2352 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2353 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2354 | if (EmitDiags) { |
| 2355 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2356 | << S->getSourceRange(); |
| 2357 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2358 | return true; |
| 2359 | } |
| 2360 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2361 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2362 | /// variable (which may be the loop variable) if possible. |
| 2363 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2364 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2365 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2366 | E = E->IgnoreParenImpCasts(); |
| 2367 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2368 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
| 2369 | if (Ctor->isCopyConstructor() && CE->getNumArgs() == 1 && |
| 2370 | CE->getArg(0) != nullptr) |
| 2371 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2372 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2373 | if (!DRE) |
| 2374 | return nullptr; |
| 2375 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2376 | } |
| 2377 | |
| 2378 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2379 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2380 | // less/greater and for strict/non-strict comparison. |
| 2381 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2382 | // var relational-op b |
| 2383 | // b relational-op var |
| 2384 | // |
| 2385 | if (!S) { |
| 2386 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2387 | return true; |
| 2388 | } |
| 2389 | S = S->IgnoreParenImpCasts(); |
| 2390 | SourceLocation CondLoc = S->getLocStart(); |
| 2391 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2392 | if (BO->isRelationalOp()) { |
| 2393 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2394 | return SetUB(BO->getRHS(), |
| 2395 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2396 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2397 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2398 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2399 | return SetUB(BO->getLHS(), |
| 2400 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2401 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2402 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2403 | } |
| 2404 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2405 | if (CE->getNumArgs() == 2) { |
| 2406 | auto Op = CE->getOperator(); |
| 2407 | switch (Op) { |
| 2408 | case OO_Greater: |
| 2409 | case OO_GreaterEqual: |
| 2410 | case OO_Less: |
| 2411 | case OO_LessEqual: |
| 2412 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2413 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2414 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2415 | CE->getOperatorLoc()); |
| 2416 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2417 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2418 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2419 | CE->getOperatorLoc()); |
| 2420 | break; |
| 2421 | default: |
| 2422 | break; |
| 2423 | } |
| 2424 | } |
| 2425 | } |
| 2426 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2427 | << S->getSourceRange() << Var; |
| 2428 | return true; |
| 2429 | } |
| 2430 | |
| 2431 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2432 | // RHS of canonical loop form increment can be: |
| 2433 | // var + incr |
| 2434 | // incr + var |
| 2435 | // var - incr |
| 2436 | // |
| 2437 | RHS = RHS->IgnoreParenImpCasts(); |
| 2438 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2439 | if (BO->isAdditiveOp()) { |
| 2440 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2441 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2442 | return SetStep(BO->getRHS(), !IsAdd); |
| 2443 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2444 | return SetStep(BO->getLHS(), false); |
| 2445 | } |
| 2446 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2447 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2448 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2449 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2450 | return SetStep(CE->getArg(1), !IsAdd); |
| 2451 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2452 | return SetStep(CE->getArg(0), false); |
| 2453 | } |
| 2454 | } |
| 2455 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2456 | << RHS->getSourceRange() << Var; |
| 2457 | return true; |
| 2458 | } |
| 2459 | |
| 2460 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2461 | // Check incr-expr for canonical loop form and return true if it |
| 2462 | // does not conform. |
| 2463 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2464 | // ++var |
| 2465 | // var++ |
| 2466 | // --var |
| 2467 | // var-- |
| 2468 | // var += incr |
| 2469 | // var -= incr |
| 2470 | // var = var + incr |
| 2471 | // var = incr + var |
| 2472 | // var = var - incr |
| 2473 | // |
| 2474 | if (!S) { |
| 2475 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2476 | return true; |
| 2477 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2478 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2479 | S = S->IgnoreParens(); |
| 2480 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2481 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2482 | return SetStep( |
| 2483 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2484 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2485 | false); |
| 2486 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2487 | switch (BO->getOpcode()) { |
| 2488 | case BO_AddAssign: |
| 2489 | case BO_SubAssign: |
| 2490 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2491 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2492 | break; |
| 2493 | case BO_Assign: |
| 2494 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2495 | return CheckIncRHS(BO->getRHS()); |
| 2496 | break; |
| 2497 | default: |
| 2498 | break; |
| 2499 | } |
| 2500 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2501 | switch (CE->getOperator()) { |
| 2502 | case OO_PlusPlus: |
| 2503 | case OO_MinusMinus: |
| 2504 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2505 | return SetStep( |
| 2506 | SemaRef.ActOnIntegerConstant( |
| 2507 | CE->getLocStart(), |
| 2508 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2509 | false); |
| 2510 | break; |
| 2511 | case OO_PlusEqual: |
| 2512 | case OO_MinusEqual: |
| 2513 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2514 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2515 | break; |
| 2516 | case OO_Equal: |
| 2517 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2518 | return CheckIncRHS(CE->getArg(1)); |
| 2519 | break; |
| 2520 | default: |
| 2521 | break; |
| 2522 | } |
| 2523 | } |
| 2524 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2525 | << S->getSourceRange() << Var; |
| 2526 | return true; |
| 2527 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2528 | |
| 2529 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2530 | Expr * |
| 2531 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2532 | const bool LimitedType) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2533 | ExprResult Diff; |
| 2534 | if (Var->getType()->isIntegerType() || Var->getType()->isPointerType() || |
| 2535 | SemaRef.getLangOpts().CPlusPlus) { |
| 2536 | // Upper - Lower |
| 2537 | Expr *Upper = TestIsLessOp ? UB : LB; |
| 2538 | Expr *Lower = TestIsLessOp ? LB : UB; |
| 2539 | |
| 2540 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2541 | |
| 2542 | if (!Diff.isUsable() && Var->getType()->getAsCXXRecordDecl()) { |
| 2543 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2544 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2545 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2546 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2547 | return nullptr; |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | if (!Diff.isUsable()) |
| 2552 | return nullptr; |
| 2553 | |
| 2554 | // Upper - Lower [- 1] |
| 2555 | if (TestIsStrictOp) |
| 2556 | Diff = SemaRef.BuildBinOp( |
| 2557 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2558 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2559 | if (!Diff.isUsable()) |
| 2560 | return nullptr; |
| 2561 | |
| 2562 | // Upper - Lower [- 1] + Step |
| 2563 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), |
| 2564 | Step->IgnoreImplicit()); |
| 2565 | if (!Diff.isUsable()) |
| 2566 | return nullptr; |
| 2567 | |
| 2568 | // Parentheses (for dumping/debugging purposes only). |
| 2569 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 2570 | if (!Diff.isUsable()) |
| 2571 | return nullptr; |
| 2572 | |
| 2573 | // (Upper - Lower [- 1] + Step) / Step |
| 2574 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), |
| 2575 | Step->IgnoreImplicit()); |
| 2576 | if (!Diff.isUsable()) |
| 2577 | return nullptr; |
| 2578 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2579 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
| 2580 | if (LimitedType) { |
| 2581 | auto &C = SemaRef.Context; |
| 2582 | QualType Type = Diff.get()->getType(); |
| 2583 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 2584 | if (NewSize != C.getTypeSize(Type)) { |
| 2585 | if (NewSize < C.getTypeSize(Type)) { |
| 2586 | assert(NewSize == 64 && "incorrect loop var size"); |
| 2587 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 2588 | << InitSrcRange << ConditionSrcRange; |
| 2589 | } |
| 2590 | QualType NewType = C.getIntTypeForBitwidth( |
| 2591 | NewSize, Type->hasSignedIntegerRepresentation()); |
| 2592 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 2593 | Sema::AA_Converting, true); |
| 2594 | if (!Diff.isUsable()) |
| 2595 | return nullptr; |
| 2596 | } |
| 2597 | } |
| 2598 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2599 | return Diff.get(); |
| 2600 | } |
| 2601 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2602 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 2603 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 2604 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 2605 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 2606 | auto CondExpr = SemaRef.BuildBinOp( |
| 2607 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 2608 | : (TestIsStrictOp ? BO_GT : BO_GE), |
| 2609 | LB, UB); |
| 2610 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 2611 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 2612 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 2613 | } |
| 2614 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2615 | /// \brief Build reference expression to the counter be used for codegen. |
| 2616 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2617 | return buildDeclRefExpr(SemaRef, Var, Var->getType(), DefaultLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | /// \brief Build initization of the counter be used for codegen. |
| 2621 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 2622 | |
| 2623 | /// \brief Build step of the counter be used for codegen. |
| 2624 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 2625 | |
| 2626 | /// \brief Iteration space of a single for loop. |
| 2627 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2628 | /// \brief Condition of the loop. |
| 2629 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2630 | /// \brief This expression calculates the number of iterations in the loop. |
| 2631 | /// It is always possible to calculate it before starting the loop. |
| 2632 | Expr *NumIterations; |
| 2633 | /// \brief The loop counter variable. |
| 2634 | Expr *CounterVar; |
| 2635 | /// \brief This is initializer for the initial value of #CounterVar. |
| 2636 | Expr *CounterInit; |
| 2637 | /// \brief This is step for the #CounterVar used to generate its update: |
| 2638 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 2639 | Expr *CounterStep; |
| 2640 | /// \brief Should step be subtracted? |
| 2641 | bool Subtract; |
| 2642 | /// \brief Source range of the loop init. |
| 2643 | SourceRange InitSrcRange; |
| 2644 | /// \brief Source range of the loop condition. |
| 2645 | SourceRange CondSrcRange; |
| 2646 | /// \brief Source range of the loop increment. |
| 2647 | SourceRange IncSrcRange; |
| 2648 | }; |
| 2649 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2650 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2651 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2652 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 2653 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 2654 | assert(Init && "Expected loop in canonical form."); |
| 2655 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 2656 | if (CollapseIteration > 0 && |
| 2657 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 2658 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 2659 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 2660 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 2661 | } |
| 2662 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 2663 | } |
| 2664 | } |
| 2665 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2666 | /// \brief Called on a for stmt to check and extract its iteration space |
| 2667 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2668 | static bool CheckOpenMPIterationSpace( |
| 2669 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 2670 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
| 2671 | Expr *NestedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2672 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 2673 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2674 | // OpenMP [2.6, Canonical Loop Form] |
| 2675 | // for (init-expr; test-expr; incr-expr) structured-block |
| 2676 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 2677 | if (!For) { |
| 2678 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2679 | << (NestedLoopCountExpr != nullptr) << getOpenMPDirectiveName(DKind) |
| 2680 | << NestedLoopCount << (CurrentNestedLoopCount > 0) |
| 2681 | << CurrentNestedLoopCount; |
| 2682 | if (NestedLoopCount > 1) |
| 2683 | SemaRef.Diag(NestedLoopCountExpr->getExprLoc(), |
| 2684 | diag::note_omp_collapse_expr) |
| 2685 | << NestedLoopCountExpr->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2686 | return true; |
| 2687 | } |
| 2688 | assert(For->getBody()); |
| 2689 | |
| 2690 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 2691 | |
| 2692 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2693 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2694 | if (ISC.CheckInit(Init)) { |
| 2695 | return true; |
| 2696 | } |
| 2697 | |
| 2698 | bool HasErrors = false; |
| 2699 | |
| 2700 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2701 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2702 | |
| 2703 | // OpenMP [2.6, Canonical Loop Form] |
| 2704 | // Var is one of the following: |
| 2705 | // A variable of signed or unsigned integer type. |
| 2706 | // For C++, a variable of a random access iterator type. |
| 2707 | // For C, a variable of a pointer type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2708 | auto VarType = Var->getType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2709 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 2710 | !VarType->isPointerType() && |
| 2711 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 2712 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 2713 | << SemaRef.getLangOpts().CPlusPlus; |
| 2714 | HasErrors = true; |
| 2715 | } |
| 2716 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2717 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 2718 | // Construct |
| 2719 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2720 | // parallel for construct is (are) private. |
| 2721 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2722 | // with just one associated for-loop is linear with a constant-linear-step |
| 2723 | // that is the increment of the associated for-loop. |
| 2724 | // Exclude loop var from the list of variables with implicitly defined data |
| 2725 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 2726 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2727 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2728 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 2729 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 2730 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2731 | // with just one associated for-loop may be listed in a linear clause with a |
| 2732 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2733 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2734 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2735 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2736 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 2737 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 2738 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2739 | auto PredeterminedCKind = |
| 2740 | isOpenMPSimdDirective(DKind) |
| 2741 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 2742 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2743 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 2744 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2745 | (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && |
| 2746 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 2747 | DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) && |
| 2748 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 2749 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2750 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2751 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 2752 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 2753 | if (DVar.RefExpr == nullptr) |
| 2754 | DVar.CKind = PredeterminedCKind; |
| 2755 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2756 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2757 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2758 | // Make the loop iteration variable private (for worksharing constructs), |
| 2759 | // linear (for simd directives with the only one associated loop) or |
| 2760 | // lastprivate (for simd directives with several collapsed loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 2761 | if (DVar.CKind == OMPC_unknown) |
| 2762 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 2763 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2764 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2767 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2768 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2769 | // Check test-expr. |
| 2770 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 2771 | |
| 2772 | // Check incr-expr. |
| 2773 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 2774 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2775 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2776 | return HasErrors; |
| 2777 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2778 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2779 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2780 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
| 2781 | DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2782 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
| 2783 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 2784 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 2785 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 2786 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 2787 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 2788 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 2789 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2790 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 2791 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2792 | ResultIterSpace.CounterVar == nullptr || |
| 2793 | ResultIterSpace.CounterInit == nullptr || |
| 2794 | ResultIterSpace.CounterStep == nullptr); |
| 2795 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2796 | return HasErrors; |
| 2797 | } |
| 2798 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2799 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 2800 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 2801 | SourceLocation Loc, ExprResult VarRef, |
| 2802 | ExprResult Start, ExprResult Iter, |
| 2803 | ExprResult Step, bool Subtract) { |
| 2804 | // Add parentheses (for debugging purposes only). |
| 2805 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 2806 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 2807 | !Step.isUsable()) |
| 2808 | return ExprError(); |
| 2809 | |
| 2810 | ExprResult Update = SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), |
| 2811 | Step.get()->IgnoreImplicit()); |
| 2812 | if (!Update.isUsable()) |
| 2813 | return ExprError(); |
| 2814 | |
| 2815 | // Build 'VarRef = Start + Iter * Step'. |
| 2816 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
| 2817 | Start.get()->IgnoreImplicit(), Update.get()); |
| 2818 | if (!Update.isUsable()) |
| 2819 | return ExprError(); |
| 2820 | |
| 2821 | Update = SemaRef.PerformImplicitConversion( |
| 2822 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 2823 | if (!Update.isUsable()) |
| 2824 | return ExprError(); |
| 2825 | |
| 2826 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 2827 | return Update; |
| 2828 | } |
| 2829 | |
| 2830 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 2831 | /// bits. |
| 2832 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 2833 | Sema &SemaRef) { |
| 2834 | if (E == nullptr) |
| 2835 | return ExprError(); |
| 2836 | auto &C = SemaRef.Context; |
| 2837 | QualType OldType = E->getType(); |
| 2838 | unsigned HasBits = C.getTypeSize(OldType); |
| 2839 | if (HasBits >= Bits) |
| 2840 | return ExprResult(E); |
| 2841 | // OK to convert to signed, because new type has more bits than old. |
| 2842 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 2843 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 2844 | true); |
| 2845 | } |
| 2846 | |
| 2847 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 2848 | /// into \a Bits bits. |
| 2849 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 2850 | if (E == nullptr) |
| 2851 | return false; |
| 2852 | llvm::APSInt Result; |
| 2853 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 2854 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 2855 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | /// \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] | 2859 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 2860 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2861 | static unsigned |
| 2862 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *NestedLoopCountExpr, |
| 2863 | Stmt *AStmt, Sema &SemaRef, DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2864 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2865 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2866 | unsigned NestedLoopCount = 1; |
| 2867 | if (NestedLoopCountExpr) { |
| 2868 | // Found 'collapse' clause - calculate collapse number. |
| 2869 | llvm::APSInt Result; |
| 2870 | if (NestedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 2871 | NestedLoopCount = Result.getLimitedValue(); |
| 2872 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2873 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 2874 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2875 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 2876 | IterSpaces.resize(NestedLoopCount); |
| 2877 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2878 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2879 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2880 | NestedLoopCount, NestedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2881 | VarsWithImplicitDSA, IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 2882 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2883 | // 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] | 2884 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2885 | // All loops associated with the construct must be perfectly nested; that |
| 2886 | // is, there must be no intervening code nor any OpenMP directive between |
| 2887 | // any two loops. |
| 2888 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2891 | Built.clear(/* size */ NestedLoopCount); |
| 2892 | |
| 2893 | if (SemaRef.CurContext->isDependentContext()) |
| 2894 | return NestedLoopCount; |
| 2895 | |
| 2896 | // An example of what is generated for the following code: |
| 2897 | // |
| 2898 | // #pragma omp simd collapse(2) |
| 2899 | // for (i = 0; i < NI; ++i) |
| 2900 | // for (j = J0; j < NJ; j+=2) { |
| 2901 | // <loop body> |
| 2902 | // } |
| 2903 | // |
| 2904 | // We generate the code below. |
| 2905 | // Note: the loop body may be outlined in CodeGen. |
| 2906 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 2907 | // iterations and operator+= to calculate counter value. |
| 2908 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 2909 | // or i64 is currently supported). |
| 2910 | // |
| 2911 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 2912 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 2913 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 2914 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 2915 | // // similar updates for vars in clauses (e.g. 'linear') |
| 2916 | // <loop body (using local i and j)> |
| 2917 | // } |
| 2918 | // i = NI; // assign final values of counters |
| 2919 | // j = NJ; |
| 2920 | // |
| 2921 | |
| 2922 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 2923 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2924 | // Precondition tests if there is at least one iteration (all conditions are |
| 2925 | // true). |
| 2926 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2927 | auto N0 = IterSpaces[0].NumIterations; |
| 2928 | ExprResult LastIteration32 = WidenIterationCount(32 /* Bits */, N0, SemaRef); |
| 2929 | ExprResult LastIteration64 = WidenIterationCount(64 /* Bits */, N0, SemaRef); |
| 2930 | |
| 2931 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 2932 | return NestedLoopCount; |
| 2933 | |
| 2934 | auto &C = SemaRef.Context; |
| 2935 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 2936 | |
| 2937 | Scope *CurScope = DSA.getCurScope(); |
| 2938 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2939 | if (PreCond.isUsable()) { |
| 2940 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 2941 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 2942 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2943 | auto N = IterSpaces[Cnt].NumIterations; |
| 2944 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 2945 | if (LastIteration32.isUsable()) |
| 2946 | LastIteration32 = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_Mul, |
| 2947 | LastIteration32.get(), N); |
| 2948 | if (LastIteration64.isUsable()) |
| 2949 | LastIteration64 = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_Mul, |
| 2950 | LastIteration64.get(), N); |
| 2951 | } |
| 2952 | |
| 2953 | // Choose either the 32-bit or 64-bit version. |
| 2954 | ExprResult LastIteration = LastIteration64; |
| 2955 | if (LastIteration32.isUsable() && |
| 2956 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 2957 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 2958 | FitsInto( |
| 2959 | 32 /* Bits */, |
| 2960 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 2961 | LastIteration64.get(), SemaRef))) |
| 2962 | LastIteration = LastIteration32; |
| 2963 | |
| 2964 | if (!LastIteration.isUsable()) |
| 2965 | return 0; |
| 2966 | |
| 2967 | // Save the number of iterations. |
| 2968 | ExprResult NumIterations = LastIteration; |
| 2969 | { |
| 2970 | LastIteration = SemaRef.BuildBinOp( |
| 2971 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 2972 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2973 | if (!LastIteration.isUsable()) |
| 2974 | return 0; |
| 2975 | } |
| 2976 | |
| 2977 | // Calculate the last iteration number beforehand instead of doing this on |
| 2978 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 2979 | llvm::APSInt Result; |
| 2980 | bool IsConstant = |
| 2981 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2982 | ExprResult CalcLastIteration; |
| 2983 | if (!IsConstant) { |
| 2984 | SourceLocation SaveLoc; |
| 2985 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2986 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2987 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2988 | ExprResult SaveRef = buildDeclRefExpr( |
| 2989 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2990 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 2991 | SaveRef.get(), LastIteration.get()); |
| 2992 | LastIteration = SaveRef; |
| 2993 | |
| 2994 | // Prepare SaveRef + 1. |
| 2995 | NumIterations = SemaRef.BuildBinOp( |
| 2996 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 2997 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2998 | if (!NumIterations.isUsable()) |
| 2999 | return 0; |
| 3000 | } |
| 3001 | |
| 3002 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3003 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3004 | QualType VType = LastIteration.get()->getType(); |
| 3005 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3006 | ExprResult LB, UB, IL, ST, EUB; |
| 3007 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3008 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3009 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3010 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3011 | SemaRef.AddInitializerToDecl( |
| 3012 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3013 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3014 | |
| 3015 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3016 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3017 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3018 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3019 | /*DirectInit*/ false, |
| 3020 | /*TypeMayContainAuto*/ false); |
| 3021 | |
| 3022 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3023 | // This will be used to implement clause 'lastprivate'. |
| 3024 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3025 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3026 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3027 | SemaRef.AddInitializerToDecl( |
| 3028 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3029 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3030 | |
| 3031 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3032 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3033 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3034 | SemaRef.AddInitializerToDecl( |
| 3035 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3036 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3037 | |
| 3038 | // Build expression: UB = min(UB, LastIteration) |
| 3039 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3040 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3041 | UB.get(), LastIteration.get()); |
| 3042 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3043 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3044 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3045 | CondOp.get()); |
| 3046 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3047 | } |
| 3048 | |
| 3049 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3050 | ExprResult IV; |
| 3051 | ExprResult Init; |
| 3052 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3053 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3054 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3055 | Expr *RHS = isOpenMPWorksharingDirective(DKind) |
| 3056 | ? LB.get() |
| 3057 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3058 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3059 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3060 | } |
| 3061 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3062 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3063 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3064 | ExprResult Cond = |
| 3065 | isOpenMPWorksharingDirective(DKind) |
| 3066 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3067 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3068 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3069 | |
| 3070 | // Loop increment (IV = IV + 1) |
| 3071 | SourceLocation IncLoc; |
| 3072 | ExprResult Inc = |
| 3073 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3074 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3075 | if (!Inc.isUsable()) |
| 3076 | return 0; |
| 3077 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3078 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3079 | if (!Inc.isUsable()) |
| 3080 | return 0; |
| 3081 | |
| 3082 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3083 | // Used for directives with static scheduling. |
| 3084 | ExprResult NextLB, NextUB; |
| 3085 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3086 | // LB + ST |
| 3087 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3088 | if (!NextLB.isUsable()) |
| 3089 | return 0; |
| 3090 | // LB = LB + ST |
| 3091 | NextLB = |
| 3092 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3093 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3094 | if (!NextLB.isUsable()) |
| 3095 | return 0; |
| 3096 | // UB + ST |
| 3097 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3098 | if (!NextUB.isUsable()) |
| 3099 | return 0; |
| 3100 | // UB = UB + ST |
| 3101 | NextUB = |
| 3102 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3103 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3104 | if (!NextUB.isUsable()) |
| 3105 | return 0; |
| 3106 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3107 | |
| 3108 | // Build updates and final values of the loop counters. |
| 3109 | bool HasErrors = false; |
| 3110 | Built.Counters.resize(NestedLoopCount); |
| 3111 | Built.Updates.resize(NestedLoopCount); |
| 3112 | Built.Finals.resize(NestedLoopCount); |
| 3113 | { |
| 3114 | ExprResult Div; |
| 3115 | // Go from inner nested loop to outer. |
| 3116 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3117 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3118 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3119 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3120 | // where Div is product of previous iterations' IS.NumIters. |
| 3121 | ExprResult Iter; |
| 3122 | if (Div.isUsable()) { |
| 3123 | Iter = |
| 3124 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3125 | } else { |
| 3126 | Iter = IV; |
| 3127 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3128 | "unusable div expected on first iteration only"); |
| 3129 | } |
| 3130 | |
| 3131 | if (Cnt != 0 && Iter.isUsable()) |
| 3132 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3133 | IS.NumIterations); |
| 3134 | if (!Iter.isUsable()) { |
| 3135 | HasErrors = true; |
| 3136 | break; |
| 3137 | } |
| 3138 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3139 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3140 | auto *CounterVar = buildDeclRefExpr( |
| 3141 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3142 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3143 | /*RefersToCapture=*/true); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3144 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3145 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3146 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3147 | if (!Update.isUsable()) { |
| 3148 | HasErrors = true; |
| 3149 | break; |
| 3150 | } |
| 3151 | |
| 3152 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3153 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3154 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3155 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3156 | if (!Final.isUsable()) { |
| 3157 | HasErrors = true; |
| 3158 | break; |
| 3159 | } |
| 3160 | |
| 3161 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3162 | if (Cnt != 0) { |
| 3163 | if (Div.isUnset()) |
| 3164 | Div = IS.NumIterations; |
| 3165 | else |
| 3166 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3167 | IS.NumIterations); |
| 3168 | |
| 3169 | // Add parentheses (for debugging purposes only). |
| 3170 | if (Div.isUsable()) |
| 3171 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3172 | if (!Div.isUsable()) { |
| 3173 | HasErrors = true; |
| 3174 | break; |
| 3175 | } |
| 3176 | } |
| 3177 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3178 | HasErrors = true; |
| 3179 | break; |
| 3180 | } |
| 3181 | // Save results |
| 3182 | Built.Counters[Cnt] = IS.CounterVar; |
| 3183 | Built.Updates[Cnt] = Update.get(); |
| 3184 | Built.Finals[Cnt] = Final.get(); |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | if (HasErrors) |
| 3189 | return 0; |
| 3190 | |
| 3191 | // Save results |
| 3192 | Built.IterationVarRef = IV.get(); |
| 3193 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3194 | Built.NumIterations = NumIterations.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3195 | Built.CalcLastIteration = CalcLastIteration.get(); |
| 3196 | Built.PreCond = PreCond.get(); |
| 3197 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3198 | Built.Init = Init.get(); |
| 3199 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3200 | Built.LB = LB.get(); |
| 3201 | Built.UB = UB.get(); |
| 3202 | Built.IL = IL.get(); |
| 3203 | Built.ST = ST.get(); |
| 3204 | Built.EUB = EUB.get(); |
| 3205 | Built.NLB = NextLB.get(); |
| 3206 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3207 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3208 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3209 | } |
| 3210 | |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3211 | static Expr *GetCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 3212 | auto &&CollapseFilter = [](const OMPClause *C) -> bool { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3213 | return C->getClauseKind() == OMPC_collapse; |
| 3214 | }; |
| 3215 | OMPExecutableDirective::filtered_clause_iterator<decltype(CollapseFilter)> I( |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 3216 | Clauses, std::move(CollapseFilter)); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3217 | if (I) |
| 3218 | return cast<OMPCollapseClause>(*I)->getNumForLoops(); |
| 3219 | return nullptr; |
| 3220 | } |
| 3221 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3222 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3223 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3224 | SourceLocation EndLoc, |
| 3225 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3226 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3227 | // In presence of clause 'collapse', it will define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3228 | unsigned NestedLoopCount = |
| 3229 | CheckOpenMPLoop(OMPD_simd, GetCollapseNumberExpr(Clauses), AStmt, *this, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3230 | *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3231 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3232 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3233 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3234 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3235 | "omp simd loop exprs were not built"); |
| 3236 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3237 | if (!CurContext->isDependentContext()) { |
| 3238 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3239 | for (auto C : Clauses) { |
| 3240 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3241 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3242 | B.NumIterations, *this, CurScope)) |
| 3243 | return StmtError(); |
| 3244 | } |
| 3245 | } |
| 3246 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3247 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3248 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3249 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3252 | StmtResult Sema::ActOnOpenMPForDirective( |
| 3253 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3254 | SourceLocation EndLoc, |
| 3255 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3256 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3257 | // In presence of clause 'collapse', it will define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3258 | unsigned NestedLoopCount = |
| 3259 | CheckOpenMPLoop(OMPD_for, GetCollapseNumberExpr(Clauses), AStmt, *this, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3260 | *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3261 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3262 | return StmtError(); |
| 3263 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3264 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3265 | "omp for loop exprs were not built"); |
| 3266 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3267 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3268 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3269 | Clauses, AStmt, B); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3272 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 3273 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3274 | SourceLocation EndLoc, |
| 3275 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3276 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3277 | // In presence of clause 'collapse', it will define the nested loops number. |
| 3278 | unsigned NestedLoopCount = |
| 3279 | CheckOpenMPLoop(OMPD_for_simd, GetCollapseNumberExpr(Clauses), AStmt, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3280 | *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3281 | if (NestedLoopCount == 0) |
| 3282 | return StmtError(); |
| 3283 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3284 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3285 | "omp for simd loop exprs were not built"); |
| 3286 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 3287 | if (!CurContext->isDependentContext()) { |
| 3288 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3289 | for (auto C : Clauses) { |
| 3290 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3291 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3292 | B.NumIterations, *this, CurScope)) |
| 3293 | return StmtError(); |
| 3294 | } |
| 3295 | } |
| 3296 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3297 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3298 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3299 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3300 | } |
| 3301 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3302 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3303 | Stmt *AStmt, |
| 3304 | SourceLocation StartLoc, |
| 3305 | SourceLocation EndLoc) { |
| 3306 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3307 | auto BaseStmt = AStmt; |
| 3308 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3309 | BaseStmt = CS->getCapturedStmt(); |
| 3310 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3311 | auto S = C->children(); |
| 3312 | if (!S) |
| 3313 | return StmtError(); |
| 3314 | // All associated statements must be '#pragma omp section' except for |
| 3315 | // the first one. |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3316 | for (++S; S; ++S) { |
| 3317 | auto SectionStmt = *S; |
| 3318 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3319 | if (SectionStmt) |
| 3320 | Diag(SectionStmt->getLocStart(), |
| 3321 | diag::err_omp_sections_substmt_not_section); |
| 3322 | return StmtError(); |
| 3323 | } |
| 3324 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3325 | } else { |
| 3326 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 3327 | return StmtError(); |
| 3328 | } |
| 3329 | |
| 3330 | getCurFunction()->setHasBranchProtectedScope(); |
| 3331 | |
| 3332 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 3333 | AStmt); |
| 3334 | } |
| 3335 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3336 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 3337 | SourceLocation StartLoc, |
| 3338 | SourceLocation EndLoc) { |
| 3339 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3340 | |
| 3341 | getCurFunction()->setHasBranchProtectedScope(); |
| 3342 | |
| 3343 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3344 | } |
| 3345 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3346 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 3347 | Stmt *AStmt, |
| 3348 | SourceLocation StartLoc, |
| 3349 | SourceLocation EndLoc) { |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3350 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3351 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3352 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3353 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 3354 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 3355 | // The copyprivate clause must not be used with the nowait clause. |
| 3356 | OMPClause *Nowait = nullptr; |
| 3357 | OMPClause *Copyprivate = nullptr; |
| 3358 | for (auto *Clause : Clauses) { |
| 3359 | if (Clause->getClauseKind() == OMPC_nowait) |
| 3360 | Nowait = Clause; |
| 3361 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 3362 | Copyprivate = Clause; |
| 3363 | if (Copyprivate && Nowait) { |
| 3364 | Diag(Copyprivate->getLocStart(), |
| 3365 | diag::err_omp_single_copyprivate_with_nowait); |
| 3366 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 3367 | return StmtError(); |
| 3368 | } |
| 3369 | } |
| 3370 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3371 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3372 | } |
| 3373 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3374 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 3375 | SourceLocation StartLoc, |
| 3376 | SourceLocation EndLoc) { |
| 3377 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3378 | |
| 3379 | getCurFunction()->setHasBranchProtectedScope(); |
| 3380 | |
| 3381 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3382 | } |
| 3383 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3384 | StmtResult |
| 3385 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 3386 | Stmt *AStmt, SourceLocation StartLoc, |
| 3387 | SourceLocation EndLoc) { |
| 3388 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3389 | |
| 3390 | getCurFunction()->setHasBranchProtectedScope(); |
| 3391 | |
| 3392 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 3393 | AStmt); |
| 3394 | } |
| 3395 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3396 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 3397 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3398 | SourceLocation EndLoc, |
| 3399 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3400 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3401 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3402 | // 1.2.2 OpenMP Language Terminology |
| 3403 | // Structured block - An executable statement with a single entry at the |
| 3404 | // top and a single exit at the bottom. |
| 3405 | // The point of exit cannot be a branch out of the structured block. |
| 3406 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3407 | CS->getCapturedDecl()->setNothrow(); |
| 3408 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3409 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3410 | // In presence of clause 'collapse', it will define the nested loops number. |
| 3411 | unsigned NestedLoopCount = |
| 3412 | CheckOpenMPLoop(OMPD_parallel_for, GetCollapseNumberExpr(Clauses), AStmt, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3413 | *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3414 | if (NestedLoopCount == 0) |
| 3415 | return StmtError(); |
| 3416 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3417 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3418 | "omp parallel for loop exprs were not built"); |
| 3419 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3420 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3421 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 3422 | NestedLoopCount, Clauses, AStmt, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3423 | } |
| 3424 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3425 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 3426 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3427 | SourceLocation EndLoc, |
| 3428 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3429 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3430 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3431 | // 1.2.2 OpenMP Language Terminology |
| 3432 | // Structured block - An executable statement with a single entry at the |
| 3433 | // top and a single exit at the bottom. |
| 3434 | // The point of exit cannot be a branch out of the structured block. |
| 3435 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3436 | CS->getCapturedDecl()->setNothrow(); |
| 3437 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3438 | OMPLoopDirective::HelperExprs B; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3439 | // In presence of clause 'collapse', it will define the nested loops number. |
| 3440 | unsigned NestedLoopCount = |
| 3441 | CheckOpenMPLoop(OMPD_parallel_for_simd, GetCollapseNumberExpr(Clauses), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3442 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3443 | if (NestedLoopCount == 0) |
| 3444 | return StmtError(); |
| 3445 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 3446 | if (!CurContext->isDependentContext()) { |
| 3447 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3448 | for (auto C : Clauses) { |
| 3449 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3450 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3451 | B.NumIterations, *this, CurScope)) |
| 3452 | return StmtError(); |
| 3453 | } |
| 3454 | } |
| 3455 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3456 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3457 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3458 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3459 | } |
| 3460 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3461 | StmtResult |
| 3462 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3463 | Stmt *AStmt, SourceLocation StartLoc, |
| 3464 | SourceLocation EndLoc) { |
| 3465 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3466 | auto BaseStmt = AStmt; |
| 3467 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3468 | BaseStmt = CS->getCapturedStmt(); |
| 3469 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3470 | auto S = C->children(); |
| 3471 | if (!S) |
| 3472 | return StmtError(); |
| 3473 | // All associated statements must be '#pragma omp section' except for |
| 3474 | // the first one. |
| 3475 | for (++S; S; ++S) { |
| 3476 | auto SectionStmt = *S; |
| 3477 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3478 | if (SectionStmt) |
| 3479 | Diag(SectionStmt->getLocStart(), |
| 3480 | diag::err_omp_parallel_sections_substmt_not_section); |
| 3481 | return StmtError(); |
| 3482 | } |
| 3483 | } |
| 3484 | } else { |
| 3485 | Diag(AStmt->getLocStart(), |
| 3486 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 3487 | return StmtError(); |
| 3488 | } |
| 3489 | |
| 3490 | getCurFunction()->setHasBranchProtectedScope(); |
| 3491 | |
| 3492 | return OMPParallelSectionsDirective::Create(Context, StartLoc, EndLoc, |
| 3493 | Clauses, AStmt); |
| 3494 | } |
| 3495 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3496 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 3497 | Stmt *AStmt, SourceLocation StartLoc, |
| 3498 | SourceLocation EndLoc) { |
| 3499 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3500 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3501 | // 1.2.2 OpenMP Language Terminology |
| 3502 | // Structured block - An executable statement with a single entry at the |
| 3503 | // top and a single exit at the bottom. |
| 3504 | // The point of exit cannot be a branch out of the structured block. |
| 3505 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3506 | CS->getCapturedDecl()->setNothrow(); |
| 3507 | |
| 3508 | getCurFunction()->setHasBranchProtectedScope(); |
| 3509 | |
| 3510 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3511 | } |
| 3512 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3513 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 3514 | SourceLocation EndLoc) { |
| 3515 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 3516 | } |
| 3517 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3518 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 3519 | SourceLocation EndLoc) { |
| 3520 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 3521 | } |
| 3522 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3523 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 3524 | SourceLocation EndLoc) { |
| 3525 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 3526 | } |
| 3527 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3528 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 3529 | SourceLocation StartLoc, |
| 3530 | SourceLocation EndLoc) { |
| 3531 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3532 | |
| 3533 | getCurFunction()->setHasBranchProtectedScope(); |
| 3534 | |
| 3535 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3536 | } |
| 3537 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3538 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 3539 | SourceLocation StartLoc, |
| 3540 | SourceLocation EndLoc) { |
| 3541 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 3542 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 3543 | } |
| 3544 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3545 | StmtResult Sema::ActOnOpenMPOrderedDirective(Stmt *AStmt, |
| 3546 | SourceLocation StartLoc, |
| 3547 | SourceLocation EndLoc) { |
| 3548 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3549 | |
| 3550 | getCurFunction()->setHasBranchProtectedScope(); |
| 3551 | |
| 3552 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3553 | } |
| 3554 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3555 | namespace { |
| 3556 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 3557 | /// construct. |
| 3558 | class OpenMPAtomicUpdateChecker { |
| 3559 | /// \brief Error results for atomic update expressions. |
| 3560 | enum ExprAnalysisErrorCode { |
| 3561 | /// \brief A statement is not an expression statement. |
| 3562 | NotAnExpression, |
| 3563 | /// \brief Expression is not builtin binary or unary operation. |
| 3564 | NotABinaryOrUnaryExpression, |
| 3565 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 3566 | NotAnUnaryIncDecExpression, |
| 3567 | /// \brief An expression is not of scalar type. |
| 3568 | NotAScalarType, |
| 3569 | /// \brief A binary operation is not an assignment operation. |
| 3570 | NotAnAssignmentOp, |
| 3571 | /// \brief RHS part of the binary operation is not a binary expression. |
| 3572 | NotABinaryExpression, |
| 3573 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 3574 | /// expression. |
| 3575 | NotABinaryOperator, |
| 3576 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 3577 | /// part. |
| 3578 | NotAnUpdateExpression, |
| 3579 | /// \brief No errors is found. |
| 3580 | NoError |
| 3581 | }; |
| 3582 | /// \brief Reference to Sema. |
| 3583 | Sema &SemaRef; |
| 3584 | /// \brief A location for note diagnostics (when error is found). |
| 3585 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3586 | /// \brief 'x' lvalue part of the source atomic expression. |
| 3587 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3588 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 3589 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3590 | /// \brief Helper expression of the form |
| 3591 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 3592 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 3593 | Expr *UpdateExpr; |
| 3594 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 3595 | /// important for non-associative operations. |
| 3596 | bool IsXLHSInRHSPart; |
| 3597 | BinaryOperatorKind Op; |
| 3598 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3599 | /// \brief true if the source expression is a postfix unary operation, false |
| 3600 | /// if it is a prefix unary operation. |
| 3601 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3602 | |
| 3603 | public: |
| 3604 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3605 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3606 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3607 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 3608 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3609 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 3610 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3611 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 3612 | /// \param NoteId Diagnostic note for the main error message. |
| 3613 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3614 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3615 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 3616 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3617 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 3618 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3619 | /// \brief Return the update expression used in calculation of the updated |
| 3620 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 3621 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 3622 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 3623 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 3624 | /// false otherwise. |
| 3625 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 3626 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3627 | /// \brief true if the source expression is a postfix unary operation, false |
| 3628 | /// if it is a prefix unary operation. |
| 3629 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 3630 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3631 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3632 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 3633 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3634 | }; |
| 3635 | } // namespace |
| 3636 | |
| 3637 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 3638 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 3639 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 3640 | SourceLocation ErrorLoc, NoteLoc; |
| 3641 | SourceRange ErrorRange, NoteRange; |
| 3642 | // Allowed constructs are: |
| 3643 | // x = x binop expr; |
| 3644 | // x = expr binop x; |
| 3645 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 3646 | X = AtomicBinOp->getLHS(); |
| 3647 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 3648 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 3649 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 3650 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 3651 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3652 | Op = AtomicInnerBinOp->getOpcode(); |
| 3653 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3654 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 3655 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 3656 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 3657 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 3658 | /*Canonical=*/true); |
| 3659 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 3660 | /*Canonical=*/true); |
| 3661 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 3662 | /*Canonical=*/true); |
| 3663 | if (XId == LHSId) { |
| 3664 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3665 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3666 | } else if (XId == RHSId) { |
| 3667 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3668 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3669 | } else { |
| 3670 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 3671 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 3672 | NoteLoc = X->getExprLoc(); |
| 3673 | NoteRange = X->getSourceRange(); |
| 3674 | ErrorFound = NotAnUpdateExpression; |
| 3675 | } |
| 3676 | } else { |
| 3677 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 3678 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 3679 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 3680 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3681 | ErrorFound = NotABinaryOperator; |
| 3682 | } |
| 3683 | } else { |
| 3684 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 3685 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 3686 | ErrorFound = NotABinaryExpression; |
| 3687 | } |
| 3688 | } else { |
| 3689 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3690 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3691 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 3692 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3693 | ErrorFound = NotAnAssignmentOp; |
| 3694 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3695 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3696 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 3697 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 3698 | return true; |
| 3699 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3700 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3701 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 3705 | unsigned NoteId) { |
| 3706 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 3707 | SourceLocation ErrorLoc, NoteLoc; |
| 3708 | SourceRange ErrorRange, NoteRange; |
| 3709 | // Allowed constructs are: |
| 3710 | // x++; |
| 3711 | // x--; |
| 3712 | // ++x; |
| 3713 | // --x; |
| 3714 | // x binop= expr; |
| 3715 | // x = x binop expr; |
| 3716 | // x = expr binop x; |
| 3717 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 3718 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 3719 | if (AtomicBody->getType()->isScalarType() || |
| 3720 | AtomicBody->isInstantiationDependent()) { |
| 3721 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 3722 | AtomicBody->IgnoreParenImpCasts())) { |
| 3723 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3724 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3725 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3726 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3727 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3728 | X = AtomicCompAssignOp->getLHS(); |
| 3729 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3730 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 3731 | AtomicBody->IgnoreParenImpCasts())) { |
| 3732 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3733 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 3734 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3735 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3736 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 3737 | // Check for Unary Operation |
| 3738 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3739 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3740 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 3741 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 3742 | X = AtomicUnaryOp->getSubExpr(); |
| 3743 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 3744 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3745 | } else { |
| 3746 | ErrorFound = NotAnUnaryIncDecExpression; |
| 3747 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 3748 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 3749 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 3750 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3751 | } |
| 3752 | } else { |
| 3753 | ErrorFound = NotABinaryOrUnaryExpression; |
| 3754 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 3755 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 3756 | } |
| 3757 | } else { |
| 3758 | ErrorFound = NotAScalarType; |
| 3759 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 3760 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 3761 | } |
| 3762 | } else { |
| 3763 | ErrorFound = NotAnExpression; |
| 3764 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 3765 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 3766 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3767 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3768 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 3769 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 3770 | return true; |
| 3771 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3772 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3773 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3774 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 3775 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 3776 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 3777 | auto *OVEX = new (SemaRef.getASTContext()) |
| 3778 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 3779 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 3780 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 3781 | auto Update = |
| 3782 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 3783 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 3784 | if (Update.isInvalid()) |
| 3785 | return true; |
| 3786 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 3787 | Sema::AA_Casting); |
| 3788 | if (Update.isInvalid()) |
| 3789 | return true; |
| 3790 | UpdateExpr = Update.get(); |
| 3791 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3792 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3795 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 3796 | Stmt *AStmt, |
| 3797 | SourceLocation StartLoc, |
| 3798 | SourceLocation EndLoc) { |
| 3799 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3800 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3801 | // 1.2.2 OpenMP Language Terminology |
| 3802 | // Structured block - An executable statement with a single entry at the |
| 3803 | // top and a single exit at the bottom. |
| 3804 | // The point of exit cannot be a branch out of the structured block. |
| 3805 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3806 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 3807 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3808 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3809 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3810 | C->getClauseKind() == OMPC_update || |
| 3811 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3812 | if (AtomicKind != OMPC_unknown) { |
| 3813 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 3814 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 3815 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 3816 | << getOpenMPClauseName(AtomicKind); |
| 3817 | } else { |
| 3818 | AtomicKind = C->getClauseKind(); |
| 3819 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3820 | } |
| 3821 | } |
| 3822 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3823 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3824 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 3825 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 3826 | Body = EWC->getSubExpr(); |
| 3827 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3828 | Expr *X = nullptr; |
| 3829 | Expr *V = nullptr; |
| 3830 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3831 | Expr *UE = nullptr; |
| 3832 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3833 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3834 | // OpenMP [2.12.6, atomic Construct] |
| 3835 | // In the next expressions: |
| 3836 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 3837 | // * During the execution of an atomic region, multiple syntactic |
| 3838 | // occurrences of x must designate the same storage location. |
| 3839 | // * Neither of v and expr (as applicable) may access the storage location |
| 3840 | // designated by x. |
| 3841 | // * Neither of x and expr (as applicable) may access the storage location |
| 3842 | // designated by v. |
| 3843 | // * expr is an expression with scalar type. |
| 3844 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 3845 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 3846 | // * The expression x binop expr must be numerically equivalent to x binop |
| 3847 | // (expr). This requirement is satisfied if the operators in expr have |
| 3848 | // precedence greater than binop, or by using parentheses around expr or |
| 3849 | // subexpressions of expr. |
| 3850 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 3851 | // binop x. This requirement is satisfied if the operators in expr have |
| 3852 | // precedence equal to or greater than binop, or by using parentheses around |
| 3853 | // expr or subexpressions of expr. |
| 3854 | // * For forms that allow multiple occurrences of x, the number of times |
| 3855 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3856 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3857 | enum { |
| 3858 | NotAnExpression, |
| 3859 | NotAnAssignmentOp, |
| 3860 | NotAScalarType, |
| 3861 | NotAnLValue, |
| 3862 | NoError |
| 3863 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3864 | SourceLocation ErrorLoc, NoteLoc; |
| 3865 | SourceRange ErrorRange, NoteRange; |
| 3866 | // If clause is read: |
| 3867 | // v = x; |
| 3868 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 3869 | auto AtomicBinOp = |
| 3870 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 3871 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 3872 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 3873 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 3874 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 3875 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 3876 | if (!X->isLValue() || !V->isLValue()) { |
| 3877 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 3878 | ErrorFound = NotAnLValue; |
| 3879 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3880 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3881 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 3882 | NoteRange = NotLValueExpr->getSourceRange(); |
| 3883 | } |
| 3884 | } else if (!X->isInstantiationDependent() || |
| 3885 | !V->isInstantiationDependent()) { |
| 3886 | auto NotScalarExpr = |
| 3887 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 3888 | ? V |
| 3889 | : X; |
| 3890 | ErrorFound = NotAScalarType; |
| 3891 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3892 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3893 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 3894 | NoteRange = NotScalarExpr->getSourceRange(); |
| 3895 | } |
| 3896 | } else { |
| 3897 | ErrorFound = NotAnAssignmentOp; |
| 3898 | ErrorLoc = AtomicBody->getExprLoc(); |
| 3899 | ErrorRange = AtomicBody->getSourceRange(); |
| 3900 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 3901 | : AtomicBody->getExprLoc(); |
| 3902 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 3903 | : AtomicBody->getSourceRange(); |
| 3904 | } |
| 3905 | } else { |
| 3906 | ErrorFound = NotAnExpression; |
| 3907 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 3908 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3909 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3910 | if (ErrorFound != NoError) { |
| 3911 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 3912 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3913 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 3914 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3915 | return StmtError(); |
| 3916 | } else if (CurContext->isDependentContext()) |
| 3917 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3918 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3919 | enum { |
| 3920 | NotAnExpression, |
| 3921 | NotAnAssignmentOp, |
| 3922 | NotAScalarType, |
| 3923 | NotAnLValue, |
| 3924 | NoError |
| 3925 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3926 | SourceLocation ErrorLoc, NoteLoc; |
| 3927 | SourceRange ErrorRange, NoteRange; |
| 3928 | // If clause is write: |
| 3929 | // x = expr; |
| 3930 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 3931 | auto AtomicBinOp = |
| 3932 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 3933 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 3934 | X = AtomicBinOp->getLHS(); |
| 3935 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3936 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 3937 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 3938 | if (!X->isLValue()) { |
| 3939 | ErrorFound = NotAnLValue; |
| 3940 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3941 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3942 | NoteLoc = X->getExprLoc(); |
| 3943 | NoteRange = X->getSourceRange(); |
| 3944 | } |
| 3945 | } else if (!X->isInstantiationDependent() || |
| 3946 | !E->isInstantiationDependent()) { |
| 3947 | auto NotScalarExpr = |
| 3948 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 3949 | ? E |
| 3950 | : X; |
| 3951 | ErrorFound = NotAScalarType; |
| 3952 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3953 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3954 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 3955 | NoteRange = NotScalarExpr->getSourceRange(); |
| 3956 | } |
| 3957 | } else { |
| 3958 | ErrorFound = NotAnAssignmentOp; |
| 3959 | ErrorLoc = AtomicBody->getExprLoc(); |
| 3960 | ErrorRange = AtomicBody->getSourceRange(); |
| 3961 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 3962 | : AtomicBody->getExprLoc(); |
| 3963 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 3964 | : AtomicBody->getSourceRange(); |
| 3965 | } |
| 3966 | } else { |
| 3967 | ErrorFound = NotAnExpression; |
| 3968 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 3969 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3970 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 3971 | if (ErrorFound != NoError) { |
| 3972 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 3973 | << ErrorRange; |
| 3974 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 3975 | << NoteRange; |
| 3976 | return StmtError(); |
| 3977 | } else if (CurContext->isDependentContext()) |
| 3978 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3979 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3980 | // If clause is update: |
| 3981 | // x++; |
| 3982 | // x--; |
| 3983 | // ++x; |
| 3984 | // --x; |
| 3985 | // x binop= expr; |
| 3986 | // x = x binop expr; |
| 3987 | // x = expr binop x; |
| 3988 | OpenMPAtomicUpdateChecker Checker(*this); |
| 3989 | if (Checker.checkStatement( |
| 3990 | Body, (AtomicKind == OMPC_update) |
| 3991 | ? diag::err_omp_atomic_update_not_expression_statement |
| 3992 | : diag::err_omp_atomic_not_expression_statement, |
| 3993 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3994 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3995 | if (!CurContext->isDependentContext()) { |
| 3996 | E = Checker.getExpr(); |
| 3997 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3998 | UE = Checker.getUpdateExpr(); |
| 3999 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4000 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4001 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4002 | enum { |
| 4003 | NotAnAssignmentOp, |
| 4004 | NotACompoundStatement, |
| 4005 | NotTwoSubstatements, |
| 4006 | NotASpecificExpression, |
| 4007 | NoError |
| 4008 | } ErrorFound = NoError; |
| 4009 | SourceLocation ErrorLoc, NoteLoc; |
| 4010 | SourceRange ErrorRange, NoteRange; |
| 4011 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 4012 | // If clause is a capture: |
| 4013 | // v = x++; |
| 4014 | // v = x--; |
| 4015 | // v = ++x; |
| 4016 | // v = --x; |
| 4017 | // v = x binop= expr; |
| 4018 | // v = x = x binop expr; |
| 4019 | // v = x = expr binop x; |
| 4020 | auto *AtomicBinOp = |
| 4021 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4022 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4023 | V = AtomicBinOp->getLHS(); |
| 4024 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4025 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4026 | if (Checker.checkStatement( |
| 4027 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 4028 | diag::note_omp_atomic_update)) |
| 4029 | return StmtError(); |
| 4030 | E = Checker.getExpr(); |
| 4031 | X = Checker.getX(); |
| 4032 | UE = Checker.getUpdateExpr(); |
| 4033 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 4034 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
| 4035 | } else { |
| 4036 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4037 | ErrorRange = AtomicBody->getSourceRange(); |
| 4038 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4039 | : AtomicBody->getExprLoc(); |
| 4040 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4041 | : AtomicBody->getSourceRange(); |
| 4042 | ErrorFound = NotAnAssignmentOp; |
| 4043 | } |
| 4044 | if (ErrorFound != NoError) { |
| 4045 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 4046 | << ErrorRange; |
| 4047 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4048 | return StmtError(); |
| 4049 | } else if (CurContext->isDependentContext()) { |
| 4050 | UE = V = E = X = nullptr; |
| 4051 | } |
| 4052 | } else { |
| 4053 | // If clause is a capture: |
| 4054 | // { v = x; x = expr; } |
| 4055 | // { v = x; x++; } |
| 4056 | // { v = x; x--; } |
| 4057 | // { v = x; ++x; } |
| 4058 | // { v = x; --x; } |
| 4059 | // { v = x; x binop= expr; } |
| 4060 | // { v = x; x = x binop expr; } |
| 4061 | // { v = x; x = expr binop x; } |
| 4062 | // { x++; v = x; } |
| 4063 | // { x--; v = x; } |
| 4064 | // { ++x; v = x; } |
| 4065 | // { --x; v = x; } |
| 4066 | // { x binop= expr; v = x; } |
| 4067 | // { x = x binop expr; v = x; } |
| 4068 | // { x = expr binop x; v = x; } |
| 4069 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 4070 | // Check that this is { expr1; expr2; } |
| 4071 | if (CS->size() == 2) { |
| 4072 | auto *First = CS->body_front(); |
| 4073 | auto *Second = CS->body_back(); |
| 4074 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 4075 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4076 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 4077 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4078 | // Need to find what subexpression is 'v' and what is 'x'. |
| 4079 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4080 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 4081 | BinaryOperator *BinOp = nullptr; |
| 4082 | if (IsUpdateExprFound) { |
| 4083 | BinOp = dyn_cast<BinaryOperator>(First); |
| 4084 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4085 | } |
| 4086 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4087 | // { v = x; x++; } |
| 4088 | // { v = x; x--; } |
| 4089 | // { v = x; ++x; } |
| 4090 | // { v = x; --x; } |
| 4091 | // { v = x; x binop= expr; } |
| 4092 | // { v = x; x = x binop expr; } |
| 4093 | // { v = x; x = expr binop x; } |
| 4094 | // Check that the first expression has form v = x. |
| 4095 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4096 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4097 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4098 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4099 | IsUpdateExprFound = XId == PossibleXId; |
| 4100 | if (IsUpdateExprFound) { |
| 4101 | V = BinOp->getLHS(); |
| 4102 | X = Checker.getX(); |
| 4103 | E = Checker.getExpr(); |
| 4104 | UE = Checker.getUpdateExpr(); |
| 4105 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4106 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4107 | } |
| 4108 | } |
| 4109 | if (!IsUpdateExprFound) { |
| 4110 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 4111 | BinOp = nullptr; |
| 4112 | if (IsUpdateExprFound) { |
| 4113 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 4114 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4115 | } |
| 4116 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4117 | // { x++; v = x; } |
| 4118 | // { x--; v = x; } |
| 4119 | // { ++x; v = x; } |
| 4120 | // { --x; v = x; } |
| 4121 | // { x binop= expr; v = x; } |
| 4122 | // { x = x binop expr; v = x; } |
| 4123 | // { x = expr binop x; v = x; } |
| 4124 | // Check that the second expression has form v = x. |
| 4125 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4126 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4127 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4128 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4129 | IsUpdateExprFound = XId == PossibleXId; |
| 4130 | if (IsUpdateExprFound) { |
| 4131 | V = BinOp->getLHS(); |
| 4132 | X = Checker.getX(); |
| 4133 | E = Checker.getExpr(); |
| 4134 | UE = Checker.getUpdateExpr(); |
| 4135 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4136 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4137 | } |
| 4138 | } |
| 4139 | } |
| 4140 | if (!IsUpdateExprFound) { |
| 4141 | // { v = x; x = expr; } |
| 4142 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 4143 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
| 4144 | ErrorFound = NotAnAssignmentOp; |
| 4145 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 4146 | : First->getLocStart(); |
| 4147 | NoteRange = ErrorRange = FirstBinOp |
| 4148 | ? FirstBinOp->getSourceRange() |
| 4149 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4150 | } else { |
| 4151 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 4152 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 4153 | ErrorFound = NotAnAssignmentOp; |
| 4154 | NoteLoc = ErrorLoc = SecondBinOp ? SecondBinOp->getOperatorLoc() |
| 4155 | : Second->getLocStart(); |
| 4156 | NoteRange = ErrorRange = SecondBinOp |
| 4157 | ? SecondBinOp->getSourceRange() |
| 4158 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4159 | } else { |
| 4160 | auto *PossibleXRHSInFirst = |
| 4161 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4162 | auto *PossibleXLHSInSecond = |
| 4163 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4164 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 4165 | PossibleXRHSInFirst->Profile(X1Id, Context, /*Canonical=*/true); |
| 4166 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 4167 | /*Canonical=*/true); |
| 4168 | IsUpdateExprFound = X1Id == X2Id; |
| 4169 | if (IsUpdateExprFound) { |
| 4170 | V = FirstBinOp->getLHS(); |
| 4171 | X = SecondBinOp->getLHS(); |
| 4172 | E = SecondBinOp->getRHS(); |
| 4173 | UE = nullptr; |
| 4174 | IsXLHSInRHSPart = false; |
| 4175 | IsPostfixUpdate = true; |
| 4176 | } else { |
| 4177 | ErrorFound = NotASpecificExpression; |
| 4178 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 4179 | ErrorRange = FirstBinOp->getSourceRange(); |
| 4180 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 4181 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 4182 | } |
| 4183 | } |
| 4184 | } |
| 4185 | } |
| 4186 | } else { |
| 4187 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4188 | NoteRange = ErrorRange = |
| 4189 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4190 | ErrorFound = NotTwoSubstatements; |
| 4191 | } |
| 4192 | } else { |
| 4193 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4194 | NoteRange = ErrorRange = |
| 4195 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4196 | ErrorFound = NotACompoundStatement; |
| 4197 | } |
| 4198 | if (ErrorFound != NoError) { |
| 4199 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 4200 | << ErrorRange; |
| 4201 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4202 | return StmtError(); |
| 4203 | } else if (CurContext->isDependentContext()) { |
| 4204 | UE = V = E = X = nullptr; |
| 4205 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4206 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4207 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4208 | |
| 4209 | getCurFunction()->setHasBranchProtectedScope(); |
| 4210 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4211 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4212 | X, V, E, UE, IsXLHSInRHSPart, |
| 4213 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4214 | } |
| 4215 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4216 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 4217 | Stmt *AStmt, |
| 4218 | SourceLocation StartLoc, |
| 4219 | SourceLocation EndLoc) { |
| 4220 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4221 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4222 | // OpenMP [2.16, Nesting of Regions] |
| 4223 | // If specified, a teams construct must be contained within a target |
| 4224 | // construct. That target construct must contain no statements or directives |
| 4225 | // outside of the teams construct. |
| 4226 | if (DSAStack->hasInnerTeamsRegion()) { |
| 4227 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 4228 | bool OMPTeamsFound = true; |
| 4229 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 4230 | auto I = CS->body_begin(); |
| 4231 | while (I != CS->body_end()) { |
| 4232 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 4233 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 4234 | OMPTeamsFound = false; |
| 4235 | break; |
| 4236 | } |
| 4237 | ++I; |
| 4238 | } |
| 4239 | assert(I != CS->body_end() && "Not found statement"); |
| 4240 | S = *I; |
| 4241 | } |
| 4242 | if (!OMPTeamsFound) { |
| 4243 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 4244 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 4245 | diag::note_omp_nested_teams_construct_here); |
| 4246 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 4247 | << isa<OMPExecutableDirective>(S); |
| 4248 | return StmtError(); |
| 4249 | } |
| 4250 | } |
| 4251 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4252 | getCurFunction()->setHasBranchProtectedScope(); |
| 4253 | |
| 4254 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4255 | } |
| 4256 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4257 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 4258 | Stmt *AStmt, SourceLocation StartLoc, |
| 4259 | SourceLocation EndLoc) { |
| 4260 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4261 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4262 | // 1.2.2 OpenMP Language Terminology |
| 4263 | // Structured block - An executable statement with a single entry at the |
| 4264 | // top and a single exit at the bottom. |
| 4265 | // The point of exit cannot be a branch out of the structured block. |
| 4266 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4267 | CS->getCapturedDecl()->setNothrow(); |
| 4268 | |
| 4269 | getCurFunction()->setHasBranchProtectedScope(); |
| 4270 | |
| 4271 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4272 | } |
| 4273 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 4274 | StmtResult |
| 4275 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 4276 | SourceLocation EndLoc, |
| 4277 | OpenMPDirectiveKind CancelRegion) { |
| 4278 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4279 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4280 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4281 | << getOpenMPDirectiveName(CancelRegion); |
| 4282 | return StmtError(); |
| 4283 | } |
| 4284 | if (DSAStack->isParentNowaitRegion()) { |
| 4285 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 4286 | return StmtError(); |
| 4287 | } |
| 4288 | if (DSAStack->isParentOrderedRegion()) { |
| 4289 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 4290 | return StmtError(); |
| 4291 | } |
| 4292 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 4293 | CancelRegion); |
| 4294 | } |
| 4295 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4296 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4297 | SourceLocation StartLoc, |
| 4298 | SourceLocation LParenLoc, |
| 4299 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4300 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4301 | switch (Kind) { |
| 4302 | case OMPC_if: |
| 4303 | Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4304 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4305 | case OMPC_final: |
| 4306 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4307 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4308 | case OMPC_num_threads: |
| 4309 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4310 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4311 | case OMPC_safelen: |
| 4312 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4313 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4314 | case OMPC_collapse: |
| 4315 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4316 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4317 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4318 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4319 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4320 | case OMPC_private: |
| 4321 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4322 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4323 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4324 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4325 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4326 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4327 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4328 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4329 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4330 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4331 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4332 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4333 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4334 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4335 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4336 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4337 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4338 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4339 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4340 | case OMPC_depend: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4341 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4342 | llvm_unreachable("Clause is not allowed."); |
| 4343 | } |
| 4344 | return Res; |
| 4345 | } |
| 4346 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4347 | OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4348 | SourceLocation LParenLoc, |
| 4349 | SourceLocation EndLoc) { |
| 4350 | Expr *ValExpr = Condition; |
| 4351 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 4352 | !Condition->isInstantiationDependent() && |
| 4353 | !Condition->containsUnexpandedParameterPack()) { |
| 4354 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4355 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4356 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4357 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4358 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4359 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 4363 | } |
| 4364 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4365 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 4366 | SourceLocation StartLoc, |
| 4367 | SourceLocation LParenLoc, |
| 4368 | SourceLocation EndLoc) { |
| 4369 | Expr *ValExpr = Condition; |
| 4370 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 4371 | !Condition->isInstantiationDependent() && |
| 4372 | !Condition->containsUnexpandedParameterPack()) { |
| 4373 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 4374 | Condition->getExprLoc(), Condition); |
| 4375 | if (Val.isInvalid()) |
| 4376 | return nullptr; |
| 4377 | |
| 4378 | ValExpr = Val.get(); |
| 4379 | } |
| 4380 | |
| 4381 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 4382 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4383 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 4384 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4385 | if (!Op) |
| 4386 | return ExprError(); |
| 4387 | |
| 4388 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 4389 | public: |
| 4390 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4391 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 4392 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 4393 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4394 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 4395 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4396 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 4397 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4398 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 4399 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4400 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 4401 | QualType T, |
| 4402 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4403 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 4404 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4405 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 4406 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4407 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4408 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4409 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4410 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 4411 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4412 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 4413 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4414 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 4415 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4416 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4417 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4418 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4419 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 4420 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4421 | llvm_unreachable("conversion functions are permitted"); |
| 4422 | } |
| 4423 | } ConvertDiagnoser; |
| 4424 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 4425 | } |
| 4426 | |
| 4427 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 4428 | SourceLocation StartLoc, |
| 4429 | SourceLocation LParenLoc, |
| 4430 | SourceLocation EndLoc) { |
| 4431 | Expr *ValExpr = NumThreads; |
| 4432 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4433 | !NumThreads->containsUnexpandedParameterPack()) { |
| 4434 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 4435 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4436 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4437 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4438 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4439 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4440 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4441 | |
| 4442 | // OpenMP [2.5, Restrictions] |
| 4443 | // The num_threads expression must evaluate to a positive integer value. |
| 4444 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4445 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 4446 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4447 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 4448 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4449 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4450 | } |
| 4451 | } |
| 4452 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4453 | return new (Context) |
| 4454 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4455 | } |
| 4456 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4457 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 4458 | OpenMPClauseKind CKind) { |
| 4459 | if (!E) |
| 4460 | return ExprError(); |
| 4461 | if (E->isValueDependent() || E->isTypeDependent() || |
| 4462 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 4463 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4464 | llvm::APSInt Result; |
| 4465 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 4466 | if (ICE.isInvalid()) |
| 4467 | return ExprError(); |
| 4468 | if (!Result.isStrictlyPositive()) { |
| 4469 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 4470 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 4471 | return ExprError(); |
| 4472 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 4473 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 4474 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 4475 | << E->getSourceRange(); |
| 4476 | return ExprError(); |
| 4477 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4478 | if (CKind == OMPC_collapse) { |
| 4479 | DSAStack->setCollapseNumber(Result.getExtValue()); |
| 4480 | } |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4481 | return ICE; |
| 4482 | } |
| 4483 | |
| 4484 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 4485 | SourceLocation LParenLoc, |
| 4486 | SourceLocation EndLoc) { |
| 4487 | // OpenMP [2.8.1, simd construct, Description] |
| 4488 | // The parameter of the safelen clause must be a constant |
| 4489 | // positive integer expression. |
| 4490 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 4491 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4492 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4493 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4494 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4495 | } |
| 4496 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4497 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 4498 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4499 | SourceLocation LParenLoc, |
| 4500 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4501 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4502 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4503 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4504 | // The parameter of the collapse clause must be a constant |
| 4505 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4506 | ExprResult NumForLoopsResult = |
| 4507 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 4508 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4509 | return nullptr; |
| 4510 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4511 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4512 | } |
| 4513 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4514 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 4515 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 4516 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4517 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4518 | switch (Kind) { |
| 4519 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4520 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4521 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 4522 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4523 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4524 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4525 | Res = ActOnOpenMPProcBindClause( |
| 4526 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 4527 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4528 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4529 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4530 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4531 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4532 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4533 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4534 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4535 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4536 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4537 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4538 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4539 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4540 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4541 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4542 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4543 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4544 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4545 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4546 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4547 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4548 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4549 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4550 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4551 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4552 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4553 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4554 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4555 | case OMPC_depend: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4556 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4557 | llvm_unreachable("Clause is not allowed."); |
| 4558 | } |
| 4559 | return Res; |
| 4560 | } |
| 4561 | |
| 4562 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 4563 | SourceLocation KindKwLoc, |
| 4564 | SourceLocation StartLoc, |
| 4565 | SourceLocation LParenLoc, |
| 4566 | SourceLocation EndLoc) { |
| 4567 | if (Kind == OMPC_DEFAULT_unknown) { |
| 4568 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4569 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 4570 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 4571 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4572 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4573 | Values += "'"; |
| 4574 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 4575 | Values += "'"; |
| 4576 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4577 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4578 | Values += " or "; |
| 4579 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4580 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4581 | break; |
| 4582 | default: |
| 4583 | Values += Sep; |
| 4584 | break; |
| 4585 | } |
| 4586 | } |
| 4587 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4588 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4589 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4590 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4591 | switch (Kind) { |
| 4592 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4593 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4594 | break; |
| 4595 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4596 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4597 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4598 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4599 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4600 | break; |
| 4601 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4602 | return new (Context) |
| 4603 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4604 | } |
| 4605 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4606 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 4607 | SourceLocation KindKwLoc, |
| 4608 | SourceLocation StartLoc, |
| 4609 | SourceLocation LParenLoc, |
| 4610 | SourceLocation EndLoc) { |
| 4611 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 4612 | std::string Values; |
| 4613 | std::string Sep(", "); |
| 4614 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 4615 | Values += "'"; |
| 4616 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 4617 | Values += "'"; |
| 4618 | switch (i) { |
| 4619 | case OMPC_PROC_BIND_unknown - 2: |
| 4620 | Values += " or "; |
| 4621 | break; |
| 4622 | case OMPC_PROC_BIND_unknown - 1: |
| 4623 | break; |
| 4624 | default: |
| 4625 | Values += Sep; |
| 4626 | break; |
| 4627 | } |
| 4628 | } |
| 4629 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4630 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4631 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4632 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4633 | return new (Context) |
| 4634 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4635 | } |
| 4636 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4637 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 4638 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 4639 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 4640 | SourceLocation ArgumentLoc, SourceLocation CommaLoc, |
| 4641 | SourceLocation EndLoc) { |
| 4642 | OMPClause *Res = nullptr; |
| 4643 | switch (Kind) { |
| 4644 | case OMPC_schedule: |
| 4645 | Res = ActOnOpenMPScheduleClause( |
| 4646 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
| 4647 | LParenLoc, ArgumentLoc, CommaLoc, EndLoc); |
| 4648 | break; |
| 4649 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4650 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4651 | case OMPC_num_threads: |
| 4652 | case OMPC_safelen: |
| 4653 | case OMPC_collapse: |
| 4654 | case OMPC_default: |
| 4655 | case OMPC_proc_bind: |
| 4656 | case OMPC_private: |
| 4657 | case OMPC_firstprivate: |
| 4658 | case OMPC_lastprivate: |
| 4659 | case OMPC_shared: |
| 4660 | case OMPC_reduction: |
| 4661 | case OMPC_linear: |
| 4662 | case OMPC_aligned: |
| 4663 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4664 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4665 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4666 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4667 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4668 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4669 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4670 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4671 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4672 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4673 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4674 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4675 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4676 | case OMPC_depend: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4677 | case OMPC_unknown: |
| 4678 | llvm_unreachable("Clause is not allowed."); |
| 4679 | } |
| 4680 | return Res; |
| 4681 | } |
| 4682 | |
| 4683 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 4684 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 4685 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 4686 | SourceLocation EndLoc) { |
| 4687 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 4688 | std::string Values; |
| 4689 | std::string Sep(", "); |
| 4690 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 4691 | Values += "'"; |
| 4692 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 4693 | Values += "'"; |
| 4694 | switch (i) { |
| 4695 | case OMPC_SCHEDULE_unknown - 2: |
| 4696 | Values += " or "; |
| 4697 | break; |
| 4698 | case OMPC_SCHEDULE_unknown - 1: |
| 4699 | break; |
| 4700 | default: |
| 4701 | Values += Sep; |
| 4702 | break; |
| 4703 | } |
| 4704 | } |
| 4705 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 4706 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 4707 | return nullptr; |
| 4708 | } |
| 4709 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4710 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4711 | if (ChunkSize) { |
| 4712 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 4713 | !ChunkSize->isInstantiationDependent() && |
| 4714 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 4715 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 4716 | ExprResult Val = |
| 4717 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 4718 | if (Val.isInvalid()) |
| 4719 | return nullptr; |
| 4720 | |
| 4721 | ValExpr = Val.get(); |
| 4722 | |
| 4723 | // OpenMP [2.7.1, Restrictions] |
| 4724 | // chunk_size must be a loop invariant integer expression with a positive |
| 4725 | // value. |
| 4726 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4727 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 4728 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 4729 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 4730 | << "schedule" << ChunkSize->getSourceRange(); |
| 4731 | return nullptr; |
| 4732 | } |
| 4733 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 4734 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 4735 | ChunkSize->getType(), ".chunk."); |
| 4736 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 4737 | ChunkSize->getExprLoc(), |
| 4738 | /*RefersToCapture=*/true); |
| 4739 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4740 | } |
| 4741 | } |
| 4742 | } |
| 4743 | |
| 4744 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4745 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4748 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 4749 | SourceLocation StartLoc, |
| 4750 | SourceLocation EndLoc) { |
| 4751 | OMPClause *Res = nullptr; |
| 4752 | switch (Kind) { |
| 4753 | case OMPC_ordered: |
| 4754 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 4755 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4756 | case OMPC_nowait: |
| 4757 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 4758 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4759 | case OMPC_untied: |
| 4760 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 4761 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4762 | case OMPC_mergeable: |
| 4763 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 4764 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4765 | case OMPC_read: |
| 4766 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 4767 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4768 | case OMPC_write: |
| 4769 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 4770 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4771 | case OMPC_update: |
| 4772 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 4773 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4774 | case OMPC_capture: |
| 4775 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 4776 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4777 | case OMPC_seq_cst: |
| 4778 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 4779 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4780 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4781 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4782 | case OMPC_num_threads: |
| 4783 | case OMPC_safelen: |
| 4784 | case OMPC_collapse: |
| 4785 | case OMPC_schedule: |
| 4786 | case OMPC_private: |
| 4787 | case OMPC_firstprivate: |
| 4788 | case OMPC_lastprivate: |
| 4789 | case OMPC_shared: |
| 4790 | case OMPC_reduction: |
| 4791 | case OMPC_linear: |
| 4792 | case OMPC_aligned: |
| 4793 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4794 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4795 | case OMPC_default: |
| 4796 | case OMPC_proc_bind: |
| 4797 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4798 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4799 | case OMPC_depend: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4800 | case OMPC_unknown: |
| 4801 | llvm_unreachable("Clause is not allowed."); |
| 4802 | } |
| 4803 | return Res; |
| 4804 | } |
| 4805 | |
| 4806 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 4807 | SourceLocation EndLoc) { |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4808 | DSAStack->setOrderedRegion(); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4809 | return new (Context) OMPOrderedClause(StartLoc, EndLoc); |
| 4810 | } |
| 4811 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4812 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 4813 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame^] | 4814 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4815 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 4816 | } |
| 4817 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4818 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 4819 | SourceLocation EndLoc) { |
| 4820 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 4821 | } |
| 4822 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4823 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 4824 | SourceLocation EndLoc) { |
| 4825 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 4826 | } |
| 4827 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4828 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 4829 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4830 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 4831 | } |
| 4832 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4833 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 4834 | SourceLocation EndLoc) { |
| 4835 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 4836 | } |
| 4837 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4838 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 4839 | SourceLocation EndLoc) { |
| 4840 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 4841 | } |
| 4842 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4843 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 4844 | SourceLocation EndLoc) { |
| 4845 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 4846 | } |
| 4847 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4848 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 4849 | SourceLocation EndLoc) { |
| 4850 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 4851 | } |
| 4852 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4853 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 4854 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 4855 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 4856 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4857 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
| 4858 | SourceLocation DepLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4859 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4860 | switch (Kind) { |
| 4861 | case OMPC_private: |
| 4862 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4863 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4864 | case OMPC_firstprivate: |
| 4865 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4866 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4867 | case OMPC_lastprivate: |
| 4868 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4869 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4870 | case OMPC_shared: |
| 4871 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4872 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4873 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4874 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 4875 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4876 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4877 | case OMPC_linear: |
| 4878 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 4879 | ColonLoc, EndLoc); |
| 4880 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4881 | case OMPC_aligned: |
| 4882 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 4883 | ColonLoc, EndLoc); |
| 4884 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4885 | case OMPC_copyin: |
| 4886 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4887 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4888 | case OMPC_copyprivate: |
| 4889 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4890 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4891 | case OMPC_flush: |
| 4892 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 4893 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4894 | case OMPC_depend: |
| 4895 | Res = ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList, StartLoc, |
| 4896 | LParenLoc, EndLoc); |
| 4897 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4898 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4899 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4900 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4901 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4902 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4903 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4904 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4905 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4906 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4907 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4908 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4909 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4910 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4911 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4912 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4913 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4914 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4915 | case OMPC_seq_cst: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4916 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4917 | llvm_unreachable("Clause is not allowed."); |
| 4918 | } |
| 4919 | return Res; |
| 4920 | } |
| 4921 | |
| 4922 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 4923 | SourceLocation StartLoc, |
| 4924 | SourceLocation LParenLoc, |
| 4925 | SourceLocation EndLoc) { |
| 4926 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4927 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4928 | for (auto &RefExpr : VarList) { |
| 4929 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 4930 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4931 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4932 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4933 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4934 | continue; |
| 4935 | } |
| 4936 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4937 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4938 | // OpenMP [2.1, C/C++] |
| 4939 | // A list item is a variable name. |
| 4940 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 4941 | // A variable that is part of another variable (as an array or |
| 4942 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4943 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4944 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4945 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4946 | continue; |
| 4947 | } |
| 4948 | Decl *D = DE->getDecl(); |
| 4949 | VarDecl *VD = cast<VarDecl>(D); |
| 4950 | |
| 4951 | QualType Type = VD->getType(); |
| 4952 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 4953 | // It will be analyzed later. |
| 4954 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 4955 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4956 | continue; |
| 4957 | } |
| 4958 | |
| 4959 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 4960 | // A variable that appears in a private clause must not have an incomplete |
| 4961 | // type or a reference type. |
| 4962 | if (RequireCompleteType(ELoc, Type, |
| 4963 | diag::err_omp_private_incomplete_type)) { |
| 4964 | continue; |
| 4965 | } |
| 4966 | if (Type->isReferenceType()) { |
| 4967 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4968 | << getOpenMPClauseName(OMPC_private) << Type; |
| 4969 | bool IsDecl = |
| 4970 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 4971 | Diag(VD->getLocation(), |
| 4972 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 4973 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4974 | continue; |
| 4975 | } |
| 4976 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4977 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4978 | // in a Construct] |
| 4979 | // Variables with the predetermined data-sharing attributes may not be |
| 4980 | // listed in data-sharing attributes clauses, except for the cases |
| 4981 | // listed below. For these exceptions only, listing a predetermined |
| 4982 | // variable in a data-sharing attribute clause is allowed and overrides |
| 4983 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4984 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4985 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4986 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 4987 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 4988 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4989 | continue; |
| 4990 | } |
| 4991 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 4992 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 4993 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 4994 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 4995 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 4996 | << getOpenMPClauseName(OMPC_private) << Type |
| 4997 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 4998 | bool IsDecl = |
| 4999 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5000 | Diag(VD->getLocation(), |
| 5001 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5002 | << VD; |
| 5003 | continue; |
| 5004 | } |
| 5005 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5006 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 5007 | // A variable of class type (or array thereof) that appears in a private |
| 5008 | // clause requires an accessible, unambiguous default constructor for the |
| 5009 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5010 | // Generate helper private variable and initialize it with the default |
| 5011 | // value. The address of the original variable is replaced by the address of |
| 5012 | // the new private variable in CodeGen. This new variable is not added to |
| 5013 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 5014 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5015 | Type = Type.getUnqualifiedType(); |
| 5016 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5017 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5018 | if (VDPrivate->isInvalidDecl()) |
| 5019 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5020 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5021 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5022 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5023 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5024 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5025 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5028 | if (Vars.empty()) |
| 5029 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5030 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5031 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 5032 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5033 | } |
| 5034 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5035 | namespace { |
| 5036 | class DiagsUninitializedSeveretyRAII { |
| 5037 | private: |
| 5038 | DiagnosticsEngine &Diags; |
| 5039 | SourceLocation SavedLoc; |
| 5040 | bool IsIgnored; |
| 5041 | |
| 5042 | public: |
| 5043 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 5044 | bool IsIgnored) |
| 5045 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 5046 | if (!IsIgnored) { |
| 5047 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 5048 | /*Map*/ diag::Severity::Ignored, Loc); |
| 5049 | } |
| 5050 | } |
| 5051 | ~DiagsUninitializedSeveretyRAII() { |
| 5052 | if (!IsIgnored) |
| 5053 | Diags.popMappings(SavedLoc); |
| 5054 | } |
| 5055 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 5056 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5057 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5058 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 5059 | SourceLocation StartLoc, |
| 5060 | SourceLocation LParenLoc, |
| 5061 | SourceLocation EndLoc) { |
| 5062 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5063 | SmallVector<Expr *, 8> PrivateCopies; |
| 5064 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5065 | bool IsImplicitClause = |
| 5066 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 5067 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 5068 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5069 | for (auto &RefExpr : VarList) { |
| 5070 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 5071 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5072 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5073 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5074 | PrivateCopies.push_back(nullptr); |
| 5075 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5076 | continue; |
| 5077 | } |
| 5078 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5079 | SourceLocation ELoc = |
| 5080 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5081 | // OpenMP [2.1, C/C++] |
| 5082 | // A list item is a variable name. |
| 5083 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5084 | // A variable that is part of another variable (as an array or |
| 5085 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5086 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5087 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5088 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5089 | continue; |
| 5090 | } |
| 5091 | Decl *D = DE->getDecl(); |
| 5092 | VarDecl *VD = cast<VarDecl>(D); |
| 5093 | |
| 5094 | QualType Type = VD->getType(); |
| 5095 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5096 | // It will be analyzed later. |
| 5097 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5098 | PrivateCopies.push_back(nullptr); |
| 5099 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5100 | continue; |
| 5101 | } |
| 5102 | |
| 5103 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5104 | // A variable that appears in a private clause must not have an incomplete |
| 5105 | // type or a reference type. |
| 5106 | if (RequireCompleteType(ELoc, Type, |
| 5107 | diag::err_omp_firstprivate_incomplete_type)) { |
| 5108 | continue; |
| 5109 | } |
| 5110 | if (Type->isReferenceType()) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5111 | if (IsImplicitClause) { |
| 5112 | Diag(ImplicitClauseLoc, |
| 5113 | diag::err_omp_task_predetermined_firstprivate_ref_type_arg) |
| 5114 | << Type; |
| 5115 | Diag(RefExpr->getExprLoc(), diag::note_used_here); |
| 5116 | } else { |
| 5117 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 5118 | << getOpenMPClauseName(OMPC_firstprivate) << Type; |
| 5119 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5120 | bool IsDecl = |
| 5121 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5122 | Diag(VD->getLocation(), |
| 5123 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5124 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5125 | continue; |
| 5126 | } |
| 5127 | |
| 5128 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 5129 | // 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] | 5130 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5131 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5132 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5133 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5134 | // If an implicit firstprivate variable found it was checked already. |
| 5135 | if (!IsImplicitClause) { |
| 5136 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5137 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5138 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 5139 | // A list item that specifies a given variable may not appear in more |
| 5140 | // than one clause on the same directive, except that a variable may be |
| 5141 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5142 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5143 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5144 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5145 | << getOpenMPClauseName(DVar.CKind) |
| 5146 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5147 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5148 | continue; |
| 5149 | } |
| 5150 | |
| 5151 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5152 | // in a Construct] |
| 5153 | // Variables with the predetermined data-sharing attributes may not be |
| 5154 | // listed in data-sharing attributes clauses, except for the cases |
| 5155 | // listed below. For these exceptions only, listing a predetermined |
| 5156 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5157 | // the variable's predetermined data-sharing attributes. |
| 5158 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5159 | // in a Construct, C/C++, p.2] |
| 5160 | // Variables with const-qualified type having no mutable member may be |
| 5161 | // listed in a firstprivate clause, even if they are static data members. |
| 5162 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 5163 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 5164 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5165 | << getOpenMPClauseName(DVar.CKind) |
| 5166 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5167 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5168 | continue; |
| 5169 | } |
| 5170 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5171 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5172 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 5173 | // A list item that is private within a parallel region must not appear |
| 5174 | // in a firstprivate clause on a worksharing construct if any of the |
| 5175 | // worksharing regions arising from the worksharing construct ever bind |
| 5176 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5177 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5178 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5179 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 5180 | if (DVar.CKind != OMPC_shared && |
| 5181 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5182 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5183 | Diag(ELoc, diag::err_omp_required_access) |
| 5184 | << getOpenMPClauseName(OMPC_firstprivate) |
| 5185 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5186 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5187 | continue; |
| 5188 | } |
| 5189 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5190 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 5191 | // A list item that appears in a reduction clause of a parallel construct |
| 5192 | // must not appear in a firstprivate clause on a worksharing or task |
| 5193 | // construct if any of the worksharing or task regions arising from the |
| 5194 | // worksharing or task construct ever bind to any of the parallel regions |
| 5195 | // arising from the parallel construct. |
| 5196 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 5197 | // A list item that appears in a reduction clause in worksharing |
| 5198 | // construct must not appear in a firstprivate clause in a task construct |
| 5199 | // encountered during execution of any of the worksharing regions arising |
| 5200 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5201 | if (CurrDir == OMPD_task) { |
| 5202 | DVar = |
| 5203 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 5204 | [](OpenMPDirectiveKind K) -> bool { |
| 5205 | return isOpenMPParallelDirective(K) || |
| 5206 | isOpenMPWorksharingDirective(K); |
| 5207 | }, |
| 5208 | false); |
| 5209 | if (DVar.CKind == OMPC_reduction && |
| 5210 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5211 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 5212 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 5213 | << getOpenMPDirectiveName(DVar.DKind); |
| 5214 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 5215 | continue; |
| 5216 | } |
| 5217 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5218 | } |
| 5219 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5220 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5221 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5222 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5223 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5224 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 5225 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5226 | bool IsDecl = |
| 5227 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5228 | Diag(VD->getLocation(), |
| 5229 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5230 | << VD; |
| 5231 | continue; |
| 5232 | } |
| 5233 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5234 | Type = Type.getUnqualifiedType(); |
| 5235 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName()); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5236 | // Generate helper private variable and initialize it with the value of the |
| 5237 | // original variable. The address of the original variable is replaced by |
| 5238 | // the address of the new private variable in the CodeGen. This new variable |
| 5239 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 5240 | // original variable for proper diagnostics and variable capturing. |
| 5241 | Expr *VDInitRefExpr = nullptr; |
| 5242 | // For arrays generate initializer for single element and replace it by the |
| 5243 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5244 | if (Type->isArrayType()) { |
| 5245 | auto VDInit = |
| 5246 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 5247 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5248 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5249 | ElemType = ElemType.getUnqualifiedType(); |
| 5250 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 5251 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5252 | InitializedEntity Entity = |
| 5253 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5254 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 5255 | |
| 5256 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 5257 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 5258 | if (Result.isInvalid()) |
| 5259 | VDPrivate->setInvalidDecl(); |
| 5260 | else |
| 5261 | VDPrivate->setInit(Result.getAs<Expr>()); |
| 5262 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5263 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5264 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5265 | VDInitRefExpr = |
| 5266 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5267 | AddInitializerToDecl(VDPrivate, |
| 5268 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 5269 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5270 | } |
| 5271 | if (VDPrivate->isInvalidDecl()) { |
| 5272 | if (IsImplicitClause) { |
| 5273 | Diag(DE->getExprLoc(), |
| 5274 | diag::note_omp_task_predetermined_firstprivate_here); |
| 5275 | } |
| 5276 | continue; |
| 5277 | } |
| 5278 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5279 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5280 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5281 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 5282 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5283 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 5284 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5285 | } |
| 5286 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5287 | if (Vars.empty()) |
| 5288 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5289 | |
| 5290 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5291 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5292 | } |
| 5293 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5294 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 5295 | SourceLocation StartLoc, |
| 5296 | SourceLocation LParenLoc, |
| 5297 | SourceLocation EndLoc) { |
| 5298 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5299 | SmallVector<Expr *, 8> SrcExprs; |
| 5300 | SmallVector<Expr *, 8> DstExprs; |
| 5301 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5302 | for (auto &RefExpr : VarList) { |
| 5303 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 5304 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5305 | // It will be analyzed later. |
| 5306 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5307 | SrcExprs.push_back(nullptr); |
| 5308 | DstExprs.push_back(nullptr); |
| 5309 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5310 | continue; |
| 5311 | } |
| 5312 | |
| 5313 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 5314 | // OpenMP [2.1, C/C++] |
| 5315 | // A list item is a variable name. |
| 5316 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 5317 | // A variable that is part of another variable (as an array or structure |
| 5318 | // element) cannot appear in a lastprivate clause. |
| 5319 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 5320 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5321 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 5322 | continue; |
| 5323 | } |
| 5324 | Decl *D = DE->getDecl(); |
| 5325 | VarDecl *VD = cast<VarDecl>(D); |
| 5326 | |
| 5327 | QualType Type = VD->getType(); |
| 5328 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5329 | // It will be analyzed later. |
| 5330 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5331 | SrcExprs.push_back(nullptr); |
| 5332 | DstExprs.push_back(nullptr); |
| 5333 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5334 | continue; |
| 5335 | } |
| 5336 | |
| 5337 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 5338 | // A variable that appears in a lastprivate clause must not have an |
| 5339 | // incomplete type or a reference type. |
| 5340 | if (RequireCompleteType(ELoc, Type, |
| 5341 | diag::err_omp_lastprivate_incomplete_type)) { |
| 5342 | continue; |
| 5343 | } |
| 5344 | if (Type->isReferenceType()) { |
| 5345 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 5346 | << getOpenMPClauseName(OMPC_lastprivate) << Type; |
| 5347 | bool IsDecl = |
| 5348 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5349 | Diag(VD->getLocation(), |
| 5350 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5351 | << VD; |
| 5352 | continue; |
| 5353 | } |
| 5354 | |
| 5355 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5356 | // in a Construct] |
| 5357 | // Variables with the predetermined data-sharing attributes may not be |
| 5358 | // listed in data-sharing attributes clauses, except for the cases |
| 5359 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5360 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5361 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 5362 | DVar.CKind != OMPC_firstprivate && |
| 5363 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 5364 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 5365 | << getOpenMPClauseName(DVar.CKind) |
| 5366 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5367 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5368 | continue; |
| 5369 | } |
| 5370 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5371 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 5372 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 5373 | // A list item that is private within a parallel region, or that appears in |
| 5374 | // the reduction clause of a parallel construct, must not appear in a |
| 5375 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 5376 | // worksharing regions ever binds to any of the corresponding parallel |
| 5377 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5378 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5379 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5380 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5381 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5382 | if (DVar.CKind != OMPC_shared) { |
| 5383 | Diag(ELoc, diag::err_omp_required_access) |
| 5384 | << getOpenMPClauseName(OMPC_lastprivate) |
| 5385 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5386 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5387 | continue; |
| 5388 | } |
| 5389 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5390 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5391 | // A variable of class type (or array thereof) that appears in a |
| 5392 | // lastprivate clause requires an accessible, unambiguous default |
| 5393 | // constructor for the class type, unless the list item is also specified |
| 5394 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5395 | // A variable of class type (or array thereof) that appears in a |
| 5396 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 5397 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5398 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5399 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5400 | Type.getUnqualifiedType(), ".lastprivate.src"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5401 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 5402 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5403 | auto *DstVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5404 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst"); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5405 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5406 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5407 | // For arrays generate assignment operation for single element and replace |
| 5408 | // it by the original array element in CodeGen. |
| 5409 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 5410 | PseudoDstExpr, PseudoSrcExpr); |
| 5411 | if (AssignmentOp.isInvalid()) |
| 5412 | continue; |
| 5413 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 5414 | /*DiscardedValue=*/true); |
| 5415 | if (AssignmentOp.isInvalid()) |
| 5416 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5417 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5418 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5419 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5420 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5421 | SrcExprs.push_back(PseudoSrcExpr); |
| 5422 | DstExprs.push_back(PseudoDstExpr); |
| 5423 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5424 | } |
| 5425 | |
| 5426 | if (Vars.empty()) |
| 5427 | return nullptr; |
| 5428 | |
| 5429 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5430 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5431 | } |
| 5432 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5433 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 5434 | SourceLocation StartLoc, |
| 5435 | SourceLocation LParenLoc, |
| 5436 | SourceLocation EndLoc) { |
| 5437 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5438 | for (auto &RefExpr : VarList) { |
| 5439 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 5440 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5441 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5442 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5443 | continue; |
| 5444 | } |
| 5445 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5446 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5447 | // OpenMP [2.1, C/C++] |
| 5448 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 5449 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 5450 | // A variable that is part of another variable (as an array or structure |
| 5451 | // element) cannot appear in a shared unless it is a static data member |
| 5452 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5453 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5454 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5455 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5456 | continue; |
| 5457 | } |
| 5458 | Decl *D = DE->getDecl(); |
| 5459 | VarDecl *VD = cast<VarDecl>(D); |
| 5460 | |
| 5461 | QualType Type = VD->getType(); |
| 5462 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5463 | // It will be analyzed later. |
| 5464 | Vars.push_back(DE); |
| 5465 | continue; |
| 5466 | } |
| 5467 | |
| 5468 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5469 | // in a Construct] |
| 5470 | // Variables with the predetermined data-sharing attributes may not be |
| 5471 | // listed in data-sharing attributes clauses, except for the cases |
| 5472 | // listed below. For these exceptions only, listing a predetermined |
| 5473 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5474 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5475 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5476 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 5477 | DVar.RefExpr) { |
| 5478 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5479 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5480 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5481 | continue; |
| 5482 | } |
| 5483 | |
| 5484 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 5485 | Vars.push_back(DE); |
| 5486 | } |
| 5487 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5488 | if (Vars.empty()) |
| 5489 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5490 | |
| 5491 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 5492 | } |
| 5493 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5494 | namespace { |
| 5495 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 5496 | DSAStackTy *Stack; |
| 5497 | |
| 5498 | public: |
| 5499 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 5500 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5501 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5502 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 5503 | return false; |
| 5504 | if (DVar.CKind != OMPC_unknown) |
| 5505 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5506 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5507 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5508 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5509 | return true; |
| 5510 | return false; |
| 5511 | } |
| 5512 | return false; |
| 5513 | } |
| 5514 | bool VisitStmt(Stmt *S) { |
| 5515 | for (auto Child : S->children()) { |
| 5516 | if (Child && Visit(Child)) |
| 5517 | return true; |
| 5518 | } |
| 5519 | return false; |
| 5520 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5521 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5522 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5523 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5524 | |
| 5525 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 5526 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 5527 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 5528 | CXXScopeSpec &ReductionIdScopeSpec, |
| 5529 | const DeclarationNameInfo &ReductionId) { |
| 5530 | // TODO: Allow scope specification search when 'declare reduction' is |
| 5531 | // supported. |
| 5532 | assert(ReductionIdScopeSpec.isEmpty() && |
| 5533 | "No support for scoped reduction identifiers yet."); |
| 5534 | |
| 5535 | auto DN = ReductionId.getName(); |
| 5536 | auto OOK = DN.getCXXOverloadedOperator(); |
| 5537 | BinaryOperatorKind BOK = BO_Comma; |
| 5538 | |
| 5539 | // OpenMP [2.14.3.6, reduction clause] |
| 5540 | // C |
| 5541 | // reduction-identifier is either an identifier or one of the following |
| 5542 | // operators: +, -, *, &, |, ^, && and || |
| 5543 | // C++ |
| 5544 | // reduction-identifier is either an id-expression or one of the following |
| 5545 | // operators: +, -, *, &, |, ^, && and || |
| 5546 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 5547 | switch (OOK) { |
| 5548 | case OO_Plus: |
| 5549 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5550 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5551 | break; |
| 5552 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5553 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5554 | break; |
| 5555 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5556 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5557 | break; |
| 5558 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5559 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5560 | break; |
| 5561 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5562 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5563 | break; |
| 5564 | case OO_AmpAmp: |
| 5565 | BOK = BO_LAnd; |
| 5566 | break; |
| 5567 | case OO_PipePipe: |
| 5568 | BOK = BO_LOr; |
| 5569 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5570 | case OO_New: |
| 5571 | case OO_Delete: |
| 5572 | case OO_Array_New: |
| 5573 | case OO_Array_Delete: |
| 5574 | case OO_Slash: |
| 5575 | case OO_Percent: |
| 5576 | case OO_Tilde: |
| 5577 | case OO_Exclaim: |
| 5578 | case OO_Equal: |
| 5579 | case OO_Less: |
| 5580 | case OO_Greater: |
| 5581 | case OO_LessEqual: |
| 5582 | case OO_GreaterEqual: |
| 5583 | case OO_PlusEqual: |
| 5584 | case OO_MinusEqual: |
| 5585 | case OO_StarEqual: |
| 5586 | case OO_SlashEqual: |
| 5587 | case OO_PercentEqual: |
| 5588 | case OO_CaretEqual: |
| 5589 | case OO_AmpEqual: |
| 5590 | case OO_PipeEqual: |
| 5591 | case OO_LessLess: |
| 5592 | case OO_GreaterGreater: |
| 5593 | case OO_LessLessEqual: |
| 5594 | case OO_GreaterGreaterEqual: |
| 5595 | case OO_EqualEqual: |
| 5596 | case OO_ExclaimEqual: |
| 5597 | case OO_PlusPlus: |
| 5598 | case OO_MinusMinus: |
| 5599 | case OO_Comma: |
| 5600 | case OO_ArrowStar: |
| 5601 | case OO_Arrow: |
| 5602 | case OO_Call: |
| 5603 | case OO_Subscript: |
| 5604 | case OO_Conditional: |
| 5605 | case NUM_OVERLOADED_OPERATORS: |
| 5606 | llvm_unreachable("Unexpected reduction identifier"); |
| 5607 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5608 | if (auto II = DN.getAsIdentifierInfo()) { |
| 5609 | if (II->isStr("max")) |
| 5610 | BOK = BO_GT; |
| 5611 | else if (II->isStr("min")) |
| 5612 | BOK = BO_LT; |
| 5613 | } |
| 5614 | break; |
| 5615 | } |
| 5616 | SourceRange ReductionIdRange; |
| 5617 | if (ReductionIdScopeSpec.isValid()) { |
| 5618 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 5619 | } |
| 5620 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 5621 | if (BOK == BO_Comma) { |
| 5622 | // Not allowed reduction identifier is found. |
| 5623 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 5624 | << ReductionIdRange; |
| 5625 | return nullptr; |
| 5626 | } |
| 5627 | |
| 5628 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5629 | SmallVector<Expr *, 8> LHSs; |
| 5630 | SmallVector<Expr *, 8> RHSs; |
| 5631 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5632 | for (auto RefExpr : VarList) { |
| 5633 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 5634 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5635 | // It will be analyzed later. |
| 5636 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5637 | LHSs.push_back(nullptr); |
| 5638 | RHSs.push_back(nullptr); |
| 5639 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5640 | continue; |
| 5641 | } |
| 5642 | |
| 5643 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 5644 | RefExpr->isInstantiationDependent() || |
| 5645 | RefExpr->containsUnexpandedParameterPack()) { |
| 5646 | // It will be analyzed later. |
| 5647 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5648 | LHSs.push_back(nullptr); |
| 5649 | RHSs.push_back(nullptr); |
| 5650 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5651 | continue; |
| 5652 | } |
| 5653 | |
| 5654 | auto ELoc = RefExpr->getExprLoc(); |
| 5655 | auto ERange = RefExpr->getSourceRange(); |
| 5656 | // OpenMP [2.1, C/C++] |
| 5657 | // A list item is a variable or array section, subject to the restrictions |
| 5658 | // specified in Section 2.4 on page 42 and in each of the sections |
| 5659 | // describing clauses and directives for which a list appears. |
| 5660 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 5661 | // A variable that is part of another variable (as an array or |
| 5662 | // structure element) cannot appear in a private clause. |
| 5663 | auto DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 5664 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5665 | Diag(ELoc, diag::err_omp_expected_var_name) << ERange; |
| 5666 | continue; |
| 5667 | } |
| 5668 | auto D = DE->getDecl(); |
| 5669 | auto VD = cast<VarDecl>(D); |
| 5670 | auto Type = VD->getType(); |
| 5671 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5672 | // A variable that appears in a private clause must not have an incomplete |
| 5673 | // type or a reference type. |
| 5674 | if (RequireCompleteType(ELoc, Type, |
| 5675 | diag::err_omp_reduction_incomplete_type)) |
| 5676 | continue; |
| 5677 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5678 | // Arrays may not appear in a reduction clause. |
| 5679 | if (Type.getNonReferenceType()->isArrayType()) { |
| 5680 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
| 5681 | bool IsDecl = |
| 5682 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5683 | Diag(VD->getLocation(), |
| 5684 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5685 | << VD; |
| 5686 | continue; |
| 5687 | } |
| 5688 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5689 | // A list item that appears in a reduction clause must not be |
| 5690 | // const-qualified. |
| 5691 | if (Type.getNonReferenceType().isConstant(Context)) { |
| 5692 | Diag(ELoc, diag::err_omp_const_variable) |
| 5693 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
| 5694 | bool IsDecl = |
| 5695 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5696 | Diag(VD->getLocation(), |
| 5697 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5698 | << VD; |
| 5699 | continue; |
| 5700 | } |
| 5701 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 5702 | // If a list-item is a reference type then it must bind to the same object |
| 5703 | // for all threads of the team. |
| 5704 | VarDecl *VDDef = VD->getDefinition(); |
| 5705 | if (Type->isReferenceType() && VDDef) { |
| 5706 | DSARefChecker Check(DSAStack); |
| 5707 | if (Check.Visit(VDDef->getInit())) { |
| 5708 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 5709 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 5710 | continue; |
| 5711 | } |
| 5712 | } |
| 5713 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5714 | // The type of a list item that appears in a reduction clause must be valid |
| 5715 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 5716 | // of the list item must be an allowed arithmetic data type: char, int, |
| 5717 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 5718 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 5719 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 5720 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 5721 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 5722 | !(Type->isScalarType() || |
| 5723 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 5724 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 5725 | << getLangOpts().CPlusPlus; |
| 5726 | bool IsDecl = |
| 5727 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5728 | Diag(VD->getLocation(), |
| 5729 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5730 | << VD; |
| 5731 | continue; |
| 5732 | } |
| 5733 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 5734 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 5735 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 5736 | bool IsDecl = |
| 5737 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5738 | Diag(VD->getLocation(), |
| 5739 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5740 | << VD; |
| 5741 | continue; |
| 5742 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5743 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5744 | // in a Construct] |
| 5745 | // Variables with the predetermined data-sharing attributes may not be |
| 5746 | // listed in data-sharing attributes clauses, except for the cases |
| 5747 | // listed below. For these exceptions only, listing a predetermined |
| 5748 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5749 | // the variable's predetermined data-sharing attributes. |
| 5750 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 5751 | // Any number of reduction clauses can be specified on the directive, |
| 5752 | // but a list item can appear only once in the reduction clauses for that |
| 5753 | // directive. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5754 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5755 | if (DVar.CKind == OMPC_reduction) { |
| 5756 | Diag(ELoc, diag::err_omp_once_referenced) |
| 5757 | << getOpenMPClauseName(OMPC_reduction); |
| 5758 | if (DVar.RefExpr) { |
| 5759 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 5760 | } |
| 5761 | } else if (DVar.CKind != OMPC_unknown) { |
| 5762 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 5763 | << getOpenMPClauseName(DVar.CKind) |
| 5764 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5765 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5766 | continue; |
| 5767 | } |
| 5768 | |
| 5769 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 5770 | // A list item that appears in a reduction clause of a worksharing |
| 5771 | // construct must be shared in the parallel regions to which any of the |
| 5772 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5773 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5774 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5775 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5776 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5777 | if (DVar.CKind != OMPC_shared) { |
| 5778 | Diag(ELoc, diag::err_omp_required_access) |
| 5779 | << getOpenMPClauseName(OMPC_reduction) |
| 5780 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5781 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5782 | continue; |
| 5783 | } |
| 5784 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5785 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5786 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs"); |
| 5787 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5788 | // Add initializer for private variable. |
| 5789 | Expr *Init = nullptr; |
| 5790 | switch (BOK) { |
| 5791 | case BO_Add: |
| 5792 | case BO_Xor: |
| 5793 | case BO_Or: |
| 5794 | case BO_LOr: |
| 5795 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 5796 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 5797 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5798 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5799 | break; |
| 5800 | case BO_Mul: |
| 5801 | case BO_LAnd: |
| 5802 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 5803 | // '*' and '&&' reduction ops - initializer is '1'. |
| 5804 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 5805 | } |
| 5806 | break; |
| 5807 | case BO_And: { |
| 5808 | // '&' reduction op - initializer is '~0'. |
| 5809 | QualType OrigType = Type; |
| 5810 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 5811 | Type = ComplexTy->getElementType(); |
| 5812 | } |
| 5813 | if (Type->isRealFloatingType()) { |
| 5814 | llvm::APFloat InitValue = |
| 5815 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 5816 | /*isIEEE=*/true); |
| 5817 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 5818 | Type, ELoc); |
| 5819 | } else if (Type->isScalarType()) { |
| 5820 | auto Size = Context.getTypeSize(Type); |
| 5821 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 5822 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 5823 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 5824 | } |
| 5825 | if (Init && OrigType->isAnyComplexType()) { |
| 5826 | // Init = 0xFFFF + 0xFFFFi; |
| 5827 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 5828 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 5829 | } |
| 5830 | Type = OrigType; |
| 5831 | break; |
| 5832 | } |
| 5833 | case BO_LT: |
| 5834 | case BO_GT: { |
| 5835 | // 'min' reduction op - initializer is 'Largest representable number in |
| 5836 | // the reduction list item type'. |
| 5837 | // 'max' reduction op - initializer is 'Least representable number in |
| 5838 | // the reduction list item type'. |
| 5839 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 5840 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 5841 | auto Size = Context.getTypeSize(Type); |
| 5842 | QualType IntTy = |
| 5843 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 5844 | llvm::APInt InitValue = |
| 5845 | (BOK != BO_LT) |
| 5846 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 5847 | : llvm::APInt::getMinValue(Size) |
| 5848 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 5849 | : llvm::APInt::getMaxValue(Size); |
| 5850 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 5851 | if (Type->isPointerType()) { |
| 5852 | // Cast to pointer type. |
| 5853 | auto CastExpr = BuildCStyleCastExpr( |
| 5854 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 5855 | SourceLocation(), Init); |
| 5856 | if (CastExpr.isInvalid()) |
| 5857 | continue; |
| 5858 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5859 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5860 | } else if (Type->isRealFloatingType()) { |
| 5861 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 5862 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 5863 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 5864 | Type, ELoc); |
| 5865 | } |
| 5866 | break; |
| 5867 | } |
| 5868 | case BO_PtrMemD: |
| 5869 | case BO_PtrMemI: |
| 5870 | case BO_MulAssign: |
| 5871 | case BO_Div: |
| 5872 | case BO_Rem: |
| 5873 | case BO_Sub: |
| 5874 | case BO_Shl: |
| 5875 | case BO_Shr: |
| 5876 | case BO_LE: |
| 5877 | case BO_GE: |
| 5878 | case BO_EQ: |
| 5879 | case BO_NE: |
| 5880 | case BO_AndAssign: |
| 5881 | case BO_XorAssign: |
| 5882 | case BO_OrAssign: |
| 5883 | case BO_Assign: |
| 5884 | case BO_AddAssign: |
| 5885 | case BO_SubAssign: |
| 5886 | case BO_DivAssign: |
| 5887 | case BO_RemAssign: |
| 5888 | case BO_ShlAssign: |
| 5889 | case BO_ShrAssign: |
| 5890 | case BO_Comma: |
| 5891 | llvm_unreachable("Unexpected reduction operation"); |
| 5892 | } |
| 5893 | if (Init) { |
| 5894 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 5895 | /*TypeMayContainAuto=*/false); |
| 5896 | } else { |
| 5897 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
| 5898 | } |
| 5899 | if (!RHSVD->hasInit()) { |
| 5900 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 5901 | << ReductionIdRange; |
| 5902 | bool IsDecl = |
| 5903 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5904 | Diag(VD->getLocation(), |
| 5905 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5906 | << VD; |
| 5907 | continue; |
| 5908 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5909 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 5910 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5911 | ExprResult ReductionOp = |
| 5912 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 5913 | LHSDRE, RHSDRE); |
| 5914 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 5915 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5916 | ReductionOp = |
| 5917 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 5918 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 5919 | } else { |
| 5920 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 5921 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 5922 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 5923 | ReductionOp = |
| 5924 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 5925 | BO_Assign, LHSDRE, ConditionalOp); |
| 5926 | } |
| 5927 | if (ReductionOp.isUsable()) { |
| 5928 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5929 | } |
| 5930 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5931 | if (ReductionOp.isInvalid()) |
| 5932 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5933 | |
| 5934 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 5935 | Vars.push_back(DE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5936 | LHSs.push_back(LHSDRE); |
| 5937 | RHSs.push_back(RHSDRE); |
| 5938 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | if (Vars.empty()) |
| 5942 | return nullptr; |
| 5943 | |
| 5944 | return OMPReductionClause::Create( |
| 5945 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5946 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, LHSs, |
| 5947 | RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5948 | } |
| 5949 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5950 | OMPClause *Sema::ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 5951 | SourceLocation StartLoc, |
| 5952 | SourceLocation LParenLoc, |
| 5953 | SourceLocation ColonLoc, |
| 5954 | SourceLocation EndLoc) { |
| 5955 | SmallVector<Expr *, 8> Vars; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5956 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5957 | for (auto &RefExpr : VarList) { |
| 5958 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 5959 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5960 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5961 | Vars.push_back(RefExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5962 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5963 | continue; |
| 5964 | } |
| 5965 | |
| 5966 | // OpenMP [2.14.3.7, linear clause] |
| 5967 | // A list item that appears in a linear clause is subject to the private |
| 5968 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 5969 | // noted. In addition, the value of the new list item on each iteration |
| 5970 | // of the associated loop(s) corresponds to the value of the original |
| 5971 | // list item before entering the construct plus the logical number of |
| 5972 | // the iteration times linear-step. |
| 5973 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5974 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5975 | // OpenMP [2.1, C/C++] |
| 5976 | // A list item is a variable name. |
| 5977 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 5978 | // A variable that is part of another variable (as an array or |
| 5979 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5980 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5981 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5982 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5983 | continue; |
| 5984 | } |
| 5985 | |
| 5986 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 5987 | |
| 5988 | // OpenMP [2.14.3.7, linear clause] |
| 5989 | // A list-item cannot appear in more than one linear clause. |
| 5990 | // A list-item that appears in a linear clause cannot appear in any |
| 5991 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5992 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5993 | if (DVar.RefExpr) { |
| 5994 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5995 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5996 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5997 | continue; |
| 5998 | } |
| 5999 | |
| 6000 | QualType QType = VD->getType(); |
| 6001 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 6002 | // It will be analyzed later. |
| 6003 | Vars.push_back(DE); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6004 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6005 | continue; |
| 6006 | } |
| 6007 | |
| 6008 | // A variable must not have an incomplete type or a reference type. |
| 6009 | if (RequireCompleteType(ELoc, QType, |
| 6010 | diag::err_omp_linear_incomplete_type)) { |
| 6011 | continue; |
| 6012 | } |
| 6013 | if (QType->isReferenceType()) { |
| 6014 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 6015 | << getOpenMPClauseName(OMPC_linear) << QType; |
| 6016 | bool IsDecl = |
| 6017 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6018 | Diag(VD->getLocation(), |
| 6019 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6020 | << VD; |
| 6021 | continue; |
| 6022 | } |
| 6023 | |
| 6024 | // A list item must not be const-qualified. |
| 6025 | if (QType.isConstant(Context)) { |
| 6026 | Diag(ELoc, diag::err_omp_const_variable) |
| 6027 | << getOpenMPClauseName(OMPC_linear); |
| 6028 | bool IsDecl = |
| 6029 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6030 | Diag(VD->getLocation(), |
| 6031 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6032 | << VD; |
| 6033 | continue; |
| 6034 | } |
| 6035 | |
| 6036 | // A list item must be of integral or pointer type. |
| 6037 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 6038 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6039 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 6040 | !Ty->isPointerType())) { |
| 6041 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 6042 | bool IsDecl = |
| 6043 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6044 | Diag(VD->getLocation(), |
| 6045 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6046 | << VD; |
| 6047 | continue; |
| 6048 | } |
| 6049 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6050 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6051 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6052 | AddInitializerToDecl(Init, DefaultLvalueConversion(DE).get(), |
| 6053 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6054 | auto InitRef = buildDeclRefExpr( |
| 6055 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6056 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 6057 | Vars.push_back(DE); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6058 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6059 | } |
| 6060 | |
| 6061 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6062 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6063 | |
| 6064 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6065 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6066 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 6067 | !Step->isInstantiationDependent() && |
| 6068 | !Step->containsUnexpandedParameterPack()) { |
| 6069 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6070 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6071 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6072 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6073 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6074 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6075 | // Build var to save the step value. |
| 6076 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6077 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6078 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6079 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6080 | ExprResult CalcStep = |
| 6081 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
| 6082 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6083 | // Warn about zero linear step (it would be probably better specified as |
| 6084 | // making corresponding variables 'const'). |
| 6085 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6086 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 6087 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6088 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 6089 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6090 | if (!IsConstant && CalcStep.isUsable()) { |
| 6091 | // Calculate the step beforehand instead of doing this on each iteration. |
| 6092 | // (This is not used if the number of iterations may be kfold-ed). |
| 6093 | CalcStepExpr = CalcStep.get(); |
| 6094 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, ColonLoc, EndLoc, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6098 | Vars, Inits, StepExpr, CalcStepExpr); |
| 6099 | } |
| 6100 | |
| 6101 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 6102 | Expr *NumIterations, Sema &SemaRef, |
| 6103 | Scope *S) { |
| 6104 | // Walk the vars and build update/final expressions for the CodeGen. |
| 6105 | SmallVector<Expr *, 8> Updates; |
| 6106 | SmallVector<Expr *, 8> Finals; |
| 6107 | Expr *Step = Clause.getStep(); |
| 6108 | Expr *CalcStep = Clause.getCalcStep(); |
| 6109 | // OpenMP [2.14.3.7, linear clause] |
| 6110 | // If linear-step is not specified it is assumed to be 1. |
| 6111 | if (Step == nullptr) |
| 6112 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 6113 | else if (CalcStep) |
| 6114 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 6115 | bool HasErrors = false; |
| 6116 | auto CurInit = Clause.inits().begin(); |
| 6117 | for (auto &RefExpr : Clause.varlists()) { |
| 6118 | Expr *InitExpr = *CurInit; |
| 6119 | |
| 6120 | // Build privatized reference to the current linear var. |
| 6121 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6122 | auto PrivateRef = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6123 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 6124 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 6125 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6126 | |
| 6127 | // Build update: Var = InitExpr + IV * Step |
| 6128 | ExprResult Update = |
| 6129 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), PrivateRef, |
| 6130 | InitExpr, IV, Step, /* Subtract */ false); |
| 6131 | Update = SemaRef.ActOnFinishFullExpr(Update.get()); |
| 6132 | |
| 6133 | // Build final: Var = InitExpr + NumIterations * Step |
| 6134 | ExprResult Final = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6135 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), PrivateRef, |
| 6136 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6137 | Final = SemaRef.ActOnFinishFullExpr(Final.get()); |
| 6138 | if (!Update.isUsable() || !Final.isUsable()) { |
| 6139 | Updates.push_back(nullptr); |
| 6140 | Finals.push_back(nullptr); |
| 6141 | HasErrors = true; |
| 6142 | } else { |
| 6143 | Updates.push_back(Update.get()); |
| 6144 | Finals.push_back(Final.get()); |
| 6145 | } |
| 6146 | ++CurInit; |
| 6147 | } |
| 6148 | Clause.setUpdates(Updates); |
| 6149 | Clause.setFinals(Finals); |
| 6150 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6151 | } |
| 6152 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6153 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 6154 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 6155 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 6156 | |
| 6157 | SmallVector<Expr *, 8> Vars; |
| 6158 | for (auto &RefExpr : VarList) { |
| 6159 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 6160 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6161 | // It will be analyzed later. |
| 6162 | Vars.push_back(RefExpr); |
| 6163 | continue; |
| 6164 | } |
| 6165 | |
| 6166 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6167 | // OpenMP [2.1, C/C++] |
| 6168 | // A list item is a variable name. |
| 6169 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6170 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6171 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6172 | continue; |
| 6173 | } |
| 6174 | |
| 6175 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6176 | |
| 6177 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6178 | // The type of list items appearing in the aligned clause must be |
| 6179 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6180 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6181 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6182 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6183 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 6184 | !Ty->isPointerType())) { |
| 6185 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 6186 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 6187 | bool IsDecl = |
| 6188 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6189 | Diag(VD->getLocation(), |
| 6190 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6191 | << VD; |
| 6192 | continue; |
| 6193 | } |
| 6194 | |
| 6195 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6196 | // A list-item cannot appear in more than one aligned clause. |
| 6197 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 6198 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 6199 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 6200 | << getOpenMPClauseName(OMPC_aligned); |
| 6201 | continue; |
| 6202 | } |
| 6203 | |
| 6204 | Vars.push_back(DE); |
| 6205 | } |
| 6206 | |
| 6207 | // OpenMP [2.8.1, simd construct, Description] |
| 6208 | // The parameter of the aligned clause, alignment, must be a constant |
| 6209 | // positive integer expression. |
| 6210 | // If no optional parameter is specified, implementation-defined default |
| 6211 | // alignments for SIMD instructions on the target platforms are assumed. |
| 6212 | if (Alignment != nullptr) { |
| 6213 | ExprResult AlignResult = |
| 6214 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 6215 | if (AlignResult.isInvalid()) |
| 6216 | return nullptr; |
| 6217 | Alignment = AlignResult.get(); |
| 6218 | } |
| 6219 | if (Vars.empty()) |
| 6220 | return nullptr; |
| 6221 | |
| 6222 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 6223 | EndLoc, Vars, Alignment); |
| 6224 | } |
| 6225 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6226 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 6227 | SourceLocation StartLoc, |
| 6228 | SourceLocation LParenLoc, |
| 6229 | SourceLocation EndLoc) { |
| 6230 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6231 | SmallVector<Expr *, 8> SrcExprs; |
| 6232 | SmallVector<Expr *, 8> DstExprs; |
| 6233 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6234 | for (auto &RefExpr : VarList) { |
| 6235 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 6236 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6237 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6238 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6239 | SrcExprs.push_back(nullptr); |
| 6240 | DstExprs.push_back(nullptr); |
| 6241 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6242 | continue; |
| 6243 | } |
| 6244 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6245 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6246 | // OpenMP [2.1, C/C++] |
| 6247 | // A list item is a variable name. |
| 6248 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6249 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6250 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6251 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6252 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6253 | continue; |
| 6254 | } |
| 6255 | |
| 6256 | Decl *D = DE->getDecl(); |
| 6257 | VarDecl *VD = cast<VarDecl>(D); |
| 6258 | |
| 6259 | QualType Type = VD->getType(); |
| 6260 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6261 | // It will be analyzed later. |
| 6262 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6263 | SrcExprs.push_back(nullptr); |
| 6264 | DstExprs.push_back(nullptr); |
| 6265 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6266 | continue; |
| 6267 | } |
| 6268 | |
| 6269 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 6270 | // A list item that appears in a copyin clause must be threadprivate. |
| 6271 | if (!DSAStack->isThreadPrivate(VD)) { |
| 6272 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6273 | << getOpenMPClauseName(OMPC_copyin) |
| 6274 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6275 | continue; |
| 6276 | } |
| 6277 | |
| 6278 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6279 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6280 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6281 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6282 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6283 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6284 | ElemType.getUnqualifiedType(), ".copyin.src"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6285 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6286 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 6287 | auto *DstVD = |
| 6288 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst"); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6289 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6290 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6291 | // For arrays generate assignment operation for single element and replace |
| 6292 | // it by the original array element in CodeGen. |
| 6293 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6294 | PseudoDstExpr, PseudoSrcExpr); |
| 6295 | if (AssignmentOp.isInvalid()) |
| 6296 | continue; |
| 6297 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6298 | /*DiscardedValue=*/true); |
| 6299 | if (AssignmentOp.isInvalid()) |
| 6300 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6301 | |
| 6302 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 6303 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6304 | SrcExprs.push_back(PseudoSrcExpr); |
| 6305 | DstExprs.push_back(PseudoDstExpr); |
| 6306 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6309 | if (Vars.empty()) |
| 6310 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6311 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6312 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6313 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6314 | } |
| 6315 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6316 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 6317 | SourceLocation StartLoc, |
| 6318 | SourceLocation LParenLoc, |
| 6319 | SourceLocation EndLoc) { |
| 6320 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6321 | SmallVector<Expr *, 8> SrcExprs; |
| 6322 | SmallVector<Expr *, 8> DstExprs; |
| 6323 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6324 | for (auto &RefExpr : VarList) { |
| 6325 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 6326 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6327 | // It will be analyzed later. |
| 6328 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6329 | SrcExprs.push_back(nullptr); |
| 6330 | DstExprs.push_back(nullptr); |
| 6331 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6332 | continue; |
| 6333 | } |
| 6334 | |
| 6335 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6336 | // OpenMP [2.1, C/C++] |
| 6337 | // A list item is a variable name. |
| 6338 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6339 | // A list item that appears in a copyin clause must be threadprivate. |
| 6340 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6341 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6342 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6343 | continue; |
| 6344 | } |
| 6345 | |
| 6346 | Decl *D = DE->getDecl(); |
| 6347 | VarDecl *VD = cast<VarDecl>(D); |
| 6348 | |
| 6349 | QualType Type = VD->getType(); |
| 6350 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6351 | // It will be analyzed later. |
| 6352 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6353 | SrcExprs.push_back(nullptr); |
| 6354 | DstExprs.push_back(nullptr); |
| 6355 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6356 | continue; |
| 6357 | } |
| 6358 | |
| 6359 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 6360 | // A list item that appears in a copyprivate clause may not appear in a |
| 6361 | // private or firstprivate clause on the single construct. |
| 6362 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6363 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6364 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 6365 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6366 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6367 | << getOpenMPClauseName(DVar.CKind) |
| 6368 | << getOpenMPClauseName(OMPC_copyprivate); |
| 6369 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6370 | continue; |
| 6371 | } |
| 6372 | |
| 6373 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 6374 | // All list items that appear in a copyprivate clause must be either |
| 6375 | // threadprivate or private in the enclosing context. |
| 6376 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6377 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6378 | if (DVar.CKind == OMPC_shared) { |
| 6379 | Diag(ELoc, diag::err_omp_required_access) |
| 6380 | << getOpenMPClauseName(OMPC_copyprivate) |
| 6381 | << "threadprivate or private in the enclosing context"; |
| 6382 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6383 | continue; |
| 6384 | } |
| 6385 | } |
| 6386 | } |
| 6387 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6388 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6389 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6390 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6391 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 6392 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6393 | bool IsDecl = |
| 6394 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6395 | Diag(VD->getLocation(), |
| 6396 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6397 | << VD; |
| 6398 | continue; |
| 6399 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6400 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6401 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6402 | // A variable of class type (or array thereof) that appears in a |
| 6403 | // copyin clause requires an accessible, unambiguous copy assignment |
| 6404 | // operator for the class type. |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6405 | Type = Context.getBaseElementType(Type).getUnqualifiedType(); |
| 6406 | auto *SrcVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6407 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src"); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6408 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6409 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6410 | auto *DstVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6411 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst"); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6412 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6413 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6414 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6415 | PseudoDstExpr, PseudoSrcExpr); |
| 6416 | if (AssignmentOp.isInvalid()) |
| 6417 | continue; |
| 6418 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6419 | /*DiscardedValue=*/true); |
| 6420 | if (AssignmentOp.isInvalid()) |
| 6421 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6422 | |
| 6423 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 6424 | // implicitly private. |
| 6425 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6426 | SrcExprs.push_back(PseudoSrcExpr); |
| 6427 | DstExprs.push_back(PseudoDstExpr); |
| 6428 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6429 | } |
| 6430 | |
| 6431 | if (Vars.empty()) |
| 6432 | return nullptr; |
| 6433 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6434 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 6435 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6436 | } |
| 6437 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6438 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 6439 | SourceLocation StartLoc, |
| 6440 | SourceLocation LParenLoc, |
| 6441 | SourceLocation EndLoc) { |
| 6442 | if (VarList.empty()) |
| 6443 | return nullptr; |
| 6444 | |
| 6445 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 6446 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6447 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6448 | OMPClause * |
| 6449 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 6450 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 6451 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 6452 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 6453 | if (DepKind == OMPC_DEPEND_unknown) { |
| 6454 | std::string Values; |
| 6455 | std::string Sep(", "); |
| 6456 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 6457 | Values += "'"; |
| 6458 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 6459 | Values += "'"; |
| 6460 | switch (i) { |
| 6461 | case OMPC_DEPEND_unknown - 2: |
| 6462 | Values += " or "; |
| 6463 | break; |
| 6464 | case OMPC_DEPEND_unknown - 1: |
| 6465 | break; |
| 6466 | default: |
| 6467 | Values += Sep; |
| 6468 | break; |
| 6469 | } |
| 6470 | } |
| 6471 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 6472 | << Values << getOpenMPClauseName(OMPC_depend); |
| 6473 | return nullptr; |
| 6474 | } |
| 6475 | SmallVector<Expr *, 8> Vars; |
| 6476 | for (auto &RefExpr : VarList) { |
| 6477 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6478 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6479 | // It will be analyzed later. |
| 6480 | Vars.push_back(RefExpr); |
| 6481 | continue; |
| 6482 | } |
| 6483 | |
| 6484 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6485 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 6486 | // A variable that is part of another variable (such as a field of a |
| 6487 | // structure) but is not an array element or an array section cannot appear |
| 6488 | // in a depend clause. |
| 6489 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 6490 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 6491 | ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 6492 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || (!ASE && !DE) || |
| 6493 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 6494 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 6495 | !ASE->getBase()->getType()->isArrayType())) { |
| 6496 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 6497 | << RefExpr->getSourceRange(); |
| 6498 | continue; |
| 6499 | } |
| 6500 | |
| 6501 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 6502 | } |
| 6503 | |
| 6504 | if (Vars.empty()) |
| 6505 | return nullptr; |
| 6506 | |
| 6507 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 6508 | DepLoc, ColonLoc, Vars); |
| 6509 | } |
| 6510 | |