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" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 24 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 25 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 26 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Scope.h" |
| 29 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 30 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 31 | using namespace clang; |
| 32 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 33 | //===----------------------------------------------------------------------===// |
| 34 | // Stack of data-sharing attributes for variables |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | |
| 37 | namespace { |
| 38 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 39 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 40 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 41 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 42 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 43 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 44 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 45 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 46 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 47 | bool operator()(T Kind) { |
| 48 | for (auto KindEl : Arr) |
| 49 | if (KindEl == Kind) |
| 50 | return true; |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | private: |
| 55 | ArrayRef<T> Arr; |
| 56 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 57 | struct MatchesAlways { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 58 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 59 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 63 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 64 | |
| 65 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 66 | /// clauses and their data-sharing attributes. |
| 67 | class DSAStackTy { |
| 68 | public: |
| 69 | struct DSAVarData { |
| 70 | OpenMPDirectiveKind DKind; |
| 71 | OpenMPClauseKind CKind; |
| 72 | DeclRefExpr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 73 | SourceLocation ImplicitDSALoc; |
| 74 | DSAVarData() |
| 75 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 76 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 77 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 78 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 79 | private: |
| 80 | struct DSAInfo { |
| 81 | OpenMPClauseKind Attributes; |
| 82 | DeclRefExpr *RefExpr; |
| 83 | }; |
| 84 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 85 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 86 | typedef llvm::DenseSet<VarDecl *> LoopControlVariablesSetTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 87 | |
| 88 | struct SharingMapTy { |
| 89 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 90 | AlignedMapTy AlignedMap; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 91 | LoopControlVariablesSetTy LCVSet; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 92 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 93 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 94 | OpenMPDirectiveKind Directive; |
| 95 | DeclarationNameInfo DirectiveName; |
| 96 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 97 | SourceLocation ConstructLoc; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 98 | bool OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 99 | bool NowaitRegion; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 100 | unsigned CollapseNumber; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 101 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 102 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 103 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 104 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 105 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 106 | ConstructLoc(Loc), OrderedRegion(false), NowaitRegion(false), |
| 107 | CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 108 | SharingMapTy() |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 109 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 110 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 111 | ConstructLoc(), OrderedRegion(false), NowaitRegion(false), |
| 112 | CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 116 | |
| 117 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 118 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 119 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 120 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 121 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 122 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 123 | bool ForceCapturing; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 124 | |
| 125 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 126 | |
| 127 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 128 | |
| 129 | /// \brief Checks if the variable is a local for OpenMP region. |
| 130 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 131 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 132 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 133 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 134 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 135 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 136 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 137 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 138 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 139 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 140 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 141 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 142 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 143 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 144 | Scope *CurScope, SourceLocation Loc) { |
| 145 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 146 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void pop() { |
| 150 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 151 | Stack.pop_back(); |
| 152 | } |
| 153 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 154 | /// \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] | 155 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 156 | /// for diagnostics. |
| 157 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 158 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 159 | /// \brief Register specified variable as loop control variable. |
| 160 | void addLoopControlVariable(VarDecl *D); |
| 161 | /// \brief Check if the specified variable is a loop control variable for |
| 162 | /// current region. |
| 163 | bool isLoopControlVariable(VarDecl *D); |
| 164 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 165 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 166 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 167 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 168 | /// \brief Returns data sharing attributes from top of the stack for the |
| 169 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 170 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 171 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 172 | DSAVarData getImplicitDSA(VarDecl *D, 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 directive which matches \a DPred |
| 175 | /// predicate. |
| 176 | template <class ClausesPredicate, class DirectivesPredicate> |
| 177 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 178 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 179 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 180 | /// match specified \a CPred predicate in any innermost directive which |
| 181 | /// matches \a DPred predicate. |
| 182 | template <class ClausesPredicate, class DirectivesPredicate> |
| 183 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 184 | DirectivesPredicate DPred, |
| 185 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 186 | /// \brief Checks if the specified variables has explicit data-sharing |
| 187 | /// attributes which match specified \a CPred predicate at the specified |
| 188 | /// OpenMP region. |
| 189 | bool hasExplicitDSA(VarDecl *D, |
| 190 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 191 | unsigned Level); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 192 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 193 | template <class NamedDirectivesPredicate> |
| 194 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 195 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 196 | /// \brief Returns currently analyzed directive. |
| 197 | OpenMPDirectiveKind getCurrentDirective() const { |
| 198 | return Stack.back().Directive; |
| 199 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 200 | /// \brief Returns parent directive. |
| 201 | OpenMPDirectiveKind getParentDirective() const { |
| 202 | if (Stack.size() > 2) |
| 203 | return Stack[Stack.size() - 2].Directive; |
| 204 | return OMPD_unknown; |
| 205 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 206 | |
| 207 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 208 | void setDefaultDSANone(SourceLocation Loc) { |
| 209 | Stack.back().DefaultAttr = DSA_none; |
| 210 | Stack.back().DefaultAttrLoc = Loc; |
| 211 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 212 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 213 | void setDefaultDSAShared(SourceLocation Loc) { |
| 214 | Stack.back().DefaultAttr = DSA_shared; |
| 215 | Stack.back().DefaultAttrLoc = Loc; |
| 216 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 217 | |
| 218 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 219 | return Stack.back().DefaultAttr; |
| 220 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 221 | SourceLocation getDefaultDSALocation() const { |
| 222 | return Stack.back().DefaultAttrLoc; |
| 223 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 224 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 225 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 226 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 227 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 228 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 229 | } |
| 230 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 231 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
| 232 | void setOrderedRegion(bool IsOrdered = true) { |
| 233 | Stack.back().OrderedRegion = IsOrdered; |
| 234 | } |
| 235 | /// \brief Returns true, if parent region is ordered (has associated |
| 236 | /// 'ordered' clause), false - otherwise. |
| 237 | bool isParentOrderedRegion() const { |
| 238 | if (Stack.size() > 2) |
| 239 | return Stack[Stack.size() - 2].OrderedRegion; |
| 240 | return false; |
| 241 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 242 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 243 | void setNowaitRegion(bool IsNowait = true) { |
| 244 | Stack.back().NowaitRegion = IsNowait; |
| 245 | } |
| 246 | /// \brief Returns true, if parent region is nowait (has associated |
| 247 | /// 'nowait' clause), false - otherwise. |
| 248 | bool isParentNowaitRegion() const { |
| 249 | if (Stack.size() > 2) |
| 250 | return Stack[Stack.size() - 2].NowaitRegion; |
| 251 | return false; |
| 252 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 253 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 254 | /// \brief Set collapse value for the region. |
| 255 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 256 | /// \brief Return collapse value for region. |
| 257 | unsigned getCollapseNumber() const { |
| 258 | return Stack.back().CollapseNumber; |
| 259 | } |
| 260 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 261 | /// \brief Marks current target region as one with closely nested teams |
| 262 | /// region. |
| 263 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 264 | if (Stack.size() > 2) |
| 265 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 266 | } |
| 267 | /// \brief Returns true, if current region has closely nested teams region. |
| 268 | bool hasInnerTeamsRegion() const { |
| 269 | return getInnerTeamsRegionLoc().isValid(); |
| 270 | } |
| 271 | /// \brief Returns location of the nested teams region (if any). |
| 272 | SourceLocation getInnerTeamsRegionLoc() const { |
| 273 | if (Stack.size() > 1) |
| 274 | return Stack.back().InnerTeamsRegionLoc; |
| 275 | return SourceLocation(); |
| 276 | } |
| 277 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 278 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 279 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 280 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 281 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 282 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 283 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 284 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 285 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 286 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 287 | |
| 288 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 289 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 290 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 291 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 292 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 293 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 294 | // in a region but not in construct] |
| 295 | // File-scope or namespace-scope variables referenced in called routines |
| 296 | // in the region are shared unless they appear in a threadprivate |
| 297 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 298 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 299 | DVar.CKind = OMPC_shared; |
| 300 | |
| 301 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 302 | // in a region but not in construct] |
| 303 | // Variables with static storage duration that are declared in called |
| 304 | // routines in the region are shared. |
| 305 | if (D->hasGlobalStorage()) |
| 306 | DVar.CKind = OMPC_shared; |
| 307 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 308 | return DVar; |
| 309 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 310 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 311 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 312 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 313 | // in a Construct, C/C++, predetermined, p.1] |
| 314 | // Variables with automatic storage duration that are declared in a scope |
| 315 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 316 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 317 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 318 | DVar.CKind = OMPC_private; |
| 319 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 322 | // Explicitly specified attributes and local variables with predetermined |
| 323 | // attributes. |
| 324 | if (Iter->SharingMap.count(D)) { |
| 325 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 326 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 327 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 328 | return DVar; |
| 329 | } |
| 330 | |
| 331 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 332 | // in a Construct, C/C++, implicitly determined, p.1] |
| 333 | // In a parallel or task construct, the data-sharing attributes of these |
| 334 | // variables are determined by the default clause, if present. |
| 335 | switch (Iter->DefaultAttr) { |
| 336 | case DSA_shared: |
| 337 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 338 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 339 | return DVar; |
| 340 | case DSA_none: |
| 341 | return DVar; |
| 342 | case DSA_unspecified: |
| 343 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 344 | // in a Construct, implicitly determined, p.2] |
| 345 | // In a parallel construct, if no default clause is present, these |
| 346 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 347 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 348 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 349 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 350 | DVar.CKind = OMPC_shared; |
| 351 | return DVar; |
| 352 | } |
| 353 | |
| 354 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 355 | // in a Construct, implicitly determined, p.4] |
| 356 | // In a task construct, if no default clause is present, a variable that in |
| 357 | // the enclosing context is determined to be shared by all implicit tasks |
| 358 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 359 | if (DVar.DKind == OMPD_task) { |
| 360 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 361 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 362 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 363 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 364 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 365 | // in a Construct, implicitly determined, p.6] |
| 366 | // In a task construct, if no default clause is present, a variable |
| 367 | // whose data-sharing attribute is not determined by the rules above is |
| 368 | // firstprivate. |
| 369 | DVarTemp = getDSA(I, D); |
| 370 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 371 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 372 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 373 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 374 | return DVar; |
| 375 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 376 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 377 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 378 | } |
| 379 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 380 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 381 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 382 | return DVar; |
| 383 | } |
| 384 | } |
| 385 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 386 | // in a Construct, implicitly determined, p.3] |
| 387 | // For constructs other than task, if no default clause is present, these |
| 388 | // variables inherit their data-sharing attributes from the enclosing |
| 389 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 390 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 393 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 394 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 395 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 396 | auto It = Stack.back().AlignedMap.find(D); |
| 397 | if (It == Stack.back().AlignedMap.end()) { |
| 398 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 399 | Stack.back().AlignedMap[D] = NewDE; |
| 400 | return nullptr; |
| 401 | } else { |
| 402 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 403 | return It->second; |
| 404 | } |
| 405 | return nullptr; |
| 406 | } |
| 407 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 408 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 409 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 410 | D = D->getCanonicalDecl(); |
| 411 | Stack.back().LCVSet.insert(D); |
| 412 | } |
| 413 | |
| 414 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 415 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 416 | D = D->getCanonicalDecl(); |
| 417 | return Stack.back().LCVSet.count(D) > 0; |
| 418 | } |
| 419 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 420 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 421 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 422 | if (A == OMPC_threadprivate) { |
| 423 | Stack[0].SharingMap[D].Attributes = A; |
| 424 | Stack[0].SharingMap[D].RefExpr = E; |
| 425 | } else { |
| 426 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 427 | Stack.back().SharingMap[D].Attributes = A; |
| 428 | Stack.back().SharingMap[D].RefExpr = E; |
| 429 | } |
| 430 | } |
| 431 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 432 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 433 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 434 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 435 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 436 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 437 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 438 | ++I; |
| 439 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 440 | if (I == E) |
| 441 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 442 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 443 | Scope *CurScope = getCurScope(); |
| 444 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 446 | } |
| 447 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 448 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 449 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 450 | } |
| 451 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 452 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 453 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
| 454 | StringRef Name) { |
| 455 | DeclContext *DC = SemaRef.CurContext; |
| 456 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 457 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 458 | VarDecl *Decl = |
| 459 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
| 460 | Decl->setImplicit(); |
| 461 | return Decl; |
| 462 | } |
| 463 | |
| 464 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 465 | SourceLocation Loc, |
| 466 | bool RefersToCapture = false) { |
| 467 | D->setReferenced(); |
| 468 | D->markUsed(S.Context); |
| 469 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 470 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 471 | VK_LValue); |
| 472 | } |
| 473 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 474 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 475 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 476 | DSAVarData DVar; |
| 477 | |
| 478 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 479 | // in a Construct, C/C++, predetermined, p.1] |
| 480 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 481 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 482 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 483 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 484 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 485 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 486 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 487 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 488 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 489 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 490 | } |
| 491 | if (Stack[0].SharingMap.count(D)) { |
| 492 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 493 | DVar.CKind = OMPC_threadprivate; |
| 494 | return DVar; |
| 495 | } |
| 496 | |
| 497 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 498 | // in a Construct, C/C++, predetermined, p.1] |
| 499 | // Variables with automatic storage duration that are declared in a scope |
| 500 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 501 | OpenMPDirectiveKind Kind = |
| 502 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 503 | auto StartI = std::next(Stack.rbegin()); |
| 504 | auto EndI = std::prev(Stack.rend()); |
| 505 | if (FromParent && StartI != EndI) { |
| 506 | StartI = std::next(StartI); |
| 507 | } |
| 508 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 509 | if (isOpenMPLocal(D, StartI) && |
| 510 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 511 | D->getStorageClass() == SC_None)) || |
| 512 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 513 | DVar.CKind = OMPC_private; |
| 514 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 515 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 516 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 517 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 518 | // in a Construct, C/C++, predetermined, p.4] |
| 519 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 520 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 521 | // in a Construct, C/C++, predetermined, p.7] |
| 522 | // Variables with static storage duration that are declared in a scope |
| 523 | // inside the construct are shared. |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 524 | if (D->isStaticDataMember() || D->isStaticLocal()) { |
| 525 | DSAVarData DVarTemp = |
| 526 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 527 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 528 | return DVar; |
| 529 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 530 | DVar.CKind = OMPC_shared; |
| 531 | return DVar; |
| 532 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 536 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 537 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 538 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 539 | // in a Construct, C/C++, predetermined, p.6] |
| 540 | // Variables with const qualified type having no mutable member are |
| 541 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 542 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 543 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 544 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 545 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 546 | // Variables with const-qualified type having no mutable member may be |
| 547 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 548 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 549 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 550 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 551 | return DVar; |
| 552 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 553 | DVar.CKind = OMPC_shared; |
| 554 | return DVar; |
| 555 | } |
| 556 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 557 | // Explicitly specified attributes and local variables with predetermined |
| 558 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 559 | auto I = std::prev(StartI); |
| 560 | if (I->SharingMap.count(D)) { |
| 561 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 562 | DVar.CKind = I->SharingMap[D].Attributes; |
| 563 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | return DVar; |
| 567 | } |
| 568 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 569 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 570 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 571 | auto StartI = Stack.rbegin(); |
| 572 | auto EndI = std::prev(Stack.rend()); |
| 573 | if (FromParent && StartI != EndI) { |
| 574 | StartI = std::next(StartI); |
| 575 | } |
| 576 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 579 | template <class ClausesPredicate, class DirectivesPredicate> |
| 580 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 581 | DirectivesPredicate DPred, |
| 582 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 583 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 584 | auto StartI = std::next(Stack.rbegin()); |
| 585 | auto EndI = std::prev(Stack.rend()); |
| 586 | if (FromParent && StartI != EndI) { |
| 587 | StartI = std::next(StartI); |
| 588 | } |
| 589 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 590 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 591 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 592 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 593 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 594 | return DVar; |
| 595 | } |
| 596 | return DSAVarData(); |
| 597 | } |
| 598 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 599 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 600 | DSAStackTy::DSAVarData |
| 601 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 602 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 603 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 604 | auto StartI = std::next(Stack.rbegin()); |
| 605 | auto EndI = std::prev(Stack.rend()); |
| 606 | if (FromParent && StartI != EndI) { |
| 607 | StartI = std::next(StartI); |
| 608 | } |
| 609 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 610 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 611 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 612 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 613 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 614 | return DVar; |
| 615 | return DSAVarData(); |
| 616 | } |
| 617 | return DSAVarData(); |
| 618 | } |
| 619 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 620 | bool DSAStackTy::hasExplicitDSA( |
| 621 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 622 | unsigned Level) { |
| 623 | if (CPred(ClauseKindMode)) |
| 624 | return true; |
| 625 | if (isClauseParsingMode()) |
| 626 | ++Level; |
| 627 | D = D->getCanonicalDecl(); |
| 628 | auto StartI = Stack.rbegin(); |
| 629 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 630 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 631 | return false; |
| 632 | std::advance(StartI, Level); |
| 633 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 634 | CPred(StartI->SharingMap[D].Attributes); |
| 635 | } |
| 636 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 637 | template <class NamedDirectivesPredicate> |
| 638 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 639 | auto StartI = std::next(Stack.rbegin()); |
| 640 | auto EndI = std::prev(Stack.rend()); |
| 641 | if (FromParent && StartI != EndI) { |
| 642 | StartI = std::next(StartI); |
| 643 | } |
| 644 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 645 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 646 | return true; |
| 647 | } |
| 648 | return false; |
| 649 | } |
| 650 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 651 | void Sema::InitDataSharingAttributesStack() { |
| 652 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 653 | } |
| 654 | |
| 655 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 656 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 657 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 658 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 659 | VD = VD->getCanonicalDecl(); |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 660 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 661 | (!DSAStack->isClauseParsingMode() || |
| 662 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 663 | if (DSAStack->isLoopControlVariable(VD) || |
| 664 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 665 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 666 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 667 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 668 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 669 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 670 | return true; |
| 671 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 672 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 673 | return DVarPrivate.CKind != OMPC_unknown; |
| 674 | } |
| 675 | return false; |
| 676 | } |
| 677 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 678 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 679 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 680 | return DSAStack->hasExplicitDSA( |
| 681 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 682 | } |
| 683 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 684 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 685 | |
| 686 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 687 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 688 | Scope *CurScope, SourceLocation Loc) { |
| 689 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 690 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 691 | } |
| 692 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 693 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 694 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 697 | void Sema::EndOpenMPClause() { |
| 698 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 701 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 702 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 703 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 704 | // clause requires an accessible, unambiguous default constructor for the |
| 705 | // class type, unless the list item is also specified in a firstprivate |
| 706 | // clause. |
| 707 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 708 | for (auto *C : D->clauses()) { |
| 709 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 710 | SmallVector<Expr *, 8> PrivateCopies; |
| 711 | for (auto *DE : Clause->varlists()) { |
| 712 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 713 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 714 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 715 | } |
| 716 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 717 | QualType Type = VD->getType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 718 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 719 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 720 | // Generate helper private variable and initialize it with the |
| 721 | // default value. The address of the original variable is replaced |
| 722 | // by the address of the new private variable in CodeGen. This new |
| 723 | // variable is not added to IdResolver, so the code in the OpenMP |
| 724 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 725 | auto *VDPrivate = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 726 | buildVarDecl(*this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 727 | VD->getName()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 728 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 729 | if (VDPrivate->isInvalidDecl()) |
| 730 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 731 | PrivateCopies.push_back(buildDeclRefExpr( |
| 732 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 733 | } else { |
| 734 | // The variable is also a firstprivate, so initialization sequence |
| 735 | // for private copy is generated already. |
| 736 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 737 | } |
| 738 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 739 | // Set initializers to private copies if no errors were found. |
| 740 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 741 | Clause->setPrivateCopies(PrivateCopies); |
| 742 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 747 | DSAStack->pop(); |
| 748 | DiscardCleanupsInEvaluationContext(); |
| 749 | PopExpressionEvaluationContext(); |
| 750 | } |
| 751 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 752 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 753 | Expr *NumIterations, Sema &SemaRef, |
| 754 | Scope *S); |
| 755 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 756 | namespace { |
| 757 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 758 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 759 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 760 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 761 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 762 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 763 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 764 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 765 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 766 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 767 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 768 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 769 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 770 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 771 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 772 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 773 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 774 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 775 | |
| 776 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 777 | CXXScopeSpec &ScopeSpec, |
| 778 | const DeclarationNameInfo &Id) { |
| 779 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 780 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 781 | |
| 782 | if (Lookup.isAmbiguous()) |
| 783 | return ExprError(); |
| 784 | |
| 785 | VarDecl *VD; |
| 786 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 787 | if (TypoCorrection Corrected = CorrectTypo( |
| 788 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 789 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 790 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 791 | PDiag(Lookup.empty() |
| 792 | ? diag::err_undeclared_var_use_suggest |
| 793 | : diag::err_omp_expected_var_arg_suggest) |
| 794 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 795 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 796 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 797 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 798 | : diag::err_omp_expected_var_arg) |
| 799 | << Id.getName(); |
| 800 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 801 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 802 | } else { |
| 803 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 804 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 805 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 806 | return ExprError(); |
| 807 | } |
| 808 | } |
| 809 | Lookup.suppressDiagnostics(); |
| 810 | |
| 811 | // OpenMP [2.9.2, Syntax, C/C++] |
| 812 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 813 | if (!VD->hasGlobalStorage()) { |
| 814 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 815 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 816 | bool IsDecl = |
| 817 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 818 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 819 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 820 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 821 | return ExprError(); |
| 822 | } |
| 823 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 824 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 825 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 826 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 827 | // A threadprivate directive for file-scope variables must appear outside |
| 828 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 829 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 830 | !getCurLexicalContext()->isTranslationUnit()) { |
| 831 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 832 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 833 | bool IsDecl = |
| 834 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 835 | Diag(VD->getLocation(), |
| 836 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 837 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 838 | return ExprError(); |
| 839 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 840 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 841 | // A threadprivate directive for static class member variables must appear |
| 842 | // in the class definition, in the same scope in which the member |
| 843 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 844 | if (CanonicalVD->isStaticDataMember() && |
| 845 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 846 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 847 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 848 | bool IsDecl = |
| 849 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 850 | Diag(VD->getLocation(), |
| 851 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 852 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 853 | return ExprError(); |
| 854 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 855 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 856 | // A threadprivate directive for namespace-scope variables must appear |
| 857 | // outside any definition or declaration other than the namespace |
| 858 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 859 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 860 | (!getCurLexicalContext()->isFileContext() || |
| 861 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 862 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 863 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 864 | bool IsDecl = |
| 865 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 866 | Diag(VD->getLocation(), |
| 867 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 868 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 869 | return ExprError(); |
| 870 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 871 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 872 | // A threadprivate directive for static block-scope variables must appear |
| 873 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 874 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 875 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 876 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 877 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 878 | bool IsDecl = |
| 879 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 880 | Diag(VD->getLocation(), |
| 881 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 882 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 883 | return ExprError(); |
| 884 | } |
| 885 | |
| 886 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 887 | // A threadprivate directive must lexically precede all references to any |
| 888 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 889 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 890 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 891 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 892 | return ExprError(); |
| 893 | } |
| 894 | |
| 895 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 896 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 897 | return DE; |
| 898 | } |
| 899 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 900 | Sema::DeclGroupPtrTy |
| 901 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 902 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 903 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 904 | CurContext->addDecl(D); |
| 905 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 906 | } |
| 907 | return DeclGroupPtrTy(); |
| 908 | } |
| 909 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 910 | namespace { |
| 911 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 912 | Sema &SemaRef; |
| 913 | |
| 914 | public: |
| 915 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 916 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 917 | if (VD->hasLocalStorage()) { |
| 918 | SemaRef.Diag(E->getLocStart(), |
| 919 | diag::err_omp_local_var_in_threadprivate_init) |
| 920 | << E->getSourceRange(); |
| 921 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 922 | << VD << VD->getSourceRange(); |
| 923 | return true; |
| 924 | } |
| 925 | } |
| 926 | return false; |
| 927 | } |
| 928 | bool VisitStmt(const Stmt *S) { |
| 929 | for (auto Child : S->children()) { |
| 930 | if (Child && Visit(Child)) |
| 931 | return true; |
| 932 | } |
| 933 | return false; |
| 934 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 935 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 936 | }; |
| 937 | } // namespace |
| 938 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 939 | OMPThreadPrivateDecl * |
| 940 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 941 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 942 | for (auto &RefExpr : VarList) { |
| 943 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 944 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 945 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 946 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 947 | QualType QType = VD->getType(); |
| 948 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 949 | // It will be analyzed later. |
| 950 | Vars.push_back(DE); |
| 951 | continue; |
| 952 | } |
| 953 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 954 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 955 | // A threadprivate variable must not have an incomplete type. |
| 956 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 957 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 958 | continue; |
| 959 | } |
| 960 | |
| 961 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 962 | // A threadprivate variable must not have a reference type. |
| 963 | if (VD->getType()->isReferenceType()) { |
| 964 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 965 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 966 | bool IsDecl = |
| 967 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 968 | Diag(VD->getLocation(), |
| 969 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 970 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 971 | continue; |
| 972 | } |
| 973 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 974 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 975 | // the corresponding diagnostic. |
| 976 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 977 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 978 | getLangOpts().OpenMPUseTLS && |
| 979 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 980 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 981 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 982 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 983 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 984 | bool IsDecl = |
| 985 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 986 | Diag(VD->getLocation(), |
| 987 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 988 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 989 | continue; |
| 990 | } |
| 991 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 992 | // Check if initial value of threadprivate variable reference variable with |
| 993 | // local storage (it is not supported by runtime). |
| 994 | if (auto Init = VD->getAnyInitializer()) { |
| 995 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 996 | if (Checker.Visit(Init)) |
| 997 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1000 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1001 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1002 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1003 | Context, SourceRange(Loc, Loc))); |
| 1004 | if (auto *ML = Context.getASTMutationListener()) |
| 1005 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1006 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1007 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1008 | if (!Vars.empty()) { |
| 1009 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1010 | Vars); |
| 1011 | D->setAccess(AS_public); |
| 1012 | } |
| 1013 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1014 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1015 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1016 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1017 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1018 | bool IsLoopIterVar = false) { |
| 1019 | if (DVar.RefExpr) { |
| 1020 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1021 | << getOpenMPClauseName(DVar.CKind); |
| 1022 | return; |
| 1023 | } |
| 1024 | enum { |
| 1025 | PDSA_StaticMemberShared, |
| 1026 | PDSA_StaticLocalVarShared, |
| 1027 | PDSA_LoopIterVarPrivate, |
| 1028 | PDSA_LoopIterVarLinear, |
| 1029 | PDSA_LoopIterVarLastprivate, |
| 1030 | PDSA_ConstVarShared, |
| 1031 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1032 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1033 | PDSA_LocalVarPrivate, |
| 1034 | PDSA_Implicit |
| 1035 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1036 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1037 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1038 | if (IsLoopIterVar) { |
| 1039 | if (DVar.CKind == OMPC_private) |
| 1040 | Reason = PDSA_LoopIterVarPrivate; |
| 1041 | else if (DVar.CKind == OMPC_lastprivate) |
| 1042 | Reason = PDSA_LoopIterVarLastprivate; |
| 1043 | else |
| 1044 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1045 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1046 | Reason = PDSA_TaskVarFirstprivate; |
| 1047 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1048 | } else if (VD->isStaticLocal()) |
| 1049 | Reason = PDSA_StaticLocalVarShared; |
| 1050 | else if (VD->isStaticDataMember()) |
| 1051 | Reason = PDSA_StaticMemberShared; |
| 1052 | else if (VD->isFileVarDecl()) |
| 1053 | Reason = PDSA_GlobalVarShared; |
| 1054 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1055 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1056 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1057 | ReportHint = true; |
| 1058 | Reason = PDSA_LocalVarPrivate; |
| 1059 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1060 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1061 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1062 | << Reason << ReportHint |
| 1063 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1064 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1065 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1066 | << getOpenMPClauseName(DVar.CKind); |
| 1067 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1070 | namespace { |
| 1071 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1072 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1073 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1074 | bool ErrorFound; |
| 1075 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1076 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1077 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1078 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1079 | public: |
| 1080 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1081 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1082 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1083 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1084 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1085 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1086 | auto DVar = Stack->getTopDSA(VD, false); |
| 1087 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1088 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1089 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1090 | auto ELoc = E->getExprLoc(); |
| 1091 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1092 | // The default(none) clause requires that each variable that is referenced |
| 1093 | // in the construct, and does not have a predetermined data-sharing |
| 1094 | // attribute, must have its data-sharing attribute explicitly determined |
| 1095 | // by being listed in a data-sharing attribute clause. |
| 1096 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1097 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1098 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1099 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1100 | return; |
| 1101 | } |
| 1102 | |
| 1103 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1104 | // A list item that appears in a reduction clause of the innermost |
| 1105 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1106 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1107 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1108 | [](OpenMPDirectiveKind K) -> bool { |
| 1109 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1110 | isOpenMPWorksharingDirective(K) || |
| 1111 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1112 | }, |
| 1113 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1114 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1115 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1116 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1117 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1118 | return; |
| 1119 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1120 | |
| 1121 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1122 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1123 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1124 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1125 | } |
| 1126 | } |
| 1127 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1128 | for (auto *C : S->clauses()) { |
| 1129 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1130 | // for task directives. |
| 1131 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1132 | for (auto *CC : C->children()) { |
| 1133 | if (CC) |
| 1134 | Visit(CC); |
| 1135 | } |
| 1136 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1137 | } |
| 1138 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1139 | for (auto *C : S->children()) { |
| 1140 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1141 | Visit(C); |
| 1142 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1143 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1144 | |
| 1145 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1146 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1147 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1148 | return VarsWithInheritedDSA; |
| 1149 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1150 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1151 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1152 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1153 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1154 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1155 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1156 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1157 | switch (DKind) { |
| 1158 | case OMPD_parallel: { |
| 1159 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1160 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1161 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1162 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1163 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 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 | } |
| 1170 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1171 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1172 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1173 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1174 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1175 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1176 | break; |
| 1177 | } |
| 1178 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1179 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1180 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1181 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1182 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1183 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1184 | break; |
| 1185 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1186 | case OMPD_for_simd: { |
| 1187 | Sema::CapturedParamNameType Params[] = { |
| 1188 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1189 | }; |
| 1190 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1191 | Params); |
| 1192 | break; |
| 1193 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1194 | case OMPD_sections: { |
| 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 | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1200 | break; |
| 1201 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1202 | case OMPD_section: { |
| 1203 | Sema::CapturedParamNameType Params[] = { |
| 1204 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1205 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1206 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1207 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1208 | break; |
| 1209 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1210 | case OMPD_single: { |
| 1211 | Sema::CapturedParamNameType Params[] = { |
| 1212 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1213 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1214 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1215 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1216 | break; |
| 1217 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1218 | case OMPD_master: { |
| 1219 | Sema::CapturedParamNameType Params[] = { |
| 1220 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1221 | }; |
| 1222 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1223 | Params); |
| 1224 | break; |
| 1225 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1226 | case OMPD_critical: { |
| 1227 | Sema::CapturedParamNameType Params[] = { |
| 1228 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1229 | }; |
| 1230 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1231 | Params); |
| 1232 | break; |
| 1233 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1234 | case OMPD_parallel_for: { |
| 1235 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1236 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1237 | Sema::CapturedParamNameType Params[] = { |
| 1238 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1239 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1240 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1241 | }; |
| 1242 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1243 | Params); |
| 1244 | break; |
| 1245 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1246 | case OMPD_parallel_for_simd: { |
| 1247 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1248 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1249 | Sema::CapturedParamNameType Params[] = { |
| 1250 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1251 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1252 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1253 | }; |
| 1254 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1255 | Params); |
| 1256 | break; |
| 1257 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1258 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1259 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1260 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1261 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1262 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1263 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1264 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1265 | }; |
| 1266 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1267 | Params); |
| 1268 | break; |
| 1269 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1270 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1271 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1272 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1273 | FunctionProtoType::ExtProtoInfo EPI; |
| 1274 | EPI.Variadic = true; |
| 1275 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1276 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1277 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1278 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1279 | std::make_pair(".privates.", |
| 1280 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1281 | std::make_pair( |
| 1282 | ".copy_fn.", |
| 1283 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1284 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1285 | }; |
| 1286 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1287 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1288 | // Mark this captured region as inlined, because we don't use outlined |
| 1289 | // function directly. |
| 1290 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1291 | AlwaysInlineAttr::CreateImplicit( |
| 1292 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1293 | break; |
| 1294 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1295 | case OMPD_ordered: { |
| 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 | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1303 | case OMPD_atomic: { |
| 1304 | Sema::CapturedParamNameType Params[] = { |
| 1305 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1306 | }; |
| 1307 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1308 | Params); |
| 1309 | break; |
| 1310 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1311 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1312 | case OMPD_target: { |
| 1313 | Sema::CapturedParamNameType Params[] = { |
| 1314 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1315 | }; |
| 1316 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1317 | Params); |
| 1318 | break; |
| 1319 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1320 | case OMPD_teams: { |
| 1321 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1322 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1323 | Sema::CapturedParamNameType Params[] = { |
| 1324 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1325 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1326 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1327 | }; |
| 1328 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1329 | Params); |
| 1330 | break; |
| 1331 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1332 | case OMPD_taskgroup: { |
| 1333 | Sema::CapturedParamNameType Params[] = { |
| 1334 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1335 | }; |
| 1336 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1337 | Params); |
| 1338 | break; |
| 1339 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1340 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1341 | case OMPD_taskyield: |
| 1342 | case OMPD_barrier: |
| 1343 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1344 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1345 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1346 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1347 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1348 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1349 | llvm_unreachable("Unknown OpenMP directive"); |
| 1350 | } |
| 1351 | } |
| 1352 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1353 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1354 | ArrayRef<OMPClause *> Clauses) { |
| 1355 | if (!S.isUsable()) { |
| 1356 | ActOnCapturedRegionError(); |
| 1357 | return StmtError(); |
| 1358 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1359 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1360 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1361 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1362 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1363 | (getLangOpts().OpenMPUseTLS && |
| 1364 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1365 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1366 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1367 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1368 | for (auto *VarRef : Clause->children()) { |
| 1369 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1370 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1371 | } |
| 1372 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1373 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1374 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1375 | Clause->getClauseKind() == OMPC_schedule) { |
| 1376 | // Mark all variables in private list clauses as used in inner region. |
| 1377 | // Required for proper codegen of combined directives. |
| 1378 | // TODO: add processing for other clauses. |
| 1379 | if (auto *E = cast_or_null<Expr>( |
| 1380 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1381 | MarkDeclarationsReferencedInExpr(E); |
| 1382 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1383 | } |
| 1384 | } |
| 1385 | return ActOnCapturedRegionEnd(S.get()); |
| 1386 | } |
| 1387 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1388 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1389 | OpenMPDirectiveKind CurrentRegion, |
| 1390 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1391 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1392 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1393 | // Allowed nesting of constructs |
| 1394 | // +------------------+-----------------+------------------------------------+ |
| 1395 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1396 | // +------------------+-----------------+------------------------------------+ |
| 1397 | // | parallel | parallel | * | |
| 1398 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1399 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1400 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1401 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1402 | // | parallel | simd | * | |
| 1403 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1404 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1405 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1406 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1407 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1408 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1409 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1410 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1411 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1412 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1413 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1414 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1415 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1416 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1417 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1418 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1419 | // | parallel | cancellation | | |
| 1420 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1421 | // | parallel | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1422 | // +------------------+-----------------+------------------------------------+ |
| 1423 | // | for | parallel | * | |
| 1424 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1425 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1426 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1427 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1428 | // | for | simd | * | |
| 1429 | // | for | sections | + | |
| 1430 | // | for | section | + | |
| 1431 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1432 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1433 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1434 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1435 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1436 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1437 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1438 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1439 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1440 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1441 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1442 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1443 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1444 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1445 | // | for | cancellation | | |
| 1446 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1447 | // | for | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1448 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1449 | // | master | parallel | * | |
| 1450 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1451 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1452 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1453 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1454 | // | master | simd | * | |
| 1455 | // | master | sections | + | |
| 1456 | // | master | section | + | |
| 1457 | // | master | single | + | |
| 1458 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1459 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1460 | // | master |parallel sections| * | |
| 1461 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1462 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1463 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1464 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1465 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1466 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1467 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1468 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1469 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1470 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1471 | // | master | cancellation | | |
| 1472 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1473 | // | master | cancel | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1474 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1475 | // | critical | parallel | * | |
| 1476 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1477 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1478 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1479 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1480 | // | critical | simd | * | |
| 1481 | // | critical | sections | + | |
| 1482 | // | critical | section | + | |
| 1483 | // | critical | single | + | |
| 1484 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1485 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1486 | // | critical |parallel sections| * | |
| 1487 | // | critical | task | * | |
| 1488 | // | critical | taskyield | * | |
| 1489 | // | critical | barrier | + | |
| 1490 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1491 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1492 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1493 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1494 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1495 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1496 | // | critical | cancellation | | |
| 1497 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1498 | // | critical | cancel | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1499 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1500 | // | simd | parallel | | |
| 1501 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1502 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1503 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1504 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1505 | // | simd | simd | | |
| 1506 | // | simd | sections | | |
| 1507 | // | simd | section | | |
| 1508 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1509 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1510 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1511 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1512 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1513 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1514 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1515 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1516 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1517 | // | simd | flush | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1518 | // | simd | ordered | | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1519 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1520 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1521 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1522 | // | simd | cancellation | | |
| 1523 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1524 | // | simd | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1525 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1526 | // | for simd | parallel | | |
| 1527 | // | for simd | for | | |
| 1528 | // | for simd | for simd | | |
| 1529 | // | for simd | master | | |
| 1530 | // | for simd | critical | | |
| 1531 | // | for simd | simd | | |
| 1532 | // | for simd | sections | | |
| 1533 | // | for simd | section | | |
| 1534 | // | for simd | single | | |
| 1535 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1536 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1537 | // | for simd |parallel sections| | |
| 1538 | // | for simd | task | | |
| 1539 | // | for simd | taskyield | | |
| 1540 | // | for simd | barrier | | |
| 1541 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1542 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1543 | // | for simd | flush | | |
| 1544 | // | for simd | ordered | | |
| 1545 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1546 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1547 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1548 | // | for simd | cancellation | | |
| 1549 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1550 | // | for simd | cancel | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1551 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1552 | // | parallel for simd| parallel | | |
| 1553 | // | parallel for simd| for | | |
| 1554 | // | parallel for simd| for simd | | |
| 1555 | // | parallel for simd| master | | |
| 1556 | // | parallel for simd| critical | | |
| 1557 | // | parallel for simd| simd | | |
| 1558 | // | parallel for simd| sections | | |
| 1559 | // | parallel for simd| section | | |
| 1560 | // | parallel for simd| single | | |
| 1561 | // | parallel for simd| parallel for | | |
| 1562 | // | parallel for simd|parallel for simd| | |
| 1563 | // | parallel for simd|parallel sections| | |
| 1564 | // | parallel for simd| task | | |
| 1565 | // | parallel for simd| taskyield | | |
| 1566 | // | parallel for simd| barrier | | |
| 1567 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1568 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1569 | // | parallel for simd| flush | | |
| 1570 | // | parallel for simd| ordered | | |
| 1571 | // | parallel for simd| atomic | | |
| 1572 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1573 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1574 | // | parallel for simd| cancellation | | |
| 1575 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1576 | // | parallel for simd| cancel | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1577 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1578 | // | sections | parallel | * | |
| 1579 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1580 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1581 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1582 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1583 | // | sections | simd | * | |
| 1584 | // | sections | sections | + | |
| 1585 | // | sections | section | * | |
| 1586 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1587 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1588 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1589 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1590 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1591 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1592 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1593 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1594 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1595 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1596 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1597 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1598 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1599 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1600 | // | sections | cancellation | | |
| 1601 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1602 | // | sections | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1603 | // +------------------+-----------------+------------------------------------+ |
| 1604 | // | section | parallel | * | |
| 1605 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1606 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1607 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1608 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1609 | // | section | simd | * | |
| 1610 | // | section | sections | + | |
| 1611 | // | section | section | + | |
| 1612 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1613 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1614 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1615 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1616 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1617 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1618 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1619 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1620 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1621 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1622 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1623 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1624 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1625 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1626 | // | section | cancellation | | |
| 1627 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1628 | // | section | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1629 | // +------------------+-----------------+------------------------------------+ |
| 1630 | // | single | parallel | * | |
| 1631 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1632 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1633 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1634 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1635 | // | single | simd | * | |
| 1636 | // | single | sections | + | |
| 1637 | // | single | section | + | |
| 1638 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1639 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1640 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1641 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1642 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1643 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1644 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1645 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1646 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1647 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1648 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1649 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1650 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1651 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1652 | // | single | cancellation | | |
| 1653 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1654 | // | single | cancel | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1655 | // +------------------+-----------------+------------------------------------+ |
| 1656 | // | parallel for | parallel | * | |
| 1657 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1658 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1659 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1660 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1661 | // | parallel for | simd | * | |
| 1662 | // | parallel for | sections | + | |
| 1663 | // | parallel for | section | + | |
| 1664 | // | parallel for | single | + | |
| 1665 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1666 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1667 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1668 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1669 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1670 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1671 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1672 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1673 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1674 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1675 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1676 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1677 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1678 | // | parallel for | cancellation | | |
| 1679 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1680 | // | parallel for | cancel | ! | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1681 | // +------------------+-----------------+------------------------------------+ |
| 1682 | // | parallel sections| parallel | * | |
| 1683 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1684 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1685 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1686 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1687 | // | parallel sections| simd | * | |
| 1688 | // | parallel sections| sections | + | |
| 1689 | // | parallel sections| section | * | |
| 1690 | // | parallel sections| single | + | |
| 1691 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1692 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1693 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1694 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1695 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1696 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1697 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1698 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1699 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1700 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1701 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1702 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1703 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1704 | // | parallel sections| cancellation | | |
| 1705 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1706 | // | parallel sections| cancel | ! | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1707 | // +------------------+-----------------+------------------------------------+ |
| 1708 | // | task | parallel | * | |
| 1709 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1710 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1711 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1712 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1713 | // | task | simd | * | |
| 1714 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1715 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1716 | // | task | single | + | |
| 1717 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1718 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1719 | // | task |parallel sections| * | |
| 1720 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1721 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1722 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1723 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1724 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1725 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1726 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1727 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1728 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1729 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1730 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1731 | // | | point | ! | |
| 1732 | // | task | cancel | ! | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1733 | // +------------------+-----------------+------------------------------------+ |
| 1734 | // | ordered | parallel | * | |
| 1735 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1736 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1737 | // | ordered | master | * | |
| 1738 | // | ordered | critical | * | |
| 1739 | // | ordered | simd | * | |
| 1740 | // | ordered | sections | + | |
| 1741 | // | ordered | section | + | |
| 1742 | // | ordered | single | + | |
| 1743 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1744 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1745 | // | ordered |parallel sections| * | |
| 1746 | // | ordered | task | * | |
| 1747 | // | ordered | taskyield | * | |
| 1748 | // | ordered | barrier | + | |
| 1749 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1750 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1751 | // | ordered | flush | * | |
| 1752 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1753 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1754 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1755 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1756 | // | ordered | cancellation | | |
| 1757 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1758 | // | ordered | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1759 | // +------------------+-----------------+------------------------------------+ |
| 1760 | // | atomic | parallel | | |
| 1761 | // | atomic | for | | |
| 1762 | // | atomic | for simd | | |
| 1763 | // | atomic | master | | |
| 1764 | // | atomic | critical | | |
| 1765 | // | atomic | simd | | |
| 1766 | // | atomic | sections | | |
| 1767 | // | atomic | section | | |
| 1768 | // | atomic | single | | |
| 1769 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1770 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1771 | // | atomic |parallel sections| | |
| 1772 | // | atomic | task | | |
| 1773 | // | atomic | taskyield | | |
| 1774 | // | atomic | barrier | | |
| 1775 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1776 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1777 | // | atomic | flush | | |
| 1778 | // | atomic | ordered | | |
| 1779 | // | atomic | atomic | | |
| 1780 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1781 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1782 | // | atomic | cancellation | | |
| 1783 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1784 | // | atomic | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1785 | // +------------------+-----------------+------------------------------------+ |
| 1786 | // | target | parallel | * | |
| 1787 | // | target | for | * | |
| 1788 | // | target | for simd | * | |
| 1789 | // | target | master | * | |
| 1790 | // | target | critical | * | |
| 1791 | // | target | simd | * | |
| 1792 | // | target | sections | * | |
| 1793 | // | target | section | * | |
| 1794 | // | target | single | * | |
| 1795 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1796 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1797 | // | target |parallel sections| * | |
| 1798 | // | target | task | * | |
| 1799 | // | target | taskyield | * | |
| 1800 | // | target | barrier | * | |
| 1801 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1802 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1803 | // | target | flush | * | |
| 1804 | // | target | ordered | * | |
| 1805 | // | target | atomic | * | |
| 1806 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1807 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1808 | // | target | cancellation | | |
| 1809 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1810 | // | target | cancel | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1811 | // +------------------+-----------------+------------------------------------+ |
| 1812 | // | teams | parallel | * | |
| 1813 | // | teams | for | + | |
| 1814 | // | teams | for simd | + | |
| 1815 | // | teams | master | + | |
| 1816 | // | teams | critical | + | |
| 1817 | // | teams | simd | + | |
| 1818 | // | teams | sections | + | |
| 1819 | // | teams | section | + | |
| 1820 | // | teams | single | + | |
| 1821 | // | teams | parallel for | * | |
| 1822 | // | teams |parallel for simd| * | |
| 1823 | // | teams |parallel sections| * | |
| 1824 | // | teams | task | + | |
| 1825 | // | teams | taskyield | + | |
| 1826 | // | teams | barrier | + | |
| 1827 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1828 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1829 | // | teams | flush | + | |
| 1830 | // | teams | ordered | + | |
| 1831 | // | teams | atomic | + | |
| 1832 | // | teams | target | + | |
| 1833 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1834 | // | teams | cancellation | | |
| 1835 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1836 | // | teams | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1837 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1838 | if (Stack->getCurScope()) { |
| 1839 | auto ParentRegion = Stack->getParentDirective(); |
| 1840 | bool NestingProhibited = false; |
| 1841 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1842 | enum { |
| 1843 | NoRecommend, |
| 1844 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1845 | ShouldBeInOrderedRegion, |
| 1846 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1847 | } Recommend = NoRecommend; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1848 | if (isOpenMPSimdDirective(ParentRegion)) { |
| 1849 | // OpenMP [2.16, Nesting of Regions] |
| 1850 | // OpenMP constructs may not be nested inside a simd region. |
| 1851 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1852 | return true; |
| 1853 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1854 | if (ParentRegion == OMPD_atomic) { |
| 1855 | // OpenMP [2.16, Nesting of Regions] |
| 1856 | // OpenMP constructs may not be nested inside an atomic region. |
| 1857 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1858 | return true; |
| 1859 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1860 | if (CurrentRegion == OMPD_section) { |
| 1861 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1862 | // Orphaned section directives are prohibited. That is, the section |
| 1863 | // directives must appear within the sections construct and must not be |
| 1864 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1865 | if (ParentRegion != OMPD_sections && |
| 1866 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1867 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1868 | << (ParentRegion != OMPD_unknown) |
| 1869 | << getOpenMPDirectiveName(ParentRegion); |
| 1870 | return true; |
| 1871 | } |
| 1872 | return false; |
| 1873 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1874 | // Allow some constructs to be orphaned (they could be used in functions, |
| 1875 | // called from OpenMP regions with the required preconditions). |
| 1876 | if (ParentRegion == OMPD_unknown) |
| 1877 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1878 | if (CurrentRegion == OMPD_cancellation_point || |
| 1879 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1880 | // OpenMP [2.16, Nesting of Regions] |
| 1881 | // A cancellation point construct for which construct-type-clause is |
| 1882 | // taskgroup must be nested inside a task construct. A cancellation |
| 1883 | // point construct for which construct-type-clause is not taskgroup must |
| 1884 | // be closely nested inside an OpenMP construct that matches the type |
| 1885 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1886 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 1887 | // nested inside a task construct. A cancel construct for which |
| 1888 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 1889 | // OpenMP construct that matches the type specified in |
| 1890 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1891 | NestingProhibited = |
| 1892 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
| 1893 | (CancelRegion == OMPD_for && ParentRegion == OMPD_for) || |
| 1894 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 1895 | (CancelRegion == OMPD_sections && |
| 1896 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections))); |
| 1897 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1898 | // OpenMP [2.16, Nesting of Regions] |
| 1899 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1900 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1901 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 1902 | ParentRegion == OMPD_task; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1903 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 1904 | // OpenMP [2.16, Nesting of Regions] |
| 1905 | // A critical region may not be nested (closely or otherwise) inside a |
| 1906 | // critical region with the same name. Note that this restriction is not |
| 1907 | // sufficient to prevent deadlock. |
| 1908 | SourceLocation PreviousCriticalLoc; |
| 1909 | bool DeadLock = |
| 1910 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 1911 | OpenMPDirectiveKind K, |
| 1912 | const DeclarationNameInfo &DNI, |
| 1913 | SourceLocation Loc) |
| 1914 | ->bool { |
| 1915 | if (K == OMPD_critical && |
| 1916 | DNI.getName() == CurrentName.getName()) { |
| 1917 | PreviousCriticalLoc = Loc; |
| 1918 | return true; |
| 1919 | } else |
| 1920 | return false; |
| 1921 | }, |
| 1922 | false /* skip top directive */); |
| 1923 | if (DeadLock) { |
| 1924 | SemaRef.Diag(StartLoc, |
| 1925 | diag::err_omp_prohibited_region_critical_same_name) |
| 1926 | << CurrentName.getName(); |
| 1927 | if (PreviousCriticalLoc.isValid()) |
| 1928 | SemaRef.Diag(PreviousCriticalLoc, |
| 1929 | diag::note_omp_previous_critical_region); |
| 1930 | return true; |
| 1931 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1932 | } else if (CurrentRegion == OMPD_barrier) { |
| 1933 | // OpenMP [2.16, Nesting of Regions] |
| 1934 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1935 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1936 | NestingProhibited = |
| 1937 | isOpenMPWorksharingDirective(ParentRegion) || |
| 1938 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1939 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1940 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1941 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1942 | // OpenMP [2.16, Nesting of Regions] |
| 1943 | // A worksharing region may not be closely nested inside a worksharing, |
| 1944 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1945 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1946 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1947 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1948 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
| 1949 | Recommend = ShouldBeInParallelRegion; |
| 1950 | } else if (CurrentRegion == OMPD_ordered) { |
| 1951 | // OpenMP [2.16, Nesting of Regions] |
| 1952 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1953 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1954 | // An ordered region must be closely nested inside a loop region (or |
| 1955 | // parallel loop region) with an ordered clause. |
| 1956 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1957 | ParentRegion == OMPD_task || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1958 | !Stack->isParentOrderedRegion(); |
| 1959 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1960 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 1961 | // OpenMP [2.16, Nesting of Regions] |
| 1962 | // If specified, a teams construct must be contained within a target |
| 1963 | // construct. |
| 1964 | NestingProhibited = ParentRegion != OMPD_target; |
| 1965 | Recommend = ShouldBeInTargetRegion; |
| 1966 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 1967 | } |
| 1968 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 1969 | // OpenMP [2.16, Nesting of Regions] |
| 1970 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 1971 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 1972 | // constructs that can be closely nested in the teams region. |
| 1973 | // TODO: add distribute directive. |
| 1974 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 1975 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1976 | } |
| 1977 | if (NestingProhibited) { |
| 1978 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1979 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 1980 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1981 | return true; |
| 1982 | } |
| 1983 | } |
| 1984 | return false; |
| 1985 | } |
| 1986 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1987 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 1988 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 1989 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 1990 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1991 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1992 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 1993 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1994 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1995 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1996 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1997 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1998 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1999 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2000 | if (AStmt) { |
| 2001 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2002 | |
| 2003 | // Check default data sharing attributes for referenced variables. |
| 2004 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2005 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2006 | if (DSAChecker.isErrorFound()) |
| 2007 | return StmtError(); |
| 2008 | // Generate list of implicitly defined firstprivate variables. |
| 2009 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2010 | |
| 2011 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2012 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2013 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2014 | SourceLocation(), SourceLocation())) { |
| 2015 | ClausesWithImplicit.push_back(Implicit); |
| 2016 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2017 | DSAChecker.getImplicitFirstprivate().size(); |
| 2018 | } else |
| 2019 | ErrorFound = true; |
| 2020 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2021 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2022 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2023 | switch (Kind) { |
| 2024 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2025 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2026 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2027 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2028 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2029 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2030 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2031 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2032 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2033 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2034 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2035 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2036 | case OMPD_for_simd: |
| 2037 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2038 | EndLoc, VarsWithInheritedDSA); |
| 2039 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2040 | case OMPD_sections: |
| 2041 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2042 | EndLoc); |
| 2043 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2044 | case OMPD_section: |
| 2045 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2046 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2047 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2048 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2049 | case OMPD_single: |
| 2050 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2051 | EndLoc); |
| 2052 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2053 | case OMPD_master: |
| 2054 | assert(ClausesWithImplicit.empty() && |
| 2055 | "No clauses are allowed for 'omp master' directive"); |
| 2056 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2057 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2058 | case OMPD_critical: |
| 2059 | assert(ClausesWithImplicit.empty() && |
| 2060 | "No clauses are allowed for 'omp critical' directive"); |
| 2061 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2062 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2063 | case OMPD_parallel_for: |
| 2064 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2065 | EndLoc, VarsWithInheritedDSA); |
| 2066 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2067 | case OMPD_parallel_for_simd: |
| 2068 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2069 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2070 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2071 | case OMPD_parallel_sections: |
| 2072 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2073 | StartLoc, EndLoc); |
| 2074 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2075 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2076 | Res = |
| 2077 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2078 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2079 | case OMPD_taskyield: |
| 2080 | assert(ClausesWithImplicit.empty() && |
| 2081 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2082 | assert(AStmt == nullptr && |
| 2083 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2084 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2085 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2086 | case OMPD_barrier: |
| 2087 | assert(ClausesWithImplicit.empty() && |
| 2088 | "No clauses are allowed for 'omp barrier' directive"); |
| 2089 | assert(AStmt == nullptr && |
| 2090 | "No associated statement allowed for 'omp barrier' directive"); |
| 2091 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2092 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2093 | case OMPD_taskwait: |
| 2094 | assert(ClausesWithImplicit.empty() && |
| 2095 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2096 | assert(AStmt == nullptr && |
| 2097 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2098 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2099 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2100 | case OMPD_taskgroup: |
| 2101 | assert(ClausesWithImplicit.empty() && |
| 2102 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2103 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2104 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2105 | case OMPD_flush: |
| 2106 | assert(AStmt == nullptr && |
| 2107 | "No associated statement allowed for 'omp flush' directive"); |
| 2108 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2109 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2110 | case OMPD_ordered: |
| 2111 | assert(ClausesWithImplicit.empty() && |
| 2112 | "No clauses are allowed for 'omp ordered' directive"); |
| 2113 | Res = ActOnOpenMPOrderedDirective(AStmt, StartLoc, EndLoc); |
| 2114 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2115 | case OMPD_atomic: |
| 2116 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2117 | EndLoc); |
| 2118 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2119 | case OMPD_teams: |
| 2120 | Res = |
| 2121 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2122 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2123 | case OMPD_target: |
| 2124 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2125 | EndLoc); |
| 2126 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2127 | case OMPD_cancellation_point: |
| 2128 | assert(ClausesWithImplicit.empty() && |
| 2129 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2130 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2131 | "cancellation point' directive"); |
| 2132 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2133 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2134 | case OMPD_cancel: |
| 2135 | assert(ClausesWithImplicit.empty() && |
| 2136 | "No clauses are allowed for 'omp cancel' directive"); |
| 2137 | assert(AStmt == nullptr && |
| 2138 | "No associated statement allowed for 'omp cancel' directive"); |
| 2139 | Res = ActOnOpenMPCancelDirective(StartLoc, EndLoc, CancelRegion); |
| 2140 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2141 | case OMPD_target_data: |
| 2142 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2143 | EndLoc); |
| 2144 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2145 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2146 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2147 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2148 | llvm_unreachable("Unknown OpenMP directive"); |
| 2149 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2150 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2151 | for (auto P : VarsWithInheritedDSA) { |
| 2152 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2153 | << P.first << P.second->getSourceRange(); |
| 2154 | } |
| 2155 | if (!VarsWithInheritedDSA.empty()) |
| 2156 | return StmtError(); |
| 2157 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2158 | if (ErrorFound) |
| 2159 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2160 | return Res; |
| 2161 | } |
| 2162 | |
| 2163 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2164 | Stmt *AStmt, |
| 2165 | SourceLocation StartLoc, |
| 2166 | SourceLocation EndLoc) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2167 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2168 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2169 | // 1.2.2 OpenMP Language Terminology |
| 2170 | // Structured block - An executable statement with a single entry at the |
| 2171 | // top and a single exit at the bottom. |
| 2172 | // The point of exit cannot be a branch out of the structured block. |
| 2173 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2174 | CS->getCapturedDecl()->setNothrow(); |
| 2175 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2176 | getCurFunction()->setHasBranchProtectedScope(); |
| 2177 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2178 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 2179 | AStmt); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2182 | namespace { |
| 2183 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2184 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2185 | /// for IR generation. |
| 2186 | class OpenMPIterationSpaceChecker { |
| 2187 | /// \brief Reference to Sema. |
| 2188 | Sema &SemaRef; |
| 2189 | /// \brief A location for diagnostics (when there is no some better location). |
| 2190 | SourceLocation DefaultLoc; |
| 2191 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2192 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2193 | /// \brief A source location for referring to loop init later. |
| 2194 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2195 | /// \brief A source location for referring to condition later. |
| 2196 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2197 | /// \brief A source location for referring to increment later. |
| 2198 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2199 | /// \brief Loop variable. |
| 2200 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2201 | /// \brief Reference to loop variable. |
| 2202 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2203 | /// \brief Lower bound (initializer for the var). |
| 2204 | Expr *LB; |
| 2205 | /// \brief Upper bound. |
| 2206 | Expr *UB; |
| 2207 | /// \brief Loop step (increment). |
| 2208 | Expr *Step; |
| 2209 | /// \brief This flag is true when condition is one of: |
| 2210 | /// Var < UB |
| 2211 | /// Var <= UB |
| 2212 | /// UB > Var |
| 2213 | /// UB >= Var |
| 2214 | bool TestIsLessOp; |
| 2215 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2216 | bool TestIsStrictOp; |
| 2217 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2218 | bool SubtractStep; |
| 2219 | |
| 2220 | public: |
| 2221 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2222 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2223 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2224 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2225 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2226 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2227 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2228 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2229 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2230 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2231 | /// for less/greater and for strict/non-strict comparison. |
| 2232 | bool CheckCond(Expr *S); |
| 2233 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2234 | /// does not conform, otherwise save loop step (#Step). |
| 2235 | bool CheckInc(Expr *S); |
| 2236 | /// \brief Return the loop counter variable. |
| 2237 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2238 | /// \brief Return the reference expression to loop counter variable. |
| 2239 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2240 | /// \brief Source range of the loop init. |
| 2241 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2242 | /// \brief Source range of the loop condition. |
| 2243 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2244 | /// \brief Source range of the loop increment. |
| 2245 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2246 | /// \brief True if the step should be subtracted. |
| 2247 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2248 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2249 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2250 | /// \brief Build the precondition expression for the loops. |
| 2251 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2252 | /// \brief Build reference expression to the counter be used for codegen. |
| 2253 | Expr *BuildCounterVar() const; |
| 2254 | /// \brief Build initization of the counter be used for codegen. |
| 2255 | Expr *BuildCounterInit() const; |
| 2256 | /// \brief Build step of the counter be used for codegen. |
| 2257 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2258 | /// \brief Return true if any expression is dependent. |
| 2259 | bool Dependent() const; |
| 2260 | |
| 2261 | private: |
| 2262 | /// \brief Check the right-hand side of an assignment in the increment |
| 2263 | /// expression. |
| 2264 | bool CheckIncRHS(Expr *RHS); |
| 2265 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2266 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2267 | /// \brief Helper to set upper bound. |
| 2268 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR, |
| 2269 | const SourceLocation &SL); |
| 2270 | /// \brief Helper to set loop increment. |
| 2271 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2272 | }; |
| 2273 | |
| 2274 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2275 | if (!Var) { |
| 2276 | assert(!LB && !UB && !Step); |
| 2277 | return false; |
| 2278 | } |
| 2279 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2280 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2281 | } |
| 2282 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2283 | template <typename T> |
| 2284 | static T *getExprAsWritten(T *E) { |
| 2285 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2286 | E = ExprTemp->getSubExpr(); |
| 2287 | |
| 2288 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2289 | E = MTE->GetTemporaryExpr(); |
| 2290 | |
| 2291 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2292 | E = Binder->getSubExpr(); |
| 2293 | |
| 2294 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2295 | E = ICE->getSubExprAsWritten(); |
| 2296 | return E->IgnoreParens(); |
| 2297 | } |
| 2298 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2299 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2300 | DeclRefExpr *NewVarRefExpr, |
| 2301 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2302 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2303 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2304 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2305 | if (!NewVar || !NewLB) |
| 2306 | return true; |
| 2307 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2308 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2309 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2310 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2311 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2312 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2313 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2314 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2315 | LB = NewLB; |
| 2316 | return false; |
| 2317 | } |
| 2318 | |
| 2319 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| 2320 | const SourceRange &SR, |
| 2321 | const SourceLocation &SL) { |
| 2322 | // State consistency checking to ensure correct usage. |
| 2323 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2324 | !TestIsLessOp && !TestIsStrictOp); |
| 2325 | if (!NewUB) |
| 2326 | return true; |
| 2327 | UB = NewUB; |
| 2328 | TestIsLessOp = LessOp; |
| 2329 | TestIsStrictOp = StrictOp; |
| 2330 | ConditionSrcRange = SR; |
| 2331 | ConditionLoc = SL; |
| 2332 | return false; |
| 2333 | } |
| 2334 | |
| 2335 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2336 | // State consistency checking to ensure correct usage. |
| 2337 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2338 | if (!NewStep) |
| 2339 | return true; |
| 2340 | if (!NewStep->isValueDependent()) { |
| 2341 | // Check that the step is integer expression. |
| 2342 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2343 | ExprResult Val = |
| 2344 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2345 | if (Val.isInvalid()) |
| 2346 | return true; |
| 2347 | NewStep = Val.get(); |
| 2348 | |
| 2349 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2350 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2351 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2352 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2353 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2354 | // the loop. |
| 2355 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2356 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2357 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2358 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2359 | // the loop. |
| 2360 | llvm::APSInt Result; |
| 2361 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2362 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2363 | bool IsConstNeg = |
| 2364 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2365 | bool IsConstPos = |
| 2366 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2367 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2368 | if (UB && (IsConstZero || |
| 2369 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2370 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2371 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2372 | diag::err_omp_loop_incr_not_compatible) |
| 2373 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2374 | SemaRef.Diag(ConditionLoc, |
| 2375 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2376 | << TestIsLessOp << ConditionSrcRange; |
| 2377 | return true; |
| 2378 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2379 | if (TestIsLessOp == Subtract) { |
| 2380 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2381 | NewStep).get(); |
| 2382 | Subtract = !Subtract; |
| 2383 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2384 | } |
| 2385 | |
| 2386 | Step = NewStep; |
| 2387 | SubtractStep = Subtract; |
| 2388 | return false; |
| 2389 | } |
| 2390 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2391 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2392 | // Check init-expr for canonical loop form and save loop counter |
| 2393 | // variable - #Var and its initialization value - #LB. |
| 2394 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2395 | // var = lb |
| 2396 | // integer-type var = lb |
| 2397 | // random-access-iterator-type var = lb |
| 2398 | // pointer-type var = lb |
| 2399 | // |
| 2400 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2401 | if (EmitDiags) { |
| 2402 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2403 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2404 | return true; |
| 2405 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2406 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2407 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2408 | S = E->IgnoreParens(); |
| 2409 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2410 | if (BO->getOpcode() == BO_Assign) |
| 2411 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2412 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2413 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2414 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2415 | if (DS->isSingleDecl()) { |
| 2416 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
| 2417 | if (Var->hasInit()) { |
| 2418 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2419 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2420 | SemaRef.Diag(S->getLocStart(), |
| 2421 | diag::ext_omp_loop_not_canonical_init) |
| 2422 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2423 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2424 | } |
| 2425 | } |
| 2426 | } |
| 2427 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2428 | if (CE->getOperator() == OO_Equal) |
| 2429 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2430 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2431 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2432 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2433 | if (EmitDiags) { |
| 2434 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2435 | << S->getSourceRange(); |
| 2436 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2437 | return true; |
| 2438 | } |
| 2439 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2440 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2441 | /// variable (which may be the loop variable) if possible. |
| 2442 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2443 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2444 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2445 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2446 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2447 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2448 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2449 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2450 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2451 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2452 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2453 | if (!DRE) |
| 2454 | return nullptr; |
| 2455 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2456 | } |
| 2457 | |
| 2458 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2459 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2460 | // less/greater and for strict/non-strict comparison. |
| 2461 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2462 | // var relational-op b |
| 2463 | // b relational-op var |
| 2464 | // |
| 2465 | if (!S) { |
| 2466 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2467 | return true; |
| 2468 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2469 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2470 | SourceLocation CondLoc = S->getLocStart(); |
| 2471 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2472 | if (BO->isRelationalOp()) { |
| 2473 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2474 | return SetUB(BO->getRHS(), |
| 2475 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2476 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2477 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2478 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2479 | return SetUB(BO->getLHS(), |
| 2480 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2481 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2482 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2483 | } |
| 2484 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2485 | if (CE->getNumArgs() == 2) { |
| 2486 | auto Op = CE->getOperator(); |
| 2487 | switch (Op) { |
| 2488 | case OO_Greater: |
| 2489 | case OO_GreaterEqual: |
| 2490 | case OO_Less: |
| 2491 | case OO_LessEqual: |
| 2492 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2493 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2494 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2495 | CE->getOperatorLoc()); |
| 2496 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2497 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2498 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2499 | CE->getOperatorLoc()); |
| 2500 | break; |
| 2501 | default: |
| 2502 | break; |
| 2503 | } |
| 2504 | } |
| 2505 | } |
| 2506 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2507 | << S->getSourceRange() << Var; |
| 2508 | return true; |
| 2509 | } |
| 2510 | |
| 2511 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2512 | // RHS of canonical loop form increment can be: |
| 2513 | // var + incr |
| 2514 | // incr + var |
| 2515 | // var - incr |
| 2516 | // |
| 2517 | RHS = RHS->IgnoreParenImpCasts(); |
| 2518 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2519 | if (BO->isAdditiveOp()) { |
| 2520 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2521 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2522 | return SetStep(BO->getRHS(), !IsAdd); |
| 2523 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2524 | return SetStep(BO->getLHS(), false); |
| 2525 | } |
| 2526 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2527 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2528 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2529 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2530 | return SetStep(CE->getArg(1), !IsAdd); |
| 2531 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2532 | return SetStep(CE->getArg(0), false); |
| 2533 | } |
| 2534 | } |
| 2535 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2536 | << RHS->getSourceRange() << Var; |
| 2537 | return true; |
| 2538 | } |
| 2539 | |
| 2540 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2541 | // Check incr-expr for canonical loop form and return true if it |
| 2542 | // does not conform. |
| 2543 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2544 | // ++var |
| 2545 | // var++ |
| 2546 | // --var |
| 2547 | // var-- |
| 2548 | // var += incr |
| 2549 | // var -= incr |
| 2550 | // var = var + incr |
| 2551 | // var = incr + var |
| 2552 | // var = var - incr |
| 2553 | // |
| 2554 | if (!S) { |
| 2555 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2556 | return true; |
| 2557 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2558 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2559 | S = S->IgnoreParens(); |
| 2560 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2561 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2562 | return SetStep( |
| 2563 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2564 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2565 | false); |
| 2566 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2567 | switch (BO->getOpcode()) { |
| 2568 | case BO_AddAssign: |
| 2569 | case BO_SubAssign: |
| 2570 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2571 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2572 | break; |
| 2573 | case BO_Assign: |
| 2574 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2575 | return CheckIncRHS(BO->getRHS()); |
| 2576 | break; |
| 2577 | default: |
| 2578 | break; |
| 2579 | } |
| 2580 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2581 | switch (CE->getOperator()) { |
| 2582 | case OO_PlusPlus: |
| 2583 | case OO_MinusMinus: |
| 2584 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2585 | return SetStep( |
| 2586 | SemaRef.ActOnIntegerConstant( |
| 2587 | CE->getLocStart(), |
| 2588 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2589 | false); |
| 2590 | break; |
| 2591 | case OO_PlusEqual: |
| 2592 | case OO_MinusEqual: |
| 2593 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2594 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2595 | break; |
| 2596 | case OO_Equal: |
| 2597 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2598 | return CheckIncRHS(CE->getArg(1)); |
| 2599 | break; |
| 2600 | default: |
| 2601 | break; |
| 2602 | } |
| 2603 | } |
| 2604 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2605 | << S->getSourceRange() << Var; |
| 2606 | return true; |
| 2607 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2608 | |
| 2609 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2610 | Expr * |
| 2611 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2612 | const bool LimitedType) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2613 | ExprResult Diff; |
| 2614 | if (Var->getType()->isIntegerType() || Var->getType()->isPointerType() || |
| 2615 | SemaRef.getLangOpts().CPlusPlus) { |
| 2616 | // Upper - Lower |
| 2617 | Expr *Upper = TestIsLessOp ? UB : LB; |
| 2618 | Expr *Lower = TestIsLessOp ? LB : UB; |
| 2619 | |
| 2620 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2621 | |
| 2622 | if (!Diff.isUsable() && Var->getType()->getAsCXXRecordDecl()) { |
| 2623 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2624 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2625 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2626 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2627 | return nullptr; |
| 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | if (!Diff.isUsable()) |
| 2632 | return nullptr; |
| 2633 | |
| 2634 | // Upper - Lower [- 1] |
| 2635 | if (TestIsStrictOp) |
| 2636 | Diff = SemaRef.BuildBinOp( |
| 2637 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2638 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2639 | if (!Diff.isUsable()) |
| 2640 | return nullptr; |
| 2641 | |
| 2642 | // Upper - Lower [- 1] + Step |
| 2643 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), |
| 2644 | Step->IgnoreImplicit()); |
| 2645 | if (!Diff.isUsable()) |
| 2646 | return nullptr; |
| 2647 | |
| 2648 | // Parentheses (for dumping/debugging purposes only). |
| 2649 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 2650 | if (!Diff.isUsable()) |
| 2651 | return nullptr; |
| 2652 | |
| 2653 | // (Upper - Lower [- 1] + Step) / Step |
| 2654 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), |
| 2655 | Step->IgnoreImplicit()); |
| 2656 | if (!Diff.isUsable()) |
| 2657 | return nullptr; |
| 2658 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2659 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
| 2660 | if (LimitedType) { |
| 2661 | auto &C = SemaRef.Context; |
| 2662 | QualType Type = Diff.get()->getType(); |
| 2663 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 2664 | if (NewSize != C.getTypeSize(Type)) { |
| 2665 | if (NewSize < C.getTypeSize(Type)) { |
| 2666 | assert(NewSize == 64 && "incorrect loop var size"); |
| 2667 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 2668 | << InitSrcRange << ConditionSrcRange; |
| 2669 | } |
| 2670 | QualType NewType = C.getIntTypeForBitwidth( |
| 2671 | NewSize, Type->hasSignedIntegerRepresentation()); |
| 2672 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 2673 | Sema::AA_Converting, true); |
| 2674 | if (!Diff.isUsable()) |
| 2675 | return nullptr; |
| 2676 | } |
| 2677 | } |
| 2678 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2679 | return Diff.get(); |
| 2680 | } |
| 2681 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2682 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 2683 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 2684 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 2685 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 2686 | auto CondExpr = SemaRef.BuildBinOp( |
| 2687 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 2688 | : (TestIsStrictOp ? BO_GT : BO_GE), |
| 2689 | LB, UB); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2690 | if (CondExpr.isUsable()) { |
| 2691 | CondExpr = SemaRef.PerformImplicitConversion( |
| 2692 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 2693 | /*AllowExplicit=*/true); |
| 2694 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2695 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 2696 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 2697 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 2698 | } |
| 2699 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2700 | /// \brief Build reference expression to the counter be used for codegen. |
| 2701 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 2702 | return buildDeclRefExpr(SemaRef, Var, Var->getType(), DefaultLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | /// \brief Build initization of the counter be used for codegen. |
| 2706 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 2707 | |
| 2708 | /// \brief Build step of the counter be used for codegen. |
| 2709 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 2710 | |
| 2711 | /// \brief Iteration space of a single for loop. |
| 2712 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2713 | /// \brief Condition of the loop. |
| 2714 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2715 | /// \brief This expression calculates the number of iterations in the loop. |
| 2716 | /// It is always possible to calculate it before starting the loop. |
| 2717 | Expr *NumIterations; |
| 2718 | /// \brief The loop counter variable. |
| 2719 | Expr *CounterVar; |
| 2720 | /// \brief This is initializer for the initial value of #CounterVar. |
| 2721 | Expr *CounterInit; |
| 2722 | /// \brief This is step for the #CounterVar used to generate its update: |
| 2723 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 2724 | Expr *CounterStep; |
| 2725 | /// \brief Should step be subtracted? |
| 2726 | bool Subtract; |
| 2727 | /// \brief Source range of the loop init. |
| 2728 | SourceRange InitSrcRange; |
| 2729 | /// \brief Source range of the loop condition. |
| 2730 | SourceRange CondSrcRange; |
| 2731 | /// \brief Source range of the loop increment. |
| 2732 | SourceRange IncSrcRange; |
| 2733 | }; |
| 2734 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2735 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2736 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2737 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 2738 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 2739 | assert(Init && "Expected loop in canonical form."); |
| 2740 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 2741 | if (CollapseIteration > 0 && |
| 2742 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 2743 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 2744 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 2745 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 2746 | } |
| 2747 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 2748 | } |
| 2749 | } |
| 2750 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2751 | /// \brief Called on a for stmt to check and extract its iteration space |
| 2752 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2753 | static bool CheckOpenMPIterationSpace( |
| 2754 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 2755 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2756 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2757 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 2758 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2759 | // OpenMP [2.6, Canonical Loop Form] |
| 2760 | // for (init-expr; test-expr; incr-expr) structured-block |
| 2761 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 2762 | if (!For) { |
| 2763 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2764 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 2765 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 2766 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 2767 | if (NestedLoopCount > 1) { |
| 2768 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 2769 | SemaRef.Diag(DSA.getConstructLoc(), |
| 2770 | diag::note_omp_collapse_ordered_expr) |
| 2771 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 2772 | << OrderedLoopCountExpr->getSourceRange(); |
| 2773 | else if (CollapseLoopCountExpr) |
| 2774 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 2775 | diag::note_omp_collapse_ordered_expr) |
| 2776 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 2777 | else |
| 2778 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 2779 | diag::note_omp_collapse_ordered_expr) |
| 2780 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 2781 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2782 | return true; |
| 2783 | } |
| 2784 | assert(For->getBody()); |
| 2785 | |
| 2786 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 2787 | |
| 2788 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2789 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2790 | if (ISC.CheckInit(Init)) { |
| 2791 | return true; |
| 2792 | } |
| 2793 | |
| 2794 | bool HasErrors = false; |
| 2795 | |
| 2796 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2797 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2798 | |
| 2799 | // OpenMP [2.6, Canonical Loop Form] |
| 2800 | // Var is one of the following: |
| 2801 | // A variable of signed or unsigned integer type. |
| 2802 | // For C++, a variable of a random access iterator type. |
| 2803 | // For C, a variable of a pointer type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2804 | auto VarType = Var->getType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2805 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 2806 | !VarType->isPointerType() && |
| 2807 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 2808 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 2809 | << SemaRef.getLangOpts().CPlusPlus; |
| 2810 | HasErrors = true; |
| 2811 | } |
| 2812 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2813 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 2814 | // Construct |
| 2815 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2816 | // parallel for construct is (are) private. |
| 2817 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2818 | // with just one associated for-loop is linear with a constant-linear-step |
| 2819 | // that is the increment of the associated for-loop. |
| 2820 | // Exclude loop var from the list of variables with implicitly defined data |
| 2821 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 2822 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2823 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2824 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 2825 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 2826 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2827 | // with just one associated for-loop may be listed in a linear clause with a |
| 2828 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2829 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2830 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2831 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2832 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 2833 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 2834 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2835 | auto PredeterminedCKind = |
| 2836 | isOpenMPSimdDirective(DKind) |
| 2837 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 2838 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2839 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 2840 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2841 | (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && |
| 2842 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 2843 | DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) && |
| 2844 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 2845 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2846 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2847 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 2848 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 2849 | if (DVar.RefExpr == nullptr) |
| 2850 | DVar.CKind = PredeterminedCKind; |
| 2851 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2852 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2853 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2854 | // Make the loop iteration variable private (for worksharing constructs), |
| 2855 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2856 | // lastprivate (for simd directives with several collapsed or ordered |
| 2857 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 2858 | if (DVar.CKind == OMPC_unknown) |
| 2859 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 2860 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2861 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2862 | } |
| 2863 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2864 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2865 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2866 | // Check test-expr. |
| 2867 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 2868 | |
| 2869 | // Check incr-expr. |
| 2870 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 2871 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2872 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2873 | return HasErrors; |
| 2874 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2875 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2876 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2877 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
| 2878 | DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2879 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
| 2880 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 2881 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 2882 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 2883 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 2884 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 2885 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 2886 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2887 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 2888 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2889 | ResultIterSpace.CounterVar == nullptr || |
| 2890 | ResultIterSpace.CounterInit == nullptr || |
| 2891 | ResultIterSpace.CounterStep == nullptr); |
| 2892 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2893 | return HasErrors; |
| 2894 | } |
| 2895 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2896 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 2897 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 2898 | SourceLocation Loc, ExprResult VarRef, |
| 2899 | ExprResult Start, ExprResult Iter, |
| 2900 | ExprResult Step, bool Subtract) { |
| 2901 | // Add parentheses (for debugging purposes only). |
| 2902 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 2903 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 2904 | !Step.isUsable()) |
| 2905 | return ExprError(); |
| 2906 | |
| 2907 | ExprResult Update = SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), |
| 2908 | Step.get()->IgnoreImplicit()); |
| 2909 | if (!Update.isUsable()) |
| 2910 | return ExprError(); |
| 2911 | |
| 2912 | // Build 'VarRef = Start + Iter * Step'. |
| 2913 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
| 2914 | Start.get()->IgnoreImplicit(), Update.get()); |
| 2915 | if (!Update.isUsable()) |
| 2916 | return ExprError(); |
| 2917 | |
| 2918 | Update = SemaRef.PerformImplicitConversion( |
| 2919 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 2920 | if (!Update.isUsable()) |
| 2921 | return ExprError(); |
| 2922 | |
| 2923 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 2924 | return Update; |
| 2925 | } |
| 2926 | |
| 2927 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 2928 | /// bits. |
| 2929 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 2930 | Sema &SemaRef) { |
| 2931 | if (E == nullptr) |
| 2932 | return ExprError(); |
| 2933 | auto &C = SemaRef.Context; |
| 2934 | QualType OldType = E->getType(); |
| 2935 | unsigned HasBits = C.getTypeSize(OldType); |
| 2936 | if (HasBits >= Bits) |
| 2937 | return ExprResult(E); |
| 2938 | // OK to convert to signed, because new type has more bits than old. |
| 2939 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 2940 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 2941 | true); |
| 2942 | } |
| 2943 | |
| 2944 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 2945 | /// into \a Bits bits. |
| 2946 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 2947 | if (E == nullptr) |
| 2948 | return false; |
| 2949 | llvm::APSInt Result; |
| 2950 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 2951 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 2952 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | /// \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] | 2956 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 2957 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2958 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2959 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 2960 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 2961 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2962 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 2963 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2964 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2965 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2966 | // Found 'collapse' clause - calculate collapse number. |
| 2967 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2968 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 2969 | NestedLoopCount += Result.getLimitedValue() - 1; |
| 2970 | } |
| 2971 | if (OrderedLoopCountExpr) { |
| 2972 | // Found 'ordered' clause - calculate collapse number. |
| 2973 | llvm::APSInt Result; |
| 2974 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 2975 | NestedLoopCount += Result.getLimitedValue() - 1; |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2976 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2977 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 2978 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2979 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 2980 | IterSpaces.resize(NestedLoopCount); |
| 2981 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2982 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 2983 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2984 | NestedLoopCount, CollapseLoopCountExpr, |
| 2985 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 2986 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 2987 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2988 | // 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] | 2989 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2990 | // All loops associated with the construct must be perfectly nested; that |
| 2991 | // is, there must be no intervening code nor any OpenMP directive between |
| 2992 | // any two loops. |
| 2993 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2994 | } |
| 2995 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2996 | Built.clear(/* size */ NestedLoopCount); |
| 2997 | |
| 2998 | if (SemaRef.CurContext->isDependentContext()) |
| 2999 | return NestedLoopCount; |
| 3000 | |
| 3001 | // An example of what is generated for the following code: |
| 3002 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3003 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3004 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3005 | // for (k = 0; k < NK; ++k) |
| 3006 | // for (j = J0; j < NJ; j+=2) { |
| 3007 | // <loop body> |
| 3008 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3009 | // |
| 3010 | // We generate the code below. |
| 3011 | // Note: the loop body may be outlined in CodeGen. |
| 3012 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3013 | // iterations and operator+= to calculate counter value. |
| 3014 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3015 | // or i64 is currently supported). |
| 3016 | // |
| 3017 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3018 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3019 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3020 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3021 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3022 | // <loop body (using local i and j)> |
| 3023 | // } |
| 3024 | // i = NI; // assign final values of counters |
| 3025 | // j = NJ; |
| 3026 | // |
| 3027 | |
| 3028 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3029 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3030 | // Precondition tests if there is at least one iteration (all conditions are |
| 3031 | // true). |
| 3032 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3033 | auto N0 = IterSpaces[0].NumIterations; |
| 3034 | ExprResult LastIteration32 = WidenIterationCount(32 /* Bits */, N0, SemaRef); |
| 3035 | ExprResult LastIteration64 = WidenIterationCount(64 /* Bits */, N0, SemaRef); |
| 3036 | |
| 3037 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3038 | return NestedLoopCount; |
| 3039 | |
| 3040 | auto &C = SemaRef.Context; |
| 3041 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3042 | |
| 3043 | Scope *CurScope = DSA.getCurScope(); |
| 3044 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3045 | if (PreCond.isUsable()) { |
| 3046 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3047 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3048 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3049 | auto N = IterSpaces[Cnt].NumIterations; |
| 3050 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3051 | if (LastIteration32.isUsable()) |
| 3052 | LastIteration32 = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_Mul, |
| 3053 | LastIteration32.get(), N); |
| 3054 | if (LastIteration64.isUsable()) |
| 3055 | LastIteration64 = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_Mul, |
| 3056 | LastIteration64.get(), N); |
| 3057 | } |
| 3058 | |
| 3059 | // Choose either the 32-bit or 64-bit version. |
| 3060 | ExprResult LastIteration = LastIteration64; |
| 3061 | if (LastIteration32.isUsable() && |
| 3062 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3063 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3064 | FitsInto( |
| 3065 | 32 /* Bits */, |
| 3066 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3067 | LastIteration64.get(), SemaRef))) |
| 3068 | LastIteration = LastIteration32; |
| 3069 | |
| 3070 | if (!LastIteration.isUsable()) |
| 3071 | return 0; |
| 3072 | |
| 3073 | // Save the number of iterations. |
| 3074 | ExprResult NumIterations = LastIteration; |
| 3075 | { |
| 3076 | LastIteration = SemaRef.BuildBinOp( |
| 3077 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3078 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3079 | if (!LastIteration.isUsable()) |
| 3080 | return 0; |
| 3081 | } |
| 3082 | |
| 3083 | // Calculate the last iteration number beforehand instead of doing this on |
| 3084 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3085 | llvm::APSInt Result; |
| 3086 | bool IsConstant = |
| 3087 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3088 | ExprResult CalcLastIteration; |
| 3089 | if (!IsConstant) { |
| 3090 | SourceLocation SaveLoc; |
| 3091 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3092 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3093 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3094 | ExprResult SaveRef = buildDeclRefExpr( |
| 3095 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3096 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3097 | SaveRef.get(), LastIteration.get()); |
| 3098 | LastIteration = SaveRef; |
| 3099 | |
| 3100 | // Prepare SaveRef + 1. |
| 3101 | NumIterations = SemaRef.BuildBinOp( |
| 3102 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3103 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3104 | if (!NumIterations.isUsable()) |
| 3105 | return 0; |
| 3106 | } |
| 3107 | |
| 3108 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3109 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3110 | QualType VType = LastIteration.get()->getType(); |
| 3111 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3112 | ExprResult LB, UB, IL, ST, EUB; |
| 3113 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3114 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3115 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3116 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3117 | SemaRef.AddInitializerToDecl( |
| 3118 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3119 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3120 | |
| 3121 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3122 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3123 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3124 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3125 | /*DirectInit*/ false, |
| 3126 | /*TypeMayContainAuto*/ false); |
| 3127 | |
| 3128 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3129 | // This will be used to implement clause 'lastprivate'. |
| 3130 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3131 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3132 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3133 | SemaRef.AddInitializerToDecl( |
| 3134 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3135 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3136 | |
| 3137 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3138 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3139 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3140 | SemaRef.AddInitializerToDecl( |
| 3141 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3142 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3143 | |
| 3144 | // Build expression: UB = min(UB, LastIteration) |
| 3145 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3146 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3147 | UB.get(), LastIteration.get()); |
| 3148 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3149 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3150 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3151 | CondOp.get()); |
| 3152 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3153 | } |
| 3154 | |
| 3155 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3156 | ExprResult IV; |
| 3157 | ExprResult Init; |
| 3158 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3159 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3160 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3161 | Expr *RHS = isOpenMPWorksharingDirective(DKind) |
| 3162 | ? LB.get() |
| 3163 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3164 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3165 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3166 | } |
| 3167 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3168 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3169 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3170 | ExprResult Cond = |
| 3171 | isOpenMPWorksharingDirective(DKind) |
| 3172 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3173 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3174 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3175 | |
| 3176 | // Loop increment (IV = IV + 1) |
| 3177 | SourceLocation IncLoc; |
| 3178 | ExprResult Inc = |
| 3179 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3180 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3181 | if (!Inc.isUsable()) |
| 3182 | return 0; |
| 3183 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3184 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3185 | if (!Inc.isUsable()) |
| 3186 | return 0; |
| 3187 | |
| 3188 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3189 | // Used for directives with static scheduling. |
| 3190 | ExprResult NextLB, NextUB; |
| 3191 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3192 | // LB + ST |
| 3193 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3194 | if (!NextLB.isUsable()) |
| 3195 | return 0; |
| 3196 | // LB = LB + ST |
| 3197 | NextLB = |
| 3198 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3199 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3200 | if (!NextLB.isUsable()) |
| 3201 | return 0; |
| 3202 | // UB + ST |
| 3203 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3204 | if (!NextUB.isUsable()) |
| 3205 | return 0; |
| 3206 | // UB = UB + ST |
| 3207 | NextUB = |
| 3208 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3209 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3210 | if (!NextUB.isUsable()) |
| 3211 | return 0; |
| 3212 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3213 | |
| 3214 | // Build updates and final values of the loop counters. |
| 3215 | bool HasErrors = false; |
| 3216 | Built.Counters.resize(NestedLoopCount); |
| 3217 | Built.Updates.resize(NestedLoopCount); |
| 3218 | Built.Finals.resize(NestedLoopCount); |
| 3219 | { |
| 3220 | ExprResult Div; |
| 3221 | // Go from inner nested loop to outer. |
| 3222 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3223 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3224 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3225 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3226 | // where Div is product of previous iterations' IS.NumIters. |
| 3227 | ExprResult Iter; |
| 3228 | if (Div.isUsable()) { |
| 3229 | Iter = |
| 3230 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3231 | } else { |
| 3232 | Iter = IV; |
| 3233 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3234 | "unusable div expected on first iteration only"); |
| 3235 | } |
| 3236 | |
| 3237 | if (Cnt != 0 && Iter.isUsable()) |
| 3238 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3239 | IS.NumIterations); |
| 3240 | if (!Iter.isUsable()) { |
| 3241 | HasErrors = true; |
| 3242 | break; |
| 3243 | } |
| 3244 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3245 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3246 | auto *CounterVar = buildDeclRefExpr( |
| 3247 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3248 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3249 | /*RefersToCapture=*/true); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3250 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3251 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3252 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3253 | if (!Update.isUsable()) { |
| 3254 | HasErrors = true; |
| 3255 | break; |
| 3256 | } |
| 3257 | |
| 3258 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3259 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3260 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3261 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3262 | if (!Final.isUsable()) { |
| 3263 | HasErrors = true; |
| 3264 | break; |
| 3265 | } |
| 3266 | |
| 3267 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3268 | if (Cnt != 0) { |
| 3269 | if (Div.isUnset()) |
| 3270 | Div = IS.NumIterations; |
| 3271 | else |
| 3272 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3273 | IS.NumIterations); |
| 3274 | |
| 3275 | // Add parentheses (for debugging purposes only). |
| 3276 | if (Div.isUsable()) |
| 3277 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3278 | if (!Div.isUsable()) { |
| 3279 | HasErrors = true; |
| 3280 | break; |
| 3281 | } |
| 3282 | } |
| 3283 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3284 | HasErrors = true; |
| 3285 | break; |
| 3286 | } |
| 3287 | // Save results |
| 3288 | Built.Counters[Cnt] = IS.CounterVar; |
| 3289 | Built.Updates[Cnt] = Update.get(); |
| 3290 | Built.Finals[Cnt] = Final.get(); |
| 3291 | } |
| 3292 | } |
| 3293 | |
| 3294 | if (HasErrors) |
| 3295 | return 0; |
| 3296 | |
| 3297 | // Save results |
| 3298 | Built.IterationVarRef = IV.get(); |
| 3299 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3300 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3301 | Built.CalcLastIteration = |
| 3302 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3303 | Built.PreCond = PreCond.get(); |
| 3304 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3305 | Built.Init = Init.get(); |
| 3306 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3307 | Built.LB = LB.get(); |
| 3308 | Built.UB = UB.get(); |
| 3309 | Built.IL = IL.get(); |
| 3310 | Built.ST = ST.get(); |
| 3311 | Built.EUB = EUB.get(); |
| 3312 | Built.NLB = NextLB.get(); |
| 3313 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3314 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3315 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3316 | } |
| 3317 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3318 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 3319 | auto &&CollapseFilter = [](const OMPClause *C) -> bool { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3320 | return C->getClauseKind() == OMPC_collapse; |
| 3321 | }; |
| 3322 | OMPExecutableDirective::filtered_clause_iterator<decltype(CollapseFilter)> I( |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 3323 | Clauses, std::move(CollapseFilter)); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3324 | if (I) |
| 3325 | return cast<OMPCollapseClause>(*I)->getNumForLoops(); |
| 3326 | return nullptr; |
| 3327 | } |
| 3328 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3329 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
| 3330 | auto &&OrderedFilter = [](const OMPClause *C) -> bool { |
| 3331 | return C->getClauseKind() == OMPC_ordered; |
| 3332 | }; |
| 3333 | OMPExecutableDirective::filtered_clause_iterator<decltype(OrderedFilter)> I( |
| 3334 | Clauses, std::move(OrderedFilter)); |
| 3335 | if (I) |
| 3336 | return cast<OMPOrderedClause>(*I)->getNumForLoops(); |
| 3337 | return nullptr; |
| 3338 | } |
| 3339 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3340 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3341 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3342 | SourceLocation EndLoc, |
| 3343 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3344 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3345 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3346 | // define the nested loops number. |
| 3347 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3348 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3349 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3350 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3351 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3352 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3353 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3354 | "omp simd loop exprs were not built"); |
| 3355 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3356 | if (!CurContext->isDependentContext()) { |
| 3357 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3358 | for (auto C : Clauses) { |
| 3359 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3360 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3361 | B.NumIterations, *this, CurScope)) |
| 3362 | return StmtError(); |
| 3363 | } |
| 3364 | } |
| 3365 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3366 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3367 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3368 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3369 | } |
| 3370 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3371 | StmtResult Sema::ActOnOpenMPForDirective( |
| 3372 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3373 | SourceLocation EndLoc, |
| 3374 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3375 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3376 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3377 | // define the nested loops number. |
| 3378 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3379 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3380 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3381 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3382 | return StmtError(); |
| 3383 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3384 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3385 | "omp for loop exprs were not built"); |
| 3386 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3387 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3388 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3389 | Clauses, AStmt, B); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3390 | } |
| 3391 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3392 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 3393 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3394 | SourceLocation EndLoc, |
| 3395 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3396 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3397 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3398 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3399 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3400 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 3401 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3402 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3403 | if (NestedLoopCount == 0) |
| 3404 | return StmtError(); |
| 3405 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3406 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3407 | "omp for simd loop exprs were not built"); |
| 3408 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 3409 | if (!CurContext->isDependentContext()) { |
| 3410 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3411 | for (auto C : Clauses) { |
| 3412 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3413 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3414 | B.NumIterations, *this, CurScope)) |
| 3415 | return StmtError(); |
| 3416 | } |
| 3417 | } |
| 3418 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3419 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3420 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3421 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3422 | } |
| 3423 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3424 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3425 | Stmt *AStmt, |
| 3426 | SourceLocation StartLoc, |
| 3427 | SourceLocation EndLoc) { |
| 3428 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3429 | auto BaseStmt = AStmt; |
| 3430 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3431 | BaseStmt = CS->getCapturedStmt(); |
| 3432 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3433 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3434 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3435 | return StmtError(); |
| 3436 | // All associated statements must be '#pragma omp section' except for |
| 3437 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3438 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3439 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3440 | if (SectionStmt) |
| 3441 | Diag(SectionStmt->getLocStart(), |
| 3442 | diag::err_omp_sections_substmt_not_section); |
| 3443 | return StmtError(); |
| 3444 | } |
| 3445 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3446 | } else { |
| 3447 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 3448 | return StmtError(); |
| 3449 | } |
| 3450 | |
| 3451 | getCurFunction()->setHasBranchProtectedScope(); |
| 3452 | |
| 3453 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 3454 | AStmt); |
| 3455 | } |
| 3456 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3457 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 3458 | SourceLocation StartLoc, |
| 3459 | SourceLocation EndLoc) { |
| 3460 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3461 | |
| 3462 | getCurFunction()->setHasBranchProtectedScope(); |
| 3463 | |
| 3464 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3465 | } |
| 3466 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3467 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 3468 | Stmt *AStmt, |
| 3469 | SourceLocation StartLoc, |
| 3470 | SourceLocation EndLoc) { |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3471 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3472 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3473 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3474 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 3475 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 3476 | // The copyprivate clause must not be used with the nowait clause. |
| 3477 | OMPClause *Nowait = nullptr; |
| 3478 | OMPClause *Copyprivate = nullptr; |
| 3479 | for (auto *Clause : Clauses) { |
| 3480 | if (Clause->getClauseKind() == OMPC_nowait) |
| 3481 | Nowait = Clause; |
| 3482 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 3483 | Copyprivate = Clause; |
| 3484 | if (Copyprivate && Nowait) { |
| 3485 | Diag(Copyprivate->getLocStart(), |
| 3486 | diag::err_omp_single_copyprivate_with_nowait); |
| 3487 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 3488 | return StmtError(); |
| 3489 | } |
| 3490 | } |
| 3491 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3492 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3493 | } |
| 3494 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3495 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 3496 | SourceLocation StartLoc, |
| 3497 | SourceLocation EndLoc) { |
| 3498 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3499 | |
| 3500 | getCurFunction()->setHasBranchProtectedScope(); |
| 3501 | |
| 3502 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3503 | } |
| 3504 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3505 | StmtResult |
| 3506 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 3507 | Stmt *AStmt, SourceLocation StartLoc, |
| 3508 | SourceLocation EndLoc) { |
| 3509 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3510 | |
| 3511 | getCurFunction()->setHasBranchProtectedScope(); |
| 3512 | |
| 3513 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 3514 | AStmt); |
| 3515 | } |
| 3516 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3517 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 3518 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3519 | SourceLocation EndLoc, |
| 3520 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3521 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3522 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3523 | // 1.2.2 OpenMP Language Terminology |
| 3524 | // Structured block - An executable statement with a single entry at the |
| 3525 | // top and a single exit at the bottom. |
| 3526 | // The point of exit cannot be a branch out of the structured block. |
| 3527 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3528 | CS->getCapturedDecl()->setNothrow(); |
| 3529 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3530 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3531 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3532 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3533 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3534 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 3535 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3536 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3537 | if (NestedLoopCount == 0) |
| 3538 | return StmtError(); |
| 3539 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3540 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3541 | "omp parallel for loop exprs were not built"); |
| 3542 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3543 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3544 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 3545 | NestedLoopCount, Clauses, AStmt, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3546 | } |
| 3547 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3548 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 3549 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3550 | SourceLocation EndLoc, |
| 3551 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3552 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3553 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3554 | // 1.2.2 OpenMP Language Terminology |
| 3555 | // Structured block - An executable statement with a single entry at the |
| 3556 | // top and a single exit at the bottom. |
| 3557 | // The point of exit cannot be a branch out of the structured block. |
| 3558 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3559 | CS->getCapturedDecl()->setNothrow(); |
| 3560 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3561 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3562 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3563 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3564 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3565 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 3566 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3567 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3568 | if (NestedLoopCount == 0) |
| 3569 | return StmtError(); |
| 3570 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 3571 | if (!CurContext->isDependentContext()) { |
| 3572 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3573 | for (auto C : Clauses) { |
| 3574 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3575 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3576 | B.NumIterations, *this, CurScope)) |
| 3577 | return StmtError(); |
| 3578 | } |
| 3579 | } |
| 3580 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3581 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3582 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3583 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3584 | } |
| 3585 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3586 | StmtResult |
| 3587 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3588 | Stmt *AStmt, SourceLocation StartLoc, |
| 3589 | SourceLocation EndLoc) { |
| 3590 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3591 | auto BaseStmt = AStmt; |
| 3592 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3593 | BaseStmt = CS->getCapturedStmt(); |
| 3594 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3595 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3596 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3597 | return StmtError(); |
| 3598 | // All associated statements must be '#pragma omp section' except for |
| 3599 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3600 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3601 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3602 | if (SectionStmt) |
| 3603 | Diag(SectionStmt->getLocStart(), |
| 3604 | diag::err_omp_parallel_sections_substmt_not_section); |
| 3605 | return StmtError(); |
| 3606 | } |
| 3607 | } |
| 3608 | } else { |
| 3609 | Diag(AStmt->getLocStart(), |
| 3610 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 3611 | return StmtError(); |
| 3612 | } |
| 3613 | |
| 3614 | getCurFunction()->setHasBranchProtectedScope(); |
| 3615 | |
| 3616 | return OMPParallelSectionsDirective::Create(Context, StartLoc, EndLoc, |
| 3617 | Clauses, AStmt); |
| 3618 | } |
| 3619 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3620 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 3621 | Stmt *AStmt, SourceLocation StartLoc, |
| 3622 | SourceLocation EndLoc) { |
| 3623 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3624 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3625 | // 1.2.2 OpenMP Language Terminology |
| 3626 | // Structured block - An executable statement with a single entry at the |
| 3627 | // top and a single exit at the bottom. |
| 3628 | // The point of exit cannot be a branch out of the structured block. |
| 3629 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3630 | CS->getCapturedDecl()->setNothrow(); |
| 3631 | |
| 3632 | getCurFunction()->setHasBranchProtectedScope(); |
| 3633 | |
| 3634 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3635 | } |
| 3636 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3637 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 3638 | SourceLocation EndLoc) { |
| 3639 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 3640 | } |
| 3641 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3642 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 3643 | SourceLocation EndLoc) { |
| 3644 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 3645 | } |
| 3646 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3647 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 3648 | SourceLocation EndLoc) { |
| 3649 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 3650 | } |
| 3651 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3652 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 3653 | SourceLocation StartLoc, |
| 3654 | SourceLocation EndLoc) { |
| 3655 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3656 | |
| 3657 | getCurFunction()->setHasBranchProtectedScope(); |
| 3658 | |
| 3659 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3660 | } |
| 3661 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3662 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 3663 | SourceLocation StartLoc, |
| 3664 | SourceLocation EndLoc) { |
| 3665 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 3666 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 3667 | } |
| 3668 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3669 | StmtResult Sema::ActOnOpenMPOrderedDirective(Stmt *AStmt, |
| 3670 | SourceLocation StartLoc, |
| 3671 | SourceLocation EndLoc) { |
| 3672 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3673 | |
| 3674 | getCurFunction()->setHasBranchProtectedScope(); |
| 3675 | |
| 3676 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3677 | } |
| 3678 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3679 | namespace { |
| 3680 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 3681 | /// construct. |
| 3682 | class OpenMPAtomicUpdateChecker { |
| 3683 | /// \brief Error results for atomic update expressions. |
| 3684 | enum ExprAnalysisErrorCode { |
| 3685 | /// \brief A statement is not an expression statement. |
| 3686 | NotAnExpression, |
| 3687 | /// \brief Expression is not builtin binary or unary operation. |
| 3688 | NotABinaryOrUnaryExpression, |
| 3689 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 3690 | NotAnUnaryIncDecExpression, |
| 3691 | /// \brief An expression is not of scalar type. |
| 3692 | NotAScalarType, |
| 3693 | /// \brief A binary operation is not an assignment operation. |
| 3694 | NotAnAssignmentOp, |
| 3695 | /// \brief RHS part of the binary operation is not a binary expression. |
| 3696 | NotABinaryExpression, |
| 3697 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 3698 | /// expression. |
| 3699 | NotABinaryOperator, |
| 3700 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 3701 | /// part. |
| 3702 | NotAnUpdateExpression, |
| 3703 | /// \brief No errors is found. |
| 3704 | NoError |
| 3705 | }; |
| 3706 | /// \brief Reference to Sema. |
| 3707 | Sema &SemaRef; |
| 3708 | /// \brief A location for note diagnostics (when error is found). |
| 3709 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3710 | /// \brief 'x' lvalue part of the source atomic expression. |
| 3711 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3712 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 3713 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3714 | /// \brief Helper expression of the form |
| 3715 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 3716 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 3717 | Expr *UpdateExpr; |
| 3718 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 3719 | /// important for non-associative operations. |
| 3720 | bool IsXLHSInRHSPart; |
| 3721 | BinaryOperatorKind Op; |
| 3722 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3723 | /// \brief true if the source expression is a postfix unary operation, false |
| 3724 | /// if it is a prefix unary operation. |
| 3725 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3726 | |
| 3727 | public: |
| 3728 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3729 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3730 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3731 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 3732 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3733 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 3734 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3735 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 3736 | /// \param NoteId Diagnostic note for the main error message. |
| 3737 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3738 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3739 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 3740 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3741 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 3742 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3743 | /// \brief Return the update expression used in calculation of the updated |
| 3744 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 3745 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 3746 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 3747 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 3748 | /// false otherwise. |
| 3749 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 3750 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3751 | /// \brief true if the source expression is a postfix unary operation, false |
| 3752 | /// if it is a prefix unary operation. |
| 3753 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 3754 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3755 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3756 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 3757 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3758 | }; |
| 3759 | } // namespace |
| 3760 | |
| 3761 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 3762 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 3763 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 3764 | SourceLocation ErrorLoc, NoteLoc; |
| 3765 | SourceRange ErrorRange, NoteRange; |
| 3766 | // Allowed constructs are: |
| 3767 | // x = x binop expr; |
| 3768 | // x = expr binop x; |
| 3769 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 3770 | X = AtomicBinOp->getLHS(); |
| 3771 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 3772 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 3773 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 3774 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 3775 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3776 | Op = AtomicInnerBinOp->getOpcode(); |
| 3777 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3778 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 3779 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 3780 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 3781 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 3782 | /*Canonical=*/true); |
| 3783 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 3784 | /*Canonical=*/true); |
| 3785 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 3786 | /*Canonical=*/true); |
| 3787 | if (XId == LHSId) { |
| 3788 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3789 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3790 | } else if (XId == RHSId) { |
| 3791 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3792 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3793 | } else { |
| 3794 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 3795 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 3796 | NoteLoc = X->getExprLoc(); |
| 3797 | NoteRange = X->getSourceRange(); |
| 3798 | ErrorFound = NotAnUpdateExpression; |
| 3799 | } |
| 3800 | } else { |
| 3801 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 3802 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 3803 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 3804 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3805 | ErrorFound = NotABinaryOperator; |
| 3806 | } |
| 3807 | } else { |
| 3808 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 3809 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 3810 | ErrorFound = NotABinaryExpression; |
| 3811 | } |
| 3812 | } else { |
| 3813 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 3814 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 3815 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 3816 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3817 | ErrorFound = NotAnAssignmentOp; |
| 3818 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3819 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3820 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 3821 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 3822 | return true; |
| 3823 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3824 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3825 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3826 | } |
| 3827 | |
| 3828 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 3829 | unsigned NoteId) { |
| 3830 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 3831 | SourceLocation ErrorLoc, NoteLoc; |
| 3832 | SourceRange ErrorRange, NoteRange; |
| 3833 | // Allowed constructs are: |
| 3834 | // x++; |
| 3835 | // x--; |
| 3836 | // ++x; |
| 3837 | // --x; |
| 3838 | // x binop= expr; |
| 3839 | // x = x binop expr; |
| 3840 | // x = expr binop x; |
| 3841 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 3842 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 3843 | if (AtomicBody->getType()->isScalarType() || |
| 3844 | AtomicBody->isInstantiationDependent()) { |
| 3845 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 3846 | AtomicBody->IgnoreParenImpCasts())) { |
| 3847 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3848 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3849 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3850 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3851 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3852 | X = AtomicCompAssignOp->getLHS(); |
| 3853 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3854 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 3855 | AtomicBody->IgnoreParenImpCasts())) { |
| 3856 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3857 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 3858 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3859 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3860 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 3861 | // Check for Unary Operation |
| 3862 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3863 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3864 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 3865 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 3866 | X = AtomicUnaryOp->getSubExpr(); |
| 3867 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 3868 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3869 | } else { |
| 3870 | ErrorFound = NotAnUnaryIncDecExpression; |
| 3871 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 3872 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 3873 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 3874 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 3875 | } |
| 3876 | } else { |
| 3877 | ErrorFound = NotABinaryOrUnaryExpression; |
| 3878 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 3879 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 3880 | } |
| 3881 | } else { |
| 3882 | ErrorFound = NotAScalarType; |
| 3883 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 3884 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 3885 | } |
| 3886 | } else { |
| 3887 | ErrorFound = NotAnExpression; |
| 3888 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 3889 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 3890 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3891 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3892 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 3893 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 3894 | return true; |
| 3895 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3896 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3897 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3898 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 3899 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 3900 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 3901 | auto *OVEX = new (SemaRef.getASTContext()) |
| 3902 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 3903 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 3904 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 3905 | auto Update = |
| 3906 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 3907 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 3908 | if (Update.isInvalid()) |
| 3909 | return true; |
| 3910 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 3911 | Sema::AA_Casting); |
| 3912 | if (Update.isInvalid()) |
| 3913 | return true; |
| 3914 | UpdateExpr = Update.get(); |
| 3915 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 3916 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3917 | } |
| 3918 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3919 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 3920 | Stmt *AStmt, |
| 3921 | SourceLocation StartLoc, |
| 3922 | SourceLocation EndLoc) { |
| 3923 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3924 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3925 | // 1.2.2 OpenMP Language Terminology |
| 3926 | // Structured block - An executable statement with a single entry at the |
| 3927 | // top and a single exit at the bottom. |
| 3928 | // The point of exit cannot be a branch out of the structured block. |
| 3929 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3930 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 3931 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3932 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 3933 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3934 | C->getClauseKind() == OMPC_update || |
| 3935 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3936 | if (AtomicKind != OMPC_unknown) { |
| 3937 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 3938 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 3939 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 3940 | << getOpenMPClauseName(AtomicKind); |
| 3941 | } else { |
| 3942 | AtomicKind = C->getClauseKind(); |
| 3943 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 3944 | } |
| 3945 | } |
| 3946 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3947 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 3948 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 3949 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 3950 | Body = EWC->getSubExpr(); |
| 3951 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3952 | Expr *X = nullptr; |
| 3953 | Expr *V = nullptr; |
| 3954 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3955 | Expr *UE = nullptr; |
| 3956 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3957 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3958 | // OpenMP [2.12.6, atomic Construct] |
| 3959 | // In the next expressions: |
| 3960 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 3961 | // * During the execution of an atomic region, multiple syntactic |
| 3962 | // occurrences of x must designate the same storage location. |
| 3963 | // * Neither of v and expr (as applicable) may access the storage location |
| 3964 | // designated by x. |
| 3965 | // * Neither of x and expr (as applicable) may access the storage location |
| 3966 | // designated by v. |
| 3967 | // * expr is an expression with scalar type. |
| 3968 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 3969 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 3970 | // * The expression x binop expr must be numerically equivalent to x binop |
| 3971 | // (expr). This requirement is satisfied if the operators in expr have |
| 3972 | // precedence greater than binop, or by using parentheses around expr or |
| 3973 | // subexpressions of expr. |
| 3974 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 3975 | // binop x. This requirement is satisfied if the operators in expr have |
| 3976 | // precedence equal to or greater than binop, or by using parentheses around |
| 3977 | // expr or subexpressions of expr. |
| 3978 | // * For forms that allow multiple occurrences of x, the number of times |
| 3979 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 3980 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3981 | enum { |
| 3982 | NotAnExpression, |
| 3983 | NotAnAssignmentOp, |
| 3984 | NotAScalarType, |
| 3985 | NotAnLValue, |
| 3986 | NoError |
| 3987 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 3988 | SourceLocation ErrorLoc, NoteLoc; |
| 3989 | SourceRange ErrorRange, NoteRange; |
| 3990 | // If clause is read: |
| 3991 | // v = x; |
| 3992 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 3993 | auto AtomicBinOp = |
| 3994 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 3995 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 3996 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 3997 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 3998 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 3999 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4000 | if (!X->isLValue() || !V->isLValue()) { |
| 4001 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4002 | ErrorFound = NotAnLValue; |
| 4003 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4004 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4005 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4006 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4007 | } |
| 4008 | } else if (!X->isInstantiationDependent() || |
| 4009 | !V->isInstantiationDependent()) { |
| 4010 | auto NotScalarExpr = |
| 4011 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4012 | ? V |
| 4013 | : X; |
| 4014 | ErrorFound = NotAScalarType; |
| 4015 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4016 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4017 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4018 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4019 | } |
| 4020 | } else { |
| 4021 | ErrorFound = NotAnAssignmentOp; |
| 4022 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4023 | ErrorRange = AtomicBody->getSourceRange(); |
| 4024 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4025 | : AtomicBody->getExprLoc(); |
| 4026 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4027 | : AtomicBody->getSourceRange(); |
| 4028 | } |
| 4029 | } else { |
| 4030 | ErrorFound = NotAnExpression; |
| 4031 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4032 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4033 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4034 | if (ErrorFound != NoError) { |
| 4035 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4036 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4037 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4038 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4039 | return StmtError(); |
| 4040 | } else if (CurContext->isDependentContext()) |
| 4041 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4042 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4043 | enum { |
| 4044 | NotAnExpression, |
| 4045 | NotAnAssignmentOp, |
| 4046 | NotAScalarType, |
| 4047 | NotAnLValue, |
| 4048 | NoError |
| 4049 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4050 | SourceLocation ErrorLoc, NoteLoc; |
| 4051 | SourceRange ErrorRange, NoteRange; |
| 4052 | // If clause is write: |
| 4053 | // x = expr; |
| 4054 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4055 | auto AtomicBinOp = |
| 4056 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4057 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4058 | X = AtomicBinOp->getLHS(); |
| 4059 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4060 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4061 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4062 | if (!X->isLValue()) { |
| 4063 | ErrorFound = NotAnLValue; |
| 4064 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4065 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4066 | NoteLoc = X->getExprLoc(); |
| 4067 | NoteRange = X->getSourceRange(); |
| 4068 | } |
| 4069 | } else if (!X->isInstantiationDependent() || |
| 4070 | !E->isInstantiationDependent()) { |
| 4071 | auto NotScalarExpr = |
| 4072 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4073 | ? E |
| 4074 | : X; |
| 4075 | ErrorFound = NotAScalarType; |
| 4076 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4077 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4078 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4079 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4080 | } |
| 4081 | } else { |
| 4082 | ErrorFound = NotAnAssignmentOp; |
| 4083 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4084 | ErrorRange = AtomicBody->getSourceRange(); |
| 4085 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4086 | : AtomicBody->getExprLoc(); |
| 4087 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4088 | : AtomicBody->getSourceRange(); |
| 4089 | } |
| 4090 | } else { |
| 4091 | ErrorFound = NotAnExpression; |
| 4092 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4093 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4094 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4095 | if (ErrorFound != NoError) { |
| 4096 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4097 | << ErrorRange; |
| 4098 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4099 | << NoteRange; |
| 4100 | return StmtError(); |
| 4101 | } else if (CurContext->isDependentContext()) |
| 4102 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4103 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4104 | // If clause is update: |
| 4105 | // x++; |
| 4106 | // x--; |
| 4107 | // ++x; |
| 4108 | // --x; |
| 4109 | // x binop= expr; |
| 4110 | // x = x binop expr; |
| 4111 | // x = expr binop x; |
| 4112 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4113 | if (Checker.checkStatement( |
| 4114 | Body, (AtomicKind == OMPC_update) |
| 4115 | ? diag::err_omp_atomic_update_not_expression_statement |
| 4116 | : diag::err_omp_atomic_not_expression_statement, |
| 4117 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4118 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4119 | if (!CurContext->isDependentContext()) { |
| 4120 | E = Checker.getExpr(); |
| 4121 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4122 | UE = Checker.getUpdateExpr(); |
| 4123 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4124 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4125 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4126 | enum { |
| 4127 | NotAnAssignmentOp, |
| 4128 | NotACompoundStatement, |
| 4129 | NotTwoSubstatements, |
| 4130 | NotASpecificExpression, |
| 4131 | NoError |
| 4132 | } ErrorFound = NoError; |
| 4133 | SourceLocation ErrorLoc, NoteLoc; |
| 4134 | SourceRange ErrorRange, NoteRange; |
| 4135 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 4136 | // If clause is a capture: |
| 4137 | // v = x++; |
| 4138 | // v = x--; |
| 4139 | // v = ++x; |
| 4140 | // v = --x; |
| 4141 | // v = x binop= expr; |
| 4142 | // v = x = x binop expr; |
| 4143 | // v = x = expr binop x; |
| 4144 | auto *AtomicBinOp = |
| 4145 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4146 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4147 | V = AtomicBinOp->getLHS(); |
| 4148 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4149 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4150 | if (Checker.checkStatement( |
| 4151 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 4152 | diag::note_omp_atomic_update)) |
| 4153 | return StmtError(); |
| 4154 | E = Checker.getExpr(); |
| 4155 | X = Checker.getX(); |
| 4156 | UE = Checker.getUpdateExpr(); |
| 4157 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 4158 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
| 4159 | } else { |
| 4160 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4161 | ErrorRange = AtomicBody->getSourceRange(); |
| 4162 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4163 | : AtomicBody->getExprLoc(); |
| 4164 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4165 | : AtomicBody->getSourceRange(); |
| 4166 | ErrorFound = NotAnAssignmentOp; |
| 4167 | } |
| 4168 | if (ErrorFound != NoError) { |
| 4169 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 4170 | << ErrorRange; |
| 4171 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4172 | return StmtError(); |
| 4173 | } else if (CurContext->isDependentContext()) { |
| 4174 | UE = V = E = X = nullptr; |
| 4175 | } |
| 4176 | } else { |
| 4177 | // If clause is a capture: |
| 4178 | // { v = x; x = expr; } |
| 4179 | // { v = x; x++; } |
| 4180 | // { v = x; x--; } |
| 4181 | // { v = x; ++x; } |
| 4182 | // { v = x; --x; } |
| 4183 | // { v = x; x binop= expr; } |
| 4184 | // { v = x; x = x binop expr; } |
| 4185 | // { v = x; x = expr binop x; } |
| 4186 | // { x++; v = x; } |
| 4187 | // { x--; v = x; } |
| 4188 | // { ++x; v = x; } |
| 4189 | // { --x; v = x; } |
| 4190 | // { x binop= expr; v = x; } |
| 4191 | // { x = x binop expr; v = x; } |
| 4192 | // { x = expr binop x; v = x; } |
| 4193 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 4194 | // Check that this is { expr1; expr2; } |
| 4195 | if (CS->size() == 2) { |
| 4196 | auto *First = CS->body_front(); |
| 4197 | auto *Second = CS->body_back(); |
| 4198 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 4199 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4200 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 4201 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4202 | // Need to find what subexpression is 'v' and what is 'x'. |
| 4203 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4204 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 4205 | BinaryOperator *BinOp = nullptr; |
| 4206 | if (IsUpdateExprFound) { |
| 4207 | BinOp = dyn_cast<BinaryOperator>(First); |
| 4208 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4209 | } |
| 4210 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4211 | // { v = x; x++; } |
| 4212 | // { v = x; x--; } |
| 4213 | // { v = x; ++x; } |
| 4214 | // { v = x; --x; } |
| 4215 | // { v = x; x binop= expr; } |
| 4216 | // { v = x; x = x binop expr; } |
| 4217 | // { v = x; x = expr binop x; } |
| 4218 | // Check that the first expression has form v = x. |
| 4219 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4220 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4221 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4222 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4223 | IsUpdateExprFound = XId == PossibleXId; |
| 4224 | if (IsUpdateExprFound) { |
| 4225 | V = BinOp->getLHS(); |
| 4226 | X = Checker.getX(); |
| 4227 | E = Checker.getExpr(); |
| 4228 | UE = Checker.getUpdateExpr(); |
| 4229 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4230 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4231 | } |
| 4232 | } |
| 4233 | if (!IsUpdateExprFound) { |
| 4234 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 4235 | BinOp = nullptr; |
| 4236 | if (IsUpdateExprFound) { |
| 4237 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 4238 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4239 | } |
| 4240 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4241 | // { x++; v = x; } |
| 4242 | // { x--; v = x; } |
| 4243 | // { ++x; v = x; } |
| 4244 | // { --x; v = x; } |
| 4245 | // { x binop= expr; v = x; } |
| 4246 | // { x = x binop expr; v = x; } |
| 4247 | // { x = expr binop x; v = x; } |
| 4248 | // Check that the second expression has form v = x. |
| 4249 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4250 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4251 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4252 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4253 | IsUpdateExprFound = XId == PossibleXId; |
| 4254 | if (IsUpdateExprFound) { |
| 4255 | V = BinOp->getLHS(); |
| 4256 | X = Checker.getX(); |
| 4257 | E = Checker.getExpr(); |
| 4258 | UE = Checker.getUpdateExpr(); |
| 4259 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4260 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4261 | } |
| 4262 | } |
| 4263 | } |
| 4264 | if (!IsUpdateExprFound) { |
| 4265 | // { v = x; x = expr; } |
| 4266 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 4267 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
| 4268 | ErrorFound = NotAnAssignmentOp; |
| 4269 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 4270 | : First->getLocStart(); |
| 4271 | NoteRange = ErrorRange = FirstBinOp |
| 4272 | ? FirstBinOp->getSourceRange() |
| 4273 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4274 | } else { |
| 4275 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 4276 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 4277 | ErrorFound = NotAnAssignmentOp; |
| 4278 | NoteLoc = ErrorLoc = SecondBinOp ? SecondBinOp->getOperatorLoc() |
| 4279 | : Second->getLocStart(); |
| 4280 | NoteRange = ErrorRange = SecondBinOp |
| 4281 | ? SecondBinOp->getSourceRange() |
| 4282 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4283 | } else { |
| 4284 | auto *PossibleXRHSInFirst = |
| 4285 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4286 | auto *PossibleXLHSInSecond = |
| 4287 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4288 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 4289 | PossibleXRHSInFirst->Profile(X1Id, Context, /*Canonical=*/true); |
| 4290 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 4291 | /*Canonical=*/true); |
| 4292 | IsUpdateExprFound = X1Id == X2Id; |
| 4293 | if (IsUpdateExprFound) { |
| 4294 | V = FirstBinOp->getLHS(); |
| 4295 | X = SecondBinOp->getLHS(); |
| 4296 | E = SecondBinOp->getRHS(); |
| 4297 | UE = nullptr; |
| 4298 | IsXLHSInRHSPart = false; |
| 4299 | IsPostfixUpdate = true; |
| 4300 | } else { |
| 4301 | ErrorFound = NotASpecificExpression; |
| 4302 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 4303 | ErrorRange = FirstBinOp->getSourceRange(); |
| 4304 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 4305 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 4306 | } |
| 4307 | } |
| 4308 | } |
| 4309 | } |
| 4310 | } else { |
| 4311 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4312 | NoteRange = ErrorRange = |
| 4313 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4314 | ErrorFound = NotTwoSubstatements; |
| 4315 | } |
| 4316 | } else { |
| 4317 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4318 | NoteRange = ErrorRange = |
| 4319 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4320 | ErrorFound = NotACompoundStatement; |
| 4321 | } |
| 4322 | if (ErrorFound != NoError) { |
| 4323 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 4324 | << ErrorRange; |
| 4325 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4326 | return StmtError(); |
| 4327 | } else if (CurContext->isDependentContext()) { |
| 4328 | UE = V = E = X = nullptr; |
| 4329 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4330 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4331 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4332 | |
| 4333 | getCurFunction()->setHasBranchProtectedScope(); |
| 4334 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4335 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4336 | X, V, E, UE, IsXLHSInRHSPart, |
| 4337 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4340 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 4341 | Stmt *AStmt, |
| 4342 | SourceLocation StartLoc, |
| 4343 | SourceLocation EndLoc) { |
| 4344 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4345 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4346 | // OpenMP [2.16, Nesting of Regions] |
| 4347 | // If specified, a teams construct must be contained within a target |
| 4348 | // construct. That target construct must contain no statements or directives |
| 4349 | // outside of the teams construct. |
| 4350 | if (DSAStack->hasInnerTeamsRegion()) { |
| 4351 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 4352 | bool OMPTeamsFound = true; |
| 4353 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 4354 | auto I = CS->body_begin(); |
| 4355 | while (I != CS->body_end()) { |
| 4356 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 4357 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 4358 | OMPTeamsFound = false; |
| 4359 | break; |
| 4360 | } |
| 4361 | ++I; |
| 4362 | } |
| 4363 | assert(I != CS->body_end() && "Not found statement"); |
| 4364 | S = *I; |
| 4365 | } |
| 4366 | if (!OMPTeamsFound) { |
| 4367 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 4368 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 4369 | diag::note_omp_nested_teams_construct_here); |
| 4370 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 4371 | << isa<OMPExecutableDirective>(S); |
| 4372 | return StmtError(); |
| 4373 | } |
| 4374 | } |
| 4375 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4376 | getCurFunction()->setHasBranchProtectedScope(); |
| 4377 | |
| 4378 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4379 | } |
| 4380 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4381 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 4382 | Stmt *AStmt, |
| 4383 | SourceLocation StartLoc, |
| 4384 | SourceLocation EndLoc) { |
| 4385 | getCurFunction()->setHasBranchProtectedScope(); |
| 4386 | |
| 4387 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 4388 | AStmt); |
| 4389 | } |
| 4390 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4391 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 4392 | Stmt *AStmt, SourceLocation StartLoc, |
| 4393 | SourceLocation EndLoc) { |
| 4394 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4395 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4396 | // 1.2.2 OpenMP Language Terminology |
| 4397 | // Structured block - An executable statement with a single entry at the |
| 4398 | // top and a single exit at the bottom. |
| 4399 | // The point of exit cannot be a branch out of the structured block. |
| 4400 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4401 | CS->getCapturedDecl()->setNothrow(); |
| 4402 | |
| 4403 | getCurFunction()->setHasBranchProtectedScope(); |
| 4404 | |
| 4405 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4406 | } |
| 4407 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4408 | StmtResult |
| 4409 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 4410 | SourceLocation EndLoc, |
| 4411 | OpenMPDirectiveKind CancelRegion) { |
| 4412 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4413 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4414 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4415 | << getOpenMPDirectiveName(CancelRegion); |
| 4416 | return StmtError(); |
| 4417 | } |
| 4418 | if (DSAStack->isParentNowaitRegion()) { |
| 4419 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 4420 | return StmtError(); |
| 4421 | } |
| 4422 | if (DSAStack->isParentOrderedRegion()) { |
| 4423 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 4424 | return StmtError(); |
| 4425 | } |
| 4426 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 4427 | CancelRegion); |
| 4428 | } |
| 4429 | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4430 | StmtResult Sema::ActOnOpenMPCancelDirective(SourceLocation StartLoc, |
| 4431 | SourceLocation EndLoc, |
| 4432 | OpenMPDirectiveKind CancelRegion) { |
| 4433 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4434 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4435 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4436 | << getOpenMPDirectiveName(CancelRegion); |
| 4437 | return StmtError(); |
| 4438 | } |
| 4439 | if (DSAStack->isParentNowaitRegion()) { |
| 4440 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 4441 | return StmtError(); |
| 4442 | } |
| 4443 | if (DSAStack->isParentOrderedRegion()) { |
| 4444 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 4445 | return StmtError(); |
| 4446 | } |
| 4447 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, CancelRegion); |
| 4448 | } |
| 4449 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4450 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4451 | SourceLocation StartLoc, |
| 4452 | SourceLocation LParenLoc, |
| 4453 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4454 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4455 | switch (Kind) { |
| 4456 | case OMPC_if: |
| 4457 | Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4458 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4459 | case OMPC_final: |
| 4460 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4461 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4462 | case OMPC_num_threads: |
| 4463 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4464 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4465 | case OMPC_safelen: |
| 4466 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4467 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4468 | case OMPC_collapse: |
| 4469 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4470 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4471 | case OMPC_ordered: |
| 4472 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 4473 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4474 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4475 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4476 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4477 | case OMPC_private: |
| 4478 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4479 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4480 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4481 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4482 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4483 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4484 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4485 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4486 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4487 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4488 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4489 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4490 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4491 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4492 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4493 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4494 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4495 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4496 | case OMPC_depend: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4497 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4498 | llvm_unreachable("Clause is not allowed."); |
| 4499 | } |
| 4500 | return Res; |
| 4501 | } |
| 4502 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4503 | OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4504 | SourceLocation LParenLoc, |
| 4505 | SourceLocation EndLoc) { |
| 4506 | Expr *ValExpr = Condition; |
| 4507 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 4508 | !Condition->isInstantiationDependent() && |
| 4509 | !Condition->containsUnexpandedParameterPack()) { |
| 4510 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4511 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4512 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4513 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4514 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4515 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 4519 | } |
| 4520 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4521 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 4522 | SourceLocation StartLoc, |
| 4523 | SourceLocation LParenLoc, |
| 4524 | SourceLocation EndLoc) { |
| 4525 | Expr *ValExpr = Condition; |
| 4526 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 4527 | !Condition->isInstantiationDependent() && |
| 4528 | !Condition->containsUnexpandedParameterPack()) { |
| 4529 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 4530 | Condition->getExprLoc(), Condition); |
| 4531 | if (Val.isInvalid()) |
| 4532 | return nullptr; |
| 4533 | |
| 4534 | ValExpr = Val.get(); |
| 4535 | } |
| 4536 | |
| 4537 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 4538 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4539 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 4540 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4541 | if (!Op) |
| 4542 | return ExprError(); |
| 4543 | |
| 4544 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 4545 | public: |
| 4546 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4547 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 4548 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 4549 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4550 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 4551 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4552 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 4553 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4554 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 4555 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4556 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 4557 | QualType T, |
| 4558 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4559 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 4560 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4561 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 4562 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4563 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4564 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4565 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4566 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 4567 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4568 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 4569 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4570 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 4571 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4572 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4573 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4574 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4575 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 4576 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4577 | llvm_unreachable("conversion functions are permitted"); |
| 4578 | } |
| 4579 | } ConvertDiagnoser; |
| 4580 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 4581 | } |
| 4582 | |
| 4583 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 4584 | SourceLocation StartLoc, |
| 4585 | SourceLocation LParenLoc, |
| 4586 | SourceLocation EndLoc) { |
| 4587 | Expr *ValExpr = NumThreads; |
| 4588 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4589 | !NumThreads->containsUnexpandedParameterPack()) { |
| 4590 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 4591 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4592 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4593 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4594 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4595 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4596 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4597 | |
| 4598 | // OpenMP [2.5, Restrictions] |
| 4599 | // The num_threads expression must evaluate to a positive integer value. |
| 4600 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4601 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 4602 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4603 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 4604 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4605 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4606 | } |
| 4607 | } |
| 4608 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4609 | return new (Context) |
| 4610 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4613 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 4614 | OpenMPClauseKind CKind) { |
| 4615 | if (!E) |
| 4616 | return ExprError(); |
| 4617 | if (E->isValueDependent() || E->isTypeDependent() || |
| 4618 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 4619 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4620 | llvm::APSInt Result; |
| 4621 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 4622 | if (ICE.isInvalid()) |
| 4623 | return ExprError(); |
| 4624 | if (!Result.isStrictlyPositive()) { |
| 4625 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 4626 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 4627 | return ExprError(); |
| 4628 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 4629 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 4630 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 4631 | << E->getSourceRange(); |
| 4632 | return ExprError(); |
| 4633 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4634 | if (CKind == OMPC_collapse) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4635 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 4636 | Result.getExtValue()); |
| 4637 | } else if (CKind == OMPC_ordered) { |
| 4638 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 4639 | Result.getExtValue()); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4640 | } |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4641 | return ICE; |
| 4642 | } |
| 4643 | |
| 4644 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 4645 | SourceLocation LParenLoc, |
| 4646 | SourceLocation EndLoc) { |
| 4647 | // OpenMP [2.8.1, simd construct, Description] |
| 4648 | // The parameter of the safelen clause must be a constant |
| 4649 | // positive integer expression. |
| 4650 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 4651 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4652 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4653 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4654 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4657 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 4658 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4659 | SourceLocation LParenLoc, |
| 4660 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4661 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4662 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4663 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4664 | // The parameter of the collapse clause must be a constant |
| 4665 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4666 | ExprResult NumForLoopsResult = |
| 4667 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 4668 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4669 | return nullptr; |
| 4670 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4671 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4672 | } |
| 4673 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4674 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 4675 | SourceLocation EndLoc, |
| 4676 | SourceLocation LParenLoc, |
| 4677 | Expr *NumForLoops) { |
| 4678 | DSAStack->setOrderedRegion(); |
| 4679 | // OpenMP [2.7.1, loop construct, Description] |
| 4680 | // OpenMP [2.8.1, simd construct, Description] |
| 4681 | // OpenMP [2.9.6, distribute construct, Description] |
| 4682 | // The parameter of the ordered clause must be a constant |
| 4683 | // positive integer expression if any. |
| 4684 | if (NumForLoops && LParenLoc.isValid()) { |
| 4685 | ExprResult NumForLoopsResult = |
| 4686 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 4687 | if (NumForLoopsResult.isInvalid()) |
| 4688 | return nullptr; |
| 4689 | NumForLoops = NumForLoopsResult.get(); |
| 4690 | } |
| 4691 | return new (Context) |
| 4692 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 4693 | } |
| 4694 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4695 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 4696 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 4697 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4698 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4699 | switch (Kind) { |
| 4700 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4701 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4702 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 4703 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4704 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4705 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4706 | Res = ActOnOpenMPProcBindClause( |
| 4707 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 4708 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4709 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4710 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4711 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4712 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4713 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4714 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4715 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4716 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4717 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4718 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4719 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4720 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4721 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4722 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4723 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4724 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4725 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4726 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4727 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4728 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4729 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4730 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4731 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4732 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4733 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4734 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4735 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4736 | case OMPC_depend: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4737 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4738 | llvm_unreachable("Clause is not allowed."); |
| 4739 | } |
| 4740 | return Res; |
| 4741 | } |
| 4742 | |
| 4743 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 4744 | SourceLocation KindKwLoc, |
| 4745 | SourceLocation StartLoc, |
| 4746 | SourceLocation LParenLoc, |
| 4747 | SourceLocation EndLoc) { |
| 4748 | if (Kind == OMPC_DEFAULT_unknown) { |
| 4749 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4750 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 4751 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 4752 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4753 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4754 | Values += "'"; |
| 4755 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 4756 | Values += "'"; |
| 4757 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4758 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4759 | Values += " or "; |
| 4760 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4761 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4762 | break; |
| 4763 | default: |
| 4764 | Values += Sep; |
| 4765 | break; |
| 4766 | } |
| 4767 | } |
| 4768 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4769 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4770 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4771 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4772 | switch (Kind) { |
| 4773 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4774 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4775 | break; |
| 4776 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4777 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4778 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4779 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4780 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4781 | break; |
| 4782 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4783 | return new (Context) |
| 4784 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4785 | } |
| 4786 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4787 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 4788 | SourceLocation KindKwLoc, |
| 4789 | SourceLocation StartLoc, |
| 4790 | SourceLocation LParenLoc, |
| 4791 | SourceLocation EndLoc) { |
| 4792 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 4793 | std::string Values; |
| 4794 | std::string Sep(", "); |
| 4795 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 4796 | Values += "'"; |
| 4797 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 4798 | Values += "'"; |
| 4799 | switch (i) { |
| 4800 | case OMPC_PROC_BIND_unknown - 2: |
| 4801 | Values += " or "; |
| 4802 | break; |
| 4803 | case OMPC_PROC_BIND_unknown - 1: |
| 4804 | break; |
| 4805 | default: |
| 4806 | Values += Sep; |
| 4807 | break; |
| 4808 | } |
| 4809 | } |
| 4810 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4811 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4812 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4813 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4814 | return new (Context) |
| 4815 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4816 | } |
| 4817 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4818 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 4819 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 4820 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 4821 | SourceLocation ArgumentLoc, SourceLocation CommaLoc, |
| 4822 | SourceLocation EndLoc) { |
| 4823 | OMPClause *Res = nullptr; |
| 4824 | switch (Kind) { |
| 4825 | case OMPC_schedule: |
| 4826 | Res = ActOnOpenMPScheduleClause( |
| 4827 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
| 4828 | LParenLoc, ArgumentLoc, CommaLoc, EndLoc); |
| 4829 | break; |
| 4830 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4831 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4832 | case OMPC_num_threads: |
| 4833 | case OMPC_safelen: |
| 4834 | case OMPC_collapse: |
| 4835 | case OMPC_default: |
| 4836 | case OMPC_proc_bind: |
| 4837 | case OMPC_private: |
| 4838 | case OMPC_firstprivate: |
| 4839 | case OMPC_lastprivate: |
| 4840 | case OMPC_shared: |
| 4841 | case OMPC_reduction: |
| 4842 | case OMPC_linear: |
| 4843 | case OMPC_aligned: |
| 4844 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4845 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4846 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4847 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4848 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4849 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4850 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4851 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4852 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4853 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4854 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4855 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4856 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4857 | case OMPC_depend: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4858 | case OMPC_unknown: |
| 4859 | llvm_unreachable("Clause is not allowed."); |
| 4860 | } |
| 4861 | return Res; |
| 4862 | } |
| 4863 | |
| 4864 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 4865 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 4866 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 4867 | SourceLocation EndLoc) { |
| 4868 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 4869 | std::string Values; |
| 4870 | std::string Sep(", "); |
| 4871 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 4872 | Values += "'"; |
| 4873 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 4874 | Values += "'"; |
| 4875 | switch (i) { |
| 4876 | case OMPC_SCHEDULE_unknown - 2: |
| 4877 | Values += " or "; |
| 4878 | break; |
| 4879 | case OMPC_SCHEDULE_unknown - 1: |
| 4880 | break; |
| 4881 | default: |
| 4882 | Values += Sep; |
| 4883 | break; |
| 4884 | } |
| 4885 | } |
| 4886 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 4887 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 4888 | return nullptr; |
| 4889 | } |
| 4890 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4891 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4892 | if (ChunkSize) { |
| 4893 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 4894 | !ChunkSize->isInstantiationDependent() && |
| 4895 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 4896 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 4897 | ExprResult Val = |
| 4898 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 4899 | if (Val.isInvalid()) |
| 4900 | return nullptr; |
| 4901 | |
| 4902 | ValExpr = Val.get(); |
| 4903 | |
| 4904 | // OpenMP [2.7.1, Restrictions] |
| 4905 | // chunk_size must be a loop invariant integer expression with a positive |
| 4906 | // value. |
| 4907 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4908 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 4909 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 4910 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 4911 | << "schedule" << ChunkSize->getSourceRange(); |
| 4912 | return nullptr; |
| 4913 | } |
| 4914 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 4915 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 4916 | ChunkSize->getType(), ".chunk."); |
| 4917 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 4918 | ChunkSize->getExprLoc(), |
| 4919 | /*RefersToCapture=*/true); |
| 4920 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4921 | } |
| 4922 | } |
| 4923 | } |
| 4924 | |
| 4925 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 4926 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4929 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 4930 | SourceLocation StartLoc, |
| 4931 | SourceLocation EndLoc) { |
| 4932 | OMPClause *Res = nullptr; |
| 4933 | switch (Kind) { |
| 4934 | case OMPC_ordered: |
| 4935 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 4936 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4937 | case OMPC_nowait: |
| 4938 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 4939 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4940 | case OMPC_untied: |
| 4941 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 4942 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4943 | case OMPC_mergeable: |
| 4944 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 4945 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4946 | case OMPC_read: |
| 4947 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 4948 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4949 | case OMPC_write: |
| 4950 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 4951 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4952 | case OMPC_update: |
| 4953 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 4954 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4955 | case OMPC_capture: |
| 4956 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 4957 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4958 | case OMPC_seq_cst: |
| 4959 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 4960 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4961 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4962 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4963 | case OMPC_num_threads: |
| 4964 | case OMPC_safelen: |
| 4965 | case OMPC_collapse: |
| 4966 | case OMPC_schedule: |
| 4967 | case OMPC_private: |
| 4968 | case OMPC_firstprivate: |
| 4969 | case OMPC_lastprivate: |
| 4970 | case OMPC_shared: |
| 4971 | case OMPC_reduction: |
| 4972 | case OMPC_linear: |
| 4973 | case OMPC_aligned: |
| 4974 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4975 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4976 | case OMPC_default: |
| 4977 | case OMPC_proc_bind: |
| 4978 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4979 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4980 | case OMPC_depend: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4981 | case OMPC_unknown: |
| 4982 | llvm_unreachable("Clause is not allowed."); |
| 4983 | } |
| 4984 | return Res; |
| 4985 | } |
| 4986 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4987 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 4988 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4989 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4990 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 4991 | } |
| 4992 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4993 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 4994 | SourceLocation EndLoc) { |
| 4995 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 4996 | } |
| 4997 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4998 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 4999 | SourceLocation EndLoc) { |
| 5000 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 5001 | } |
| 5002 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5003 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 5004 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5005 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 5006 | } |
| 5007 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5008 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 5009 | SourceLocation EndLoc) { |
| 5010 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 5011 | } |
| 5012 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5013 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 5014 | SourceLocation EndLoc) { |
| 5015 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 5016 | } |
| 5017 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5018 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 5019 | SourceLocation EndLoc) { |
| 5020 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 5021 | } |
| 5022 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5023 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 5024 | SourceLocation EndLoc) { |
| 5025 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 5026 | } |
| 5027 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5028 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 5029 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 5030 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 5031 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5032 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
| 5033 | SourceLocation DepLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5034 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5035 | switch (Kind) { |
| 5036 | case OMPC_private: |
| 5037 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5038 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5039 | case OMPC_firstprivate: |
| 5040 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5041 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5042 | case OMPC_lastprivate: |
| 5043 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5044 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5045 | case OMPC_shared: |
| 5046 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5047 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5048 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5049 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 5050 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5051 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5052 | case OMPC_linear: |
| 5053 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 5054 | ColonLoc, EndLoc); |
| 5055 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5056 | case OMPC_aligned: |
| 5057 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 5058 | ColonLoc, EndLoc); |
| 5059 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5060 | case OMPC_copyin: |
| 5061 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5062 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5063 | case OMPC_copyprivate: |
| 5064 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5065 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5066 | case OMPC_flush: |
| 5067 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5068 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5069 | case OMPC_depend: |
| 5070 | Res = ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList, StartLoc, |
| 5071 | LParenLoc, EndLoc); |
| 5072 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5073 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5074 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5075 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5076 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5077 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5078 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5079 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5080 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5081 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5082 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5083 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5084 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5085 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5086 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5087 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5088 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5089 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5090 | case OMPC_seq_cst: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5091 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5092 | llvm_unreachable("Clause is not allowed."); |
| 5093 | } |
| 5094 | return Res; |
| 5095 | } |
| 5096 | |
| 5097 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 5098 | SourceLocation StartLoc, |
| 5099 | SourceLocation LParenLoc, |
| 5100 | SourceLocation EndLoc) { |
| 5101 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5102 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5103 | for (auto &RefExpr : VarList) { |
| 5104 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 5105 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5106 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5107 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5108 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5109 | continue; |
| 5110 | } |
| 5111 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5112 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5113 | // OpenMP [2.1, C/C++] |
| 5114 | // A list item is a variable name. |
| 5115 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5116 | // A variable that is part of another variable (as an array or |
| 5117 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5118 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5119 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5120 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5121 | continue; |
| 5122 | } |
| 5123 | Decl *D = DE->getDecl(); |
| 5124 | VarDecl *VD = cast<VarDecl>(D); |
| 5125 | |
| 5126 | QualType Type = VD->getType(); |
| 5127 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5128 | // It will be analyzed later. |
| 5129 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5130 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5131 | continue; |
| 5132 | } |
| 5133 | |
| 5134 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5135 | // A variable that appears in a private clause must not have an incomplete |
| 5136 | // type or a reference type. |
| 5137 | if (RequireCompleteType(ELoc, Type, |
| 5138 | diag::err_omp_private_incomplete_type)) { |
| 5139 | continue; |
| 5140 | } |
| 5141 | if (Type->isReferenceType()) { |
| 5142 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5143 | << getOpenMPClauseName(OMPC_private) << Type; |
| 5144 | bool IsDecl = |
| 5145 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5146 | Diag(VD->getLocation(), |
| 5147 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5148 | << VD; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5149 | continue; |
| 5150 | } |
| 5151 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5152 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5153 | // in a Construct] |
| 5154 | // Variables with the predetermined data-sharing attributes may not be |
| 5155 | // listed in data-sharing attributes clauses, except for the cases |
| 5156 | // listed below. For these exceptions only, listing a predetermined |
| 5157 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5158 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5159 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5160 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5161 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5162 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5163 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5164 | continue; |
| 5165 | } |
| 5166 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5167 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5168 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5169 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5170 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5171 | << getOpenMPClauseName(OMPC_private) << Type |
| 5172 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5173 | bool IsDecl = |
| 5174 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5175 | Diag(VD->getLocation(), |
| 5176 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5177 | << VD; |
| 5178 | continue; |
| 5179 | } |
| 5180 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5181 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 5182 | // A variable of class type (or array thereof) that appears in a private |
| 5183 | // clause requires an accessible, unambiguous default constructor for the |
| 5184 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5185 | // Generate helper private variable and initialize it with the default |
| 5186 | // value. The address of the original variable is replaced by the address of |
| 5187 | // the new private variable in CodeGen. This new variable is not added to |
| 5188 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 5189 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5190 | Type = Type.getUnqualifiedType(); |
| 5191 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5192 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5193 | if (VDPrivate->isInvalidDecl()) |
| 5194 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5195 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5196 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5197 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5198 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5199 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5200 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5201 | } |
| 5202 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5203 | if (Vars.empty()) |
| 5204 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5205 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5206 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 5207 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5208 | } |
| 5209 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5210 | namespace { |
| 5211 | class DiagsUninitializedSeveretyRAII { |
| 5212 | private: |
| 5213 | DiagnosticsEngine &Diags; |
| 5214 | SourceLocation SavedLoc; |
| 5215 | bool IsIgnored; |
| 5216 | |
| 5217 | public: |
| 5218 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 5219 | bool IsIgnored) |
| 5220 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 5221 | if (!IsIgnored) { |
| 5222 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 5223 | /*Map*/ diag::Severity::Ignored, Loc); |
| 5224 | } |
| 5225 | } |
| 5226 | ~DiagsUninitializedSeveretyRAII() { |
| 5227 | if (!IsIgnored) |
| 5228 | Diags.popMappings(SavedLoc); |
| 5229 | } |
| 5230 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 5231 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5232 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5233 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 5234 | SourceLocation StartLoc, |
| 5235 | SourceLocation LParenLoc, |
| 5236 | SourceLocation EndLoc) { |
| 5237 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5238 | SmallVector<Expr *, 8> PrivateCopies; |
| 5239 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5240 | bool IsImplicitClause = |
| 5241 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 5242 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 5243 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5244 | for (auto &RefExpr : VarList) { |
| 5245 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 5246 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5247 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5248 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5249 | PrivateCopies.push_back(nullptr); |
| 5250 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5251 | continue; |
| 5252 | } |
| 5253 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5254 | SourceLocation ELoc = |
| 5255 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5256 | // OpenMP [2.1, C/C++] |
| 5257 | // A list item is a variable name. |
| 5258 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5259 | // A variable that is part of another variable (as an array or |
| 5260 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5261 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5262 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5263 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5264 | continue; |
| 5265 | } |
| 5266 | Decl *D = DE->getDecl(); |
| 5267 | VarDecl *VD = cast<VarDecl>(D); |
| 5268 | |
| 5269 | QualType Type = VD->getType(); |
| 5270 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5271 | // It will be analyzed later. |
| 5272 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5273 | PrivateCopies.push_back(nullptr); |
| 5274 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5275 | continue; |
| 5276 | } |
| 5277 | |
| 5278 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5279 | // A variable that appears in a private clause must not have an incomplete |
| 5280 | // type or a reference type. |
| 5281 | if (RequireCompleteType(ELoc, Type, |
| 5282 | diag::err_omp_firstprivate_incomplete_type)) { |
| 5283 | continue; |
| 5284 | } |
| 5285 | if (Type->isReferenceType()) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5286 | if (IsImplicitClause) { |
| 5287 | Diag(ImplicitClauseLoc, |
| 5288 | diag::err_omp_task_predetermined_firstprivate_ref_type_arg) |
| 5289 | << Type; |
| 5290 | Diag(RefExpr->getExprLoc(), diag::note_used_here); |
| 5291 | } else { |
| 5292 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 5293 | << getOpenMPClauseName(OMPC_firstprivate) << Type; |
| 5294 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5295 | bool IsDecl = |
| 5296 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5297 | Diag(VD->getLocation(), |
| 5298 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5299 | << VD; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5300 | continue; |
| 5301 | } |
| 5302 | |
| 5303 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 5304 | // 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] | 5305 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5306 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5307 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5308 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5309 | // If an implicit firstprivate variable found it was checked already. |
| 5310 | if (!IsImplicitClause) { |
| 5311 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5312 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5313 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 5314 | // A list item that specifies a given variable may not appear in more |
| 5315 | // than one clause on the same directive, except that a variable may be |
| 5316 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5317 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5318 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5319 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5320 | << getOpenMPClauseName(DVar.CKind) |
| 5321 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5322 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5323 | continue; |
| 5324 | } |
| 5325 | |
| 5326 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5327 | // in a Construct] |
| 5328 | // Variables with the predetermined data-sharing attributes may not be |
| 5329 | // listed in data-sharing attributes clauses, except for the cases |
| 5330 | // listed below. For these exceptions only, listing a predetermined |
| 5331 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5332 | // the variable's predetermined data-sharing attributes. |
| 5333 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5334 | // in a Construct, C/C++, p.2] |
| 5335 | // Variables with const-qualified type having no mutable member may be |
| 5336 | // listed in a firstprivate clause, even if they are static data members. |
| 5337 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 5338 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 5339 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5340 | << getOpenMPClauseName(DVar.CKind) |
| 5341 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5342 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5343 | continue; |
| 5344 | } |
| 5345 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5346 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5347 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 5348 | // A list item that is private within a parallel region must not appear |
| 5349 | // in a firstprivate clause on a worksharing construct if any of the |
| 5350 | // worksharing regions arising from the worksharing construct ever bind |
| 5351 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5352 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5353 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5354 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 5355 | if (DVar.CKind != OMPC_shared && |
| 5356 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5357 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5358 | Diag(ELoc, diag::err_omp_required_access) |
| 5359 | << getOpenMPClauseName(OMPC_firstprivate) |
| 5360 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5361 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5362 | continue; |
| 5363 | } |
| 5364 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5365 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 5366 | // A list item that appears in a reduction clause of a parallel construct |
| 5367 | // must not appear in a firstprivate clause on a worksharing or task |
| 5368 | // construct if any of the worksharing or task regions arising from the |
| 5369 | // worksharing or task construct ever bind to any of the parallel regions |
| 5370 | // arising from the parallel construct. |
| 5371 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 5372 | // A list item that appears in a reduction clause in worksharing |
| 5373 | // construct must not appear in a firstprivate clause in a task construct |
| 5374 | // encountered during execution of any of the worksharing regions arising |
| 5375 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5376 | if (CurrDir == OMPD_task) { |
| 5377 | DVar = |
| 5378 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 5379 | [](OpenMPDirectiveKind K) -> bool { |
| 5380 | return isOpenMPParallelDirective(K) || |
| 5381 | isOpenMPWorksharingDirective(K); |
| 5382 | }, |
| 5383 | false); |
| 5384 | if (DVar.CKind == OMPC_reduction && |
| 5385 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5386 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 5387 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 5388 | << getOpenMPDirectiveName(DVar.DKind); |
| 5389 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 5390 | continue; |
| 5391 | } |
| 5392 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5393 | } |
| 5394 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5395 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5396 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5397 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5398 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5399 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 5400 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5401 | bool IsDecl = |
| 5402 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5403 | Diag(VD->getLocation(), |
| 5404 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5405 | << VD; |
| 5406 | continue; |
| 5407 | } |
| 5408 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5409 | Type = Type.getUnqualifiedType(); |
| 5410 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName()); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5411 | // Generate helper private variable and initialize it with the value of the |
| 5412 | // original variable. The address of the original variable is replaced by |
| 5413 | // the address of the new private variable in the CodeGen. This new variable |
| 5414 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 5415 | // original variable for proper diagnostics and variable capturing. |
| 5416 | Expr *VDInitRefExpr = nullptr; |
| 5417 | // For arrays generate initializer for single element and replace it by the |
| 5418 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5419 | if (Type->isArrayType()) { |
| 5420 | auto VDInit = |
| 5421 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 5422 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5423 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5424 | ElemType = ElemType.getUnqualifiedType(); |
| 5425 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 5426 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5427 | InitializedEntity Entity = |
| 5428 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5429 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 5430 | |
| 5431 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 5432 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 5433 | if (Result.isInvalid()) |
| 5434 | VDPrivate->setInvalidDecl(); |
| 5435 | else |
| 5436 | VDPrivate->setInit(Result.getAs<Expr>()); |
| 5437 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5438 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5439 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5440 | VDInitRefExpr = |
| 5441 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5442 | AddInitializerToDecl(VDPrivate, |
| 5443 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 5444 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5445 | } |
| 5446 | if (VDPrivate->isInvalidDecl()) { |
| 5447 | if (IsImplicitClause) { |
| 5448 | Diag(DE->getExprLoc(), |
| 5449 | diag::note_omp_task_predetermined_firstprivate_here); |
| 5450 | } |
| 5451 | continue; |
| 5452 | } |
| 5453 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5454 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5455 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5456 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 5457 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5458 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 5459 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5460 | } |
| 5461 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5462 | if (Vars.empty()) |
| 5463 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5464 | |
| 5465 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5466 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5467 | } |
| 5468 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5469 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 5470 | SourceLocation StartLoc, |
| 5471 | SourceLocation LParenLoc, |
| 5472 | SourceLocation EndLoc) { |
| 5473 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5474 | SmallVector<Expr *, 8> SrcExprs; |
| 5475 | SmallVector<Expr *, 8> DstExprs; |
| 5476 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5477 | for (auto &RefExpr : VarList) { |
| 5478 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 5479 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5480 | // It will be analyzed later. |
| 5481 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5482 | SrcExprs.push_back(nullptr); |
| 5483 | DstExprs.push_back(nullptr); |
| 5484 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5485 | continue; |
| 5486 | } |
| 5487 | |
| 5488 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 5489 | // OpenMP [2.1, C/C++] |
| 5490 | // A list item is a variable name. |
| 5491 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 5492 | // A variable that is part of another variable (as an array or structure |
| 5493 | // element) cannot appear in a lastprivate clause. |
| 5494 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 5495 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5496 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 5497 | continue; |
| 5498 | } |
| 5499 | Decl *D = DE->getDecl(); |
| 5500 | VarDecl *VD = cast<VarDecl>(D); |
| 5501 | |
| 5502 | QualType Type = VD->getType(); |
| 5503 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5504 | // It will be analyzed later. |
| 5505 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5506 | SrcExprs.push_back(nullptr); |
| 5507 | DstExprs.push_back(nullptr); |
| 5508 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5509 | continue; |
| 5510 | } |
| 5511 | |
| 5512 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 5513 | // A variable that appears in a lastprivate clause must not have an |
| 5514 | // incomplete type or a reference type. |
| 5515 | if (RequireCompleteType(ELoc, Type, |
| 5516 | diag::err_omp_lastprivate_incomplete_type)) { |
| 5517 | continue; |
| 5518 | } |
| 5519 | if (Type->isReferenceType()) { |
| 5520 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 5521 | << getOpenMPClauseName(OMPC_lastprivate) << Type; |
| 5522 | bool IsDecl = |
| 5523 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5524 | Diag(VD->getLocation(), |
| 5525 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5526 | << VD; |
| 5527 | continue; |
| 5528 | } |
| 5529 | |
| 5530 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5531 | // in a Construct] |
| 5532 | // Variables with the predetermined data-sharing attributes may not be |
| 5533 | // listed in data-sharing attributes clauses, except for the cases |
| 5534 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5535 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5536 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 5537 | DVar.CKind != OMPC_firstprivate && |
| 5538 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 5539 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 5540 | << getOpenMPClauseName(DVar.CKind) |
| 5541 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5542 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5543 | continue; |
| 5544 | } |
| 5545 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5546 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 5547 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 5548 | // A list item that is private within a parallel region, or that appears in |
| 5549 | // the reduction clause of a parallel construct, must not appear in a |
| 5550 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 5551 | // worksharing regions ever binds to any of the corresponding parallel |
| 5552 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5553 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5554 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5555 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5556 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5557 | if (DVar.CKind != OMPC_shared) { |
| 5558 | Diag(ELoc, diag::err_omp_required_access) |
| 5559 | << getOpenMPClauseName(OMPC_lastprivate) |
| 5560 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5561 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5562 | continue; |
| 5563 | } |
| 5564 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5565 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5566 | // A variable of class type (or array thereof) that appears in a |
| 5567 | // lastprivate clause requires an accessible, unambiguous default |
| 5568 | // constructor for the class type, unless the list item is also specified |
| 5569 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5570 | // A variable of class type (or array thereof) that appears in a |
| 5571 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 5572 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5573 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5574 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5575 | Type.getUnqualifiedType(), ".lastprivate.src"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5576 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 5577 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5578 | auto *DstVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5579 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst"); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5580 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5581 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5582 | // For arrays generate assignment operation for single element and replace |
| 5583 | // it by the original array element in CodeGen. |
| 5584 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 5585 | PseudoDstExpr, PseudoSrcExpr); |
| 5586 | if (AssignmentOp.isInvalid()) |
| 5587 | continue; |
| 5588 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 5589 | /*DiscardedValue=*/true); |
| 5590 | if (AssignmentOp.isInvalid()) |
| 5591 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5592 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5593 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5594 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5595 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5596 | SrcExprs.push_back(PseudoSrcExpr); |
| 5597 | DstExprs.push_back(PseudoDstExpr); |
| 5598 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5599 | } |
| 5600 | |
| 5601 | if (Vars.empty()) |
| 5602 | return nullptr; |
| 5603 | |
| 5604 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5605 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5606 | } |
| 5607 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5608 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 5609 | SourceLocation StartLoc, |
| 5610 | SourceLocation LParenLoc, |
| 5611 | SourceLocation EndLoc) { |
| 5612 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5613 | for (auto &RefExpr : VarList) { |
| 5614 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 5615 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5616 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5617 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5618 | continue; |
| 5619 | } |
| 5620 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5621 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5622 | // OpenMP [2.1, C/C++] |
| 5623 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 5624 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 5625 | // A variable that is part of another variable (as an array or structure |
| 5626 | // element) cannot appear in a shared unless it is a static data member |
| 5627 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5628 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5629 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5630 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5631 | continue; |
| 5632 | } |
| 5633 | Decl *D = DE->getDecl(); |
| 5634 | VarDecl *VD = cast<VarDecl>(D); |
| 5635 | |
| 5636 | QualType Type = VD->getType(); |
| 5637 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5638 | // It will be analyzed later. |
| 5639 | Vars.push_back(DE); |
| 5640 | continue; |
| 5641 | } |
| 5642 | |
| 5643 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5644 | // in a Construct] |
| 5645 | // Variables with the predetermined data-sharing attributes may not be |
| 5646 | // listed in data-sharing attributes clauses, except for the cases |
| 5647 | // listed below. For these exceptions only, listing a predetermined |
| 5648 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5649 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5650 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5651 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 5652 | DVar.RefExpr) { |
| 5653 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5654 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5655 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5656 | continue; |
| 5657 | } |
| 5658 | |
| 5659 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 5660 | Vars.push_back(DE); |
| 5661 | } |
| 5662 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5663 | if (Vars.empty()) |
| 5664 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5665 | |
| 5666 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 5667 | } |
| 5668 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5669 | namespace { |
| 5670 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 5671 | DSAStackTy *Stack; |
| 5672 | |
| 5673 | public: |
| 5674 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 5675 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5676 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5677 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 5678 | return false; |
| 5679 | if (DVar.CKind != OMPC_unknown) |
| 5680 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5681 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5682 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5683 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5684 | return true; |
| 5685 | return false; |
| 5686 | } |
| 5687 | return false; |
| 5688 | } |
| 5689 | bool VisitStmt(Stmt *S) { |
| 5690 | for (auto Child : S->children()) { |
| 5691 | if (Child && Visit(Child)) |
| 5692 | return true; |
| 5693 | } |
| 5694 | return false; |
| 5695 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5696 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5697 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5698 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5699 | |
| 5700 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 5701 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 5702 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 5703 | CXXScopeSpec &ReductionIdScopeSpec, |
| 5704 | const DeclarationNameInfo &ReductionId) { |
| 5705 | // TODO: Allow scope specification search when 'declare reduction' is |
| 5706 | // supported. |
| 5707 | assert(ReductionIdScopeSpec.isEmpty() && |
| 5708 | "No support for scoped reduction identifiers yet."); |
| 5709 | |
| 5710 | auto DN = ReductionId.getName(); |
| 5711 | auto OOK = DN.getCXXOverloadedOperator(); |
| 5712 | BinaryOperatorKind BOK = BO_Comma; |
| 5713 | |
| 5714 | // OpenMP [2.14.3.6, reduction clause] |
| 5715 | // C |
| 5716 | // reduction-identifier is either an identifier or one of the following |
| 5717 | // operators: +, -, *, &, |, ^, && and || |
| 5718 | // C++ |
| 5719 | // reduction-identifier is either an id-expression or one of the following |
| 5720 | // operators: +, -, *, &, |, ^, && and || |
| 5721 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 5722 | switch (OOK) { |
| 5723 | case OO_Plus: |
| 5724 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5725 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5726 | break; |
| 5727 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5728 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5729 | break; |
| 5730 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5731 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5732 | break; |
| 5733 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5734 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5735 | break; |
| 5736 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5737 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5738 | break; |
| 5739 | case OO_AmpAmp: |
| 5740 | BOK = BO_LAnd; |
| 5741 | break; |
| 5742 | case OO_PipePipe: |
| 5743 | BOK = BO_LOr; |
| 5744 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5745 | case OO_New: |
| 5746 | case OO_Delete: |
| 5747 | case OO_Array_New: |
| 5748 | case OO_Array_Delete: |
| 5749 | case OO_Slash: |
| 5750 | case OO_Percent: |
| 5751 | case OO_Tilde: |
| 5752 | case OO_Exclaim: |
| 5753 | case OO_Equal: |
| 5754 | case OO_Less: |
| 5755 | case OO_Greater: |
| 5756 | case OO_LessEqual: |
| 5757 | case OO_GreaterEqual: |
| 5758 | case OO_PlusEqual: |
| 5759 | case OO_MinusEqual: |
| 5760 | case OO_StarEqual: |
| 5761 | case OO_SlashEqual: |
| 5762 | case OO_PercentEqual: |
| 5763 | case OO_CaretEqual: |
| 5764 | case OO_AmpEqual: |
| 5765 | case OO_PipeEqual: |
| 5766 | case OO_LessLess: |
| 5767 | case OO_GreaterGreater: |
| 5768 | case OO_LessLessEqual: |
| 5769 | case OO_GreaterGreaterEqual: |
| 5770 | case OO_EqualEqual: |
| 5771 | case OO_ExclaimEqual: |
| 5772 | case OO_PlusPlus: |
| 5773 | case OO_MinusMinus: |
| 5774 | case OO_Comma: |
| 5775 | case OO_ArrowStar: |
| 5776 | case OO_Arrow: |
| 5777 | case OO_Call: |
| 5778 | case OO_Subscript: |
| 5779 | case OO_Conditional: |
| 5780 | case NUM_OVERLOADED_OPERATORS: |
| 5781 | llvm_unreachable("Unexpected reduction identifier"); |
| 5782 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5783 | if (auto II = DN.getAsIdentifierInfo()) { |
| 5784 | if (II->isStr("max")) |
| 5785 | BOK = BO_GT; |
| 5786 | else if (II->isStr("min")) |
| 5787 | BOK = BO_LT; |
| 5788 | } |
| 5789 | break; |
| 5790 | } |
| 5791 | SourceRange ReductionIdRange; |
| 5792 | if (ReductionIdScopeSpec.isValid()) { |
| 5793 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 5794 | } |
| 5795 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 5796 | if (BOK == BO_Comma) { |
| 5797 | // Not allowed reduction identifier is found. |
| 5798 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 5799 | << ReductionIdRange; |
| 5800 | return nullptr; |
| 5801 | } |
| 5802 | |
| 5803 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5804 | SmallVector<Expr *, 8> LHSs; |
| 5805 | SmallVector<Expr *, 8> RHSs; |
| 5806 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5807 | for (auto RefExpr : VarList) { |
| 5808 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 5809 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5810 | // It will be analyzed later. |
| 5811 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5812 | LHSs.push_back(nullptr); |
| 5813 | RHSs.push_back(nullptr); |
| 5814 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5815 | continue; |
| 5816 | } |
| 5817 | |
| 5818 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 5819 | RefExpr->isInstantiationDependent() || |
| 5820 | RefExpr->containsUnexpandedParameterPack()) { |
| 5821 | // It will be analyzed later. |
| 5822 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5823 | LHSs.push_back(nullptr); |
| 5824 | RHSs.push_back(nullptr); |
| 5825 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5826 | continue; |
| 5827 | } |
| 5828 | |
| 5829 | auto ELoc = RefExpr->getExprLoc(); |
| 5830 | auto ERange = RefExpr->getSourceRange(); |
| 5831 | // OpenMP [2.1, C/C++] |
| 5832 | // A list item is a variable or array section, subject to the restrictions |
| 5833 | // specified in Section 2.4 on page 42 and in each of the sections |
| 5834 | // describing clauses and directives for which a list appears. |
| 5835 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 5836 | // A variable that is part of another variable (as an array or |
| 5837 | // structure element) cannot appear in a private clause. |
| 5838 | auto DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 5839 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5840 | Diag(ELoc, diag::err_omp_expected_var_name) << ERange; |
| 5841 | continue; |
| 5842 | } |
| 5843 | auto D = DE->getDecl(); |
| 5844 | auto VD = cast<VarDecl>(D); |
| 5845 | auto Type = VD->getType(); |
| 5846 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5847 | // A variable that appears in a private clause must not have an incomplete |
| 5848 | // type or a reference type. |
| 5849 | if (RequireCompleteType(ELoc, Type, |
| 5850 | diag::err_omp_reduction_incomplete_type)) |
| 5851 | continue; |
| 5852 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5853 | // Arrays may not appear in a reduction clause. |
| 5854 | if (Type.getNonReferenceType()->isArrayType()) { |
| 5855 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
| 5856 | bool IsDecl = |
| 5857 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5858 | Diag(VD->getLocation(), |
| 5859 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5860 | << VD; |
| 5861 | continue; |
| 5862 | } |
| 5863 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5864 | // A list item that appears in a reduction clause must not be |
| 5865 | // const-qualified. |
| 5866 | if (Type.getNonReferenceType().isConstant(Context)) { |
| 5867 | Diag(ELoc, diag::err_omp_const_variable) |
| 5868 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
| 5869 | bool IsDecl = |
| 5870 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5871 | Diag(VD->getLocation(), |
| 5872 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5873 | << VD; |
| 5874 | continue; |
| 5875 | } |
| 5876 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 5877 | // If a list-item is a reference type then it must bind to the same object |
| 5878 | // for all threads of the team. |
| 5879 | VarDecl *VDDef = VD->getDefinition(); |
| 5880 | if (Type->isReferenceType() && VDDef) { |
| 5881 | DSARefChecker Check(DSAStack); |
| 5882 | if (Check.Visit(VDDef->getInit())) { |
| 5883 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 5884 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 5885 | continue; |
| 5886 | } |
| 5887 | } |
| 5888 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 5889 | // The type of a list item that appears in a reduction clause must be valid |
| 5890 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 5891 | // of the list item must be an allowed arithmetic data type: char, int, |
| 5892 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 5893 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 5894 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 5895 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 5896 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 5897 | !(Type->isScalarType() || |
| 5898 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 5899 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 5900 | << getLangOpts().CPlusPlus; |
| 5901 | bool IsDecl = |
| 5902 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5903 | Diag(VD->getLocation(), |
| 5904 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5905 | << VD; |
| 5906 | continue; |
| 5907 | } |
| 5908 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 5909 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 5910 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 5911 | bool IsDecl = |
| 5912 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5913 | Diag(VD->getLocation(), |
| 5914 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5915 | << VD; |
| 5916 | continue; |
| 5917 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5918 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5919 | // in a Construct] |
| 5920 | // Variables with the predetermined data-sharing attributes may not be |
| 5921 | // listed in data-sharing attributes clauses, except for the cases |
| 5922 | // listed below. For these exceptions only, listing a predetermined |
| 5923 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5924 | // the variable's predetermined data-sharing attributes. |
| 5925 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 5926 | // Any number of reduction clauses can be specified on the directive, |
| 5927 | // but a list item can appear only once in the reduction clauses for that |
| 5928 | // directive. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5929 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5930 | if (DVar.CKind == OMPC_reduction) { |
| 5931 | Diag(ELoc, diag::err_omp_once_referenced) |
| 5932 | << getOpenMPClauseName(OMPC_reduction); |
| 5933 | if (DVar.RefExpr) { |
| 5934 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 5935 | } |
| 5936 | } else if (DVar.CKind != OMPC_unknown) { |
| 5937 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 5938 | << getOpenMPClauseName(DVar.CKind) |
| 5939 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5940 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5941 | continue; |
| 5942 | } |
| 5943 | |
| 5944 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 5945 | // A list item that appears in a reduction clause of a worksharing |
| 5946 | // construct must be shared in the parallel regions to which any of the |
| 5947 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5948 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5949 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5950 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5951 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5952 | if (DVar.CKind != OMPC_shared) { |
| 5953 | Diag(ELoc, diag::err_omp_required_access) |
| 5954 | << getOpenMPClauseName(OMPC_reduction) |
| 5955 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5956 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5957 | continue; |
| 5958 | } |
| 5959 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5960 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5961 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs"); |
| 5962 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5963 | // Add initializer for private variable. |
| 5964 | Expr *Init = nullptr; |
| 5965 | switch (BOK) { |
| 5966 | case BO_Add: |
| 5967 | case BO_Xor: |
| 5968 | case BO_Or: |
| 5969 | case BO_LOr: |
| 5970 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 5971 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 5972 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5973 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5974 | break; |
| 5975 | case BO_Mul: |
| 5976 | case BO_LAnd: |
| 5977 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 5978 | // '*' and '&&' reduction ops - initializer is '1'. |
| 5979 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 5980 | } |
| 5981 | break; |
| 5982 | case BO_And: { |
| 5983 | // '&' reduction op - initializer is '~0'. |
| 5984 | QualType OrigType = Type; |
| 5985 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 5986 | Type = ComplexTy->getElementType(); |
| 5987 | } |
| 5988 | if (Type->isRealFloatingType()) { |
| 5989 | llvm::APFloat InitValue = |
| 5990 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 5991 | /*isIEEE=*/true); |
| 5992 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 5993 | Type, ELoc); |
| 5994 | } else if (Type->isScalarType()) { |
| 5995 | auto Size = Context.getTypeSize(Type); |
| 5996 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 5997 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 5998 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 5999 | } |
| 6000 | if (Init && OrigType->isAnyComplexType()) { |
| 6001 | // Init = 0xFFFF + 0xFFFFi; |
| 6002 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 6003 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 6004 | } |
| 6005 | Type = OrigType; |
| 6006 | break; |
| 6007 | } |
| 6008 | case BO_LT: |
| 6009 | case BO_GT: { |
| 6010 | // 'min' reduction op - initializer is 'Largest representable number in |
| 6011 | // the reduction list item type'. |
| 6012 | // 'max' reduction op - initializer is 'Least representable number in |
| 6013 | // the reduction list item type'. |
| 6014 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 6015 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 6016 | auto Size = Context.getTypeSize(Type); |
| 6017 | QualType IntTy = |
| 6018 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 6019 | llvm::APInt InitValue = |
| 6020 | (BOK != BO_LT) |
| 6021 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 6022 | : llvm::APInt::getMinValue(Size) |
| 6023 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 6024 | : llvm::APInt::getMaxValue(Size); |
| 6025 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6026 | if (Type->isPointerType()) { |
| 6027 | // Cast to pointer type. |
| 6028 | auto CastExpr = BuildCStyleCastExpr( |
| 6029 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 6030 | SourceLocation(), Init); |
| 6031 | if (CastExpr.isInvalid()) |
| 6032 | continue; |
| 6033 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6034 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6035 | } else if (Type->isRealFloatingType()) { |
| 6036 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 6037 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 6038 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6039 | Type, ELoc); |
| 6040 | } |
| 6041 | break; |
| 6042 | } |
| 6043 | case BO_PtrMemD: |
| 6044 | case BO_PtrMemI: |
| 6045 | case BO_MulAssign: |
| 6046 | case BO_Div: |
| 6047 | case BO_Rem: |
| 6048 | case BO_Sub: |
| 6049 | case BO_Shl: |
| 6050 | case BO_Shr: |
| 6051 | case BO_LE: |
| 6052 | case BO_GE: |
| 6053 | case BO_EQ: |
| 6054 | case BO_NE: |
| 6055 | case BO_AndAssign: |
| 6056 | case BO_XorAssign: |
| 6057 | case BO_OrAssign: |
| 6058 | case BO_Assign: |
| 6059 | case BO_AddAssign: |
| 6060 | case BO_SubAssign: |
| 6061 | case BO_DivAssign: |
| 6062 | case BO_RemAssign: |
| 6063 | case BO_ShlAssign: |
| 6064 | case BO_ShrAssign: |
| 6065 | case BO_Comma: |
| 6066 | llvm_unreachable("Unexpected reduction operation"); |
| 6067 | } |
| 6068 | if (Init) { |
| 6069 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 6070 | /*TypeMayContainAuto=*/false); |
| 6071 | } else { |
| 6072 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
| 6073 | } |
| 6074 | if (!RHSVD->hasInit()) { |
| 6075 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 6076 | << ReductionIdRange; |
| 6077 | bool IsDecl = |
| 6078 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6079 | Diag(VD->getLocation(), |
| 6080 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6081 | << VD; |
| 6082 | continue; |
| 6083 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6084 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 6085 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6086 | ExprResult ReductionOp = |
| 6087 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 6088 | LHSDRE, RHSDRE); |
| 6089 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 6090 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6091 | ReductionOp = |
| 6092 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6093 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 6094 | } else { |
| 6095 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 6096 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 6097 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 6098 | ReductionOp = |
| 6099 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6100 | BO_Assign, LHSDRE, ConditionalOp); |
| 6101 | } |
| 6102 | if (ReductionOp.isUsable()) { |
| 6103 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6104 | } |
| 6105 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6106 | if (ReductionOp.isInvalid()) |
| 6107 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6108 | |
| 6109 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 6110 | Vars.push_back(DE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6111 | LHSs.push_back(LHSDRE); |
| 6112 | RHSs.push_back(RHSDRE); |
| 6113 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6114 | } |
| 6115 | |
| 6116 | if (Vars.empty()) |
| 6117 | return nullptr; |
| 6118 | |
| 6119 | return OMPReductionClause::Create( |
| 6120 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6121 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, LHSs, |
| 6122 | RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6123 | } |
| 6124 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6125 | OMPClause *Sema::ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 6126 | SourceLocation StartLoc, |
| 6127 | SourceLocation LParenLoc, |
| 6128 | SourceLocation ColonLoc, |
| 6129 | SourceLocation EndLoc) { |
| 6130 | SmallVector<Expr *, 8> Vars; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6131 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6132 | for (auto &RefExpr : VarList) { |
| 6133 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 6134 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6135 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6136 | Vars.push_back(RefExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6137 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6138 | continue; |
| 6139 | } |
| 6140 | |
| 6141 | // OpenMP [2.14.3.7, linear clause] |
| 6142 | // A list item that appears in a linear clause is subject to the private |
| 6143 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 6144 | // noted. In addition, the value of the new list item on each iteration |
| 6145 | // of the associated loop(s) corresponds to the value of the original |
| 6146 | // list item before entering the construct plus the logical number of |
| 6147 | // the iteration times linear-step. |
| 6148 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6149 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6150 | // OpenMP [2.1, C/C++] |
| 6151 | // A list item is a variable name. |
| 6152 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6153 | // A variable that is part of another variable (as an array or |
| 6154 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6155 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6156 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6157 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6158 | continue; |
| 6159 | } |
| 6160 | |
| 6161 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6162 | |
| 6163 | // OpenMP [2.14.3.7, linear clause] |
| 6164 | // A list-item cannot appear in more than one linear clause. |
| 6165 | // A list-item that appears in a linear clause cannot appear in any |
| 6166 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6167 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6168 | if (DVar.RefExpr) { |
| 6169 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6170 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6171 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6172 | continue; |
| 6173 | } |
| 6174 | |
| 6175 | QualType QType = VD->getType(); |
| 6176 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 6177 | // It will be analyzed later. |
| 6178 | Vars.push_back(DE); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6179 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6180 | continue; |
| 6181 | } |
| 6182 | |
| 6183 | // A variable must not have an incomplete type or a reference type. |
| 6184 | if (RequireCompleteType(ELoc, QType, |
| 6185 | diag::err_omp_linear_incomplete_type)) { |
| 6186 | continue; |
| 6187 | } |
| 6188 | if (QType->isReferenceType()) { |
| 6189 | Diag(ELoc, diag::err_omp_clause_ref_type_arg) |
| 6190 | << getOpenMPClauseName(OMPC_linear) << QType; |
| 6191 | bool IsDecl = |
| 6192 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6193 | Diag(VD->getLocation(), |
| 6194 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6195 | << VD; |
| 6196 | continue; |
| 6197 | } |
| 6198 | |
| 6199 | // A list item must not be const-qualified. |
| 6200 | if (QType.isConstant(Context)) { |
| 6201 | Diag(ELoc, diag::err_omp_const_variable) |
| 6202 | << getOpenMPClauseName(OMPC_linear); |
| 6203 | bool IsDecl = |
| 6204 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6205 | Diag(VD->getLocation(), |
| 6206 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6207 | << VD; |
| 6208 | continue; |
| 6209 | } |
| 6210 | |
| 6211 | // A list item must be of integral or pointer type. |
| 6212 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 6213 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6214 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 6215 | !Ty->isPointerType())) { |
| 6216 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 6217 | bool IsDecl = |
| 6218 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6219 | Diag(VD->getLocation(), |
| 6220 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6221 | << VD; |
| 6222 | continue; |
| 6223 | } |
| 6224 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6225 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6226 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6227 | AddInitializerToDecl(Init, DefaultLvalueConversion(DE).get(), |
| 6228 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6229 | auto InitRef = buildDeclRefExpr( |
| 6230 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6231 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 6232 | Vars.push_back(DE); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6233 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6234 | } |
| 6235 | |
| 6236 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6237 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6238 | |
| 6239 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6240 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6241 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 6242 | !Step->isInstantiationDependent() && |
| 6243 | !Step->containsUnexpandedParameterPack()) { |
| 6244 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6245 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6246 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6247 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6248 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6249 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6250 | // Build var to save the step value. |
| 6251 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6252 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6253 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6254 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6255 | ExprResult CalcStep = |
| 6256 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
| 6257 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6258 | // Warn about zero linear step (it would be probably better specified as |
| 6259 | // making corresponding variables 'const'). |
| 6260 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6261 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 6262 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6263 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 6264 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6265 | if (!IsConstant && CalcStep.isUsable()) { |
| 6266 | // Calculate the step beforehand instead of doing this on each iteration. |
| 6267 | // (This is not used if the number of iterations may be kfold-ed). |
| 6268 | CalcStepExpr = CalcStep.get(); |
| 6269 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6270 | } |
| 6271 | |
| 6272 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, ColonLoc, EndLoc, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6273 | Vars, Inits, StepExpr, CalcStepExpr); |
| 6274 | } |
| 6275 | |
| 6276 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 6277 | Expr *NumIterations, Sema &SemaRef, |
| 6278 | Scope *S) { |
| 6279 | // Walk the vars and build update/final expressions for the CodeGen. |
| 6280 | SmallVector<Expr *, 8> Updates; |
| 6281 | SmallVector<Expr *, 8> Finals; |
| 6282 | Expr *Step = Clause.getStep(); |
| 6283 | Expr *CalcStep = Clause.getCalcStep(); |
| 6284 | // OpenMP [2.14.3.7, linear clause] |
| 6285 | // If linear-step is not specified it is assumed to be 1. |
| 6286 | if (Step == nullptr) |
| 6287 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 6288 | else if (CalcStep) |
| 6289 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 6290 | bool HasErrors = false; |
| 6291 | auto CurInit = Clause.inits().begin(); |
| 6292 | for (auto &RefExpr : Clause.varlists()) { |
| 6293 | Expr *InitExpr = *CurInit; |
| 6294 | |
| 6295 | // Build privatized reference to the current linear var. |
| 6296 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6297 | auto PrivateRef = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6298 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 6299 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 6300 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6301 | |
| 6302 | // Build update: Var = InitExpr + IV * Step |
| 6303 | ExprResult Update = |
| 6304 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), PrivateRef, |
| 6305 | InitExpr, IV, Step, /* Subtract */ false); |
| 6306 | Update = SemaRef.ActOnFinishFullExpr(Update.get()); |
| 6307 | |
| 6308 | // Build final: Var = InitExpr + NumIterations * Step |
| 6309 | ExprResult Final = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6310 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), PrivateRef, |
| 6311 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6312 | Final = SemaRef.ActOnFinishFullExpr(Final.get()); |
| 6313 | if (!Update.isUsable() || !Final.isUsable()) { |
| 6314 | Updates.push_back(nullptr); |
| 6315 | Finals.push_back(nullptr); |
| 6316 | HasErrors = true; |
| 6317 | } else { |
| 6318 | Updates.push_back(Update.get()); |
| 6319 | Finals.push_back(Final.get()); |
| 6320 | } |
| 6321 | ++CurInit; |
| 6322 | } |
| 6323 | Clause.setUpdates(Updates); |
| 6324 | Clause.setFinals(Finals); |
| 6325 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6326 | } |
| 6327 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6328 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 6329 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 6330 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 6331 | |
| 6332 | SmallVector<Expr *, 8> Vars; |
| 6333 | for (auto &RefExpr : VarList) { |
| 6334 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 6335 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6336 | // It will be analyzed later. |
| 6337 | Vars.push_back(RefExpr); |
| 6338 | continue; |
| 6339 | } |
| 6340 | |
| 6341 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6342 | // OpenMP [2.1, C/C++] |
| 6343 | // A list item is a variable name. |
| 6344 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6345 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6346 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6347 | continue; |
| 6348 | } |
| 6349 | |
| 6350 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6351 | |
| 6352 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6353 | // The type of list items appearing in the aligned clause must be |
| 6354 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6355 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6356 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6357 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6358 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 6359 | !Ty->isPointerType())) { |
| 6360 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 6361 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 6362 | bool IsDecl = |
| 6363 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6364 | Diag(VD->getLocation(), |
| 6365 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6366 | << VD; |
| 6367 | continue; |
| 6368 | } |
| 6369 | |
| 6370 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6371 | // A list-item cannot appear in more than one aligned clause. |
| 6372 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 6373 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 6374 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 6375 | << getOpenMPClauseName(OMPC_aligned); |
| 6376 | continue; |
| 6377 | } |
| 6378 | |
| 6379 | Vars.push_back(DE); |
| 6380 | } |
| 6381 | |
| 6382 | // OpenMP [2.8.1, simd construct, Description] |
| 6383 | // The parameter of the aligned clause, alignment, must be a constant |
| 6384 | // positive integer expression. |
| 6385 | // If no optional parameter is specified, implementation-defined default |
| 6386 | // alignments for SIMD instructions on the target platforms are assumed. |
| 6387 | if (Alignment != nullptr) { |
| 6388 | ExprResult AlignResult = |
| 6389 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 6390 | if (AlignResult.isInvalid()) |
| 6391 | return nullptr; |
| 6392 | Alignment = AlignResult.get(); |
| 6393 | } |
| 6394 | if (Vars.empty()) |
| 6395 | return nullptr; |
| 6396 | |
| 6397 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 6398 | EndLoc, Vars, Alignment); |
| 6399 | } |
| 6400 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6401 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 6402 | SourceLocation StartLoc, |
| 6403 | SourceLocation LParenLoc, |
| 6404 | SourceLocation EndLoc) { |
| 6405 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6406 | SmallVector<Expr *, 8> SrcExprs; |
| 6407 | SmallVector<Expr *, 8> DstExprs; |
| 6408 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6409 | for (auto &RefExpr : VarList) { |
| 6410 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 6411 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6412 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6413 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6414 | SrcExprs.push_back(nullptr); |
| 6415 | DstExprs.push_back(nullptr); |
| 6416 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6417 | continue; |
| 6418 | } |
| 6419 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6420 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6421 | // OpenMP [2.1, C/C++] |
| 6422 | // A list item is a variable name. |
| 6423 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6424 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6425 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6426 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6427 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6428 | continue; |
| 6429 | } |
| 6430 | |
| 6431 | Decl *D = DE->getDecl(); |
| 6432 | VarDecl *VD = cast<VarDecl>(D); |
| 6433 | |
| 6434 | QualType Type = VD->getType(); |
| 6435 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6436 | // It will be analyzed later. |
| 6437 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6438 | SrcExprs.push_back(nullptr); |
| 6439 | DstExprs.push_back(nullptr); |
| 6440 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6441 | continue; |
| 6442 | } |
| 6443 | |
| 6444 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 6445 | // A list item that appears in a copyin clause must be threadprivate. |
| 6446 | if (!DSAStack->isThreadPrivate(VD)) { |
| 6447 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6448 | << getOpenMPClauseName(OMPC_copyin) |
| 6449 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6450 | continue; |
| 6451 | } |
| 6452 | |
| 6453 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6454 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6455 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6456 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6457 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6458 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6459 | ElemType.getUnqualifiedType(), ".copyin.src"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6460 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6461 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 6462 | auto *DstVD = |
| 6463 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst"); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6464 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6465 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6466 | // For arrays generate assignment operation for single element and replace |
| 6467 | // it by the original array element in CodeGen. |
| 6468 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6469 | PseudoDstExpr, PseudoSrcExpr); |
| 6470 | if (AssignmentOp.isInvalid()) |
| 6471 | continue; |
| 6472 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6473 | /*DiscardedValue=*/true); |
| 6474 | if (AssignmentOp.isInvalid()) |
| 6475 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6476 | |
| 6477 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 6478 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6479 | SrcExprs.push_back(PseudoSrcExpr); |
| 6480 | DstExprs.push_back(PseudoDstExpr); |
| 6481 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6482 | } |
| 6483 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6484 | if (Vars.empty()) |
| 6485 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6486 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6487 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6488 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6489 | } |
| 6490 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6491 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 6492 | SourceLocation StartLoc, |
| 6493 | SourceLocation LParenLoc, |
| 6494 | SourceLocation EndLoc) { |
| 6495 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6496 | SmallVector<Expr *, 8> SrcExprs; |
| 6497 | SmallVector<Expr *, 8> DstExprs; |
| 6498 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6499 | for (auto &RefExpr : VarList) { |
| 6500 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 6501 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6502 | // It will be analyzed later. |
| 6503 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6504 | SrcExprs.push_back(nullptr); |
| 6505 | DstExprs.push_back(nullptr); |
| 6506 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6507 | continue; |
| 6508 | } |
| 6509 | |
| 6510 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6511 | // OpenMP [2.1, C/C++] |
| 6512 | // A list item is a variable name. |
| 6513 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6514 | // A list item that appears in a copyin clause must be threadprivate. |
| 6515 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6516 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6517 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6518 | continue; |
| 6519 | } |
| 6520 | |
| 6521 | Decl *D = DE->getDecl(); |
| 6522 | VarDecl *VD = cast<VarDecl>(D); |
| 6523 | |
| 6524 | QualType Type = VD->getType(); |
| 6525 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6526 | // It will be analyzed later. |
| 6527 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6528 | SrcExprs.push_back(nullptr); |
| 6529 | DstExprs.push_back(nullptr); |
| 6530 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6531 | continue; |
| 6532 | } |
| 6533 | |
| 6534 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 6535 | // A list item that appears in a copyprivate clause may not appear in a |
| 6536 | // private or firstprivate clause on the single construct. |
| 6537 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6538 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6539 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 6540 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6541 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6542 | << getOpenMPClauseName(DVar.CKind) |
| 6543 | << getOpenMPClauseName(OMPC_copyprivate); |
| 6544 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6545 | continue; |
| 6546 | } |
| 6547 | |
| 6548 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 6549 | // All list items that appear in a copyprivate clause must be either |
| 6550 | // threadprivate or private in the enclosing context. |
| 6551 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6552 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6553 | if (DVar.CKind == OMPC_shared) { |
| 6554 | Diag(ELoc, diag::err_omp_required_access) |
| 6555 | << getOpenMPClauseName(OMPC_copyprivate) |
| 6556 | << "threadprivate or private in the enclosing context"; |
| 6557 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6558 | continue; |
| 6559 | } |
| 6560 | } |
| 6561 | } |
| 6562 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6563 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6564 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6565 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6566 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 6567 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6568 | bool IsDecl = |
| 6569 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6570 | Diag(VD->getLocation(), |
| 6571 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6572 | << VD; |
| 6573 | continue; |
| 6574 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6575 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6576 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6577 | // A variable of class type (or array thereof) that appears in a |
| 6578 | // copyin clause requires an accessible, unambiguous copy assignment |
| 6579 | // operator for the class type. |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6580 | Type = Context.getBaseElementType(Type).getUnqualifiedType(); |
| 6581 | auto *SrcVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6582 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src"); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6583 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6584 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6585 | auto *DstVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6586 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst"); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6587 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6588 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6589 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6590 | PseudoDstExpr, PseudoSrcExpr); |
| 6591 | if (AssignmentOp.isInvalid()) |
| 6592 | continue; |
| 6593 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6594 | /*DiscardedValue=*/true); |
| 6595 | if (AssignmentOp.isInvalid()) |
| 6596 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6597 | |
| 6598 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 6599 | // implicitly private. |
| 6600 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6601 | SrcExprs.push_back(PseudoSrcExpr); |
| 6602 | DstExprs.push_back(PseudoDstExpr); |
| 6603 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6604 | } |
| 6605 | |
| 6606 | if (Vars.empty()) |
| 6607 | return nullptr; |
| 6608 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6609 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 6610 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6613 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 6614 | SourceLocation StartLoc, |
| 6615 | SourceLocation LParenLoc, |
| 6616 | SourceLocation EndLoc) { |
| 6617 | if (VarList.empty()) |
| 6618 | return nullptr; |
| 6619 | |
| 6620 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 6621 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6622 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6623 | OMPClause * |
| 6624 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 6625 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 6626 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 6627 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 6628 | if (DepKind == OMPC_DEPEND_unknown) { |
| 6629 | std::string Values; |
| 6630 | std::string Sep(", "); |
| 6631 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 6632 | Values += "'"; |
| 6633 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 6634 | Values += "'"; |
| 6635 | switch (i) { |
| 6636 | case OMPC_DEPEND_unknown - 2: |
| 6637 | Values += " or "; |
| 6638 | break; |
| 6639 | case OMPC_DEPEND_unknown - 1: |
| 6640 | break; |
| 6641 | default: |
| 6642 | Values += Sep; |
| 6643 | break; |
| 6644 | } |
| 6645 | } |
| 6646 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 6647 | << Values << getOpenMPClauseName(OMPC_depend); |
| 6648 | return nullptr; |
| 6649 | } |
| 6650 | SmallVector<Expr *, 8> Vars; |
| 6651 | for (auto &RefExpr : VarList) { |
| 6652 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6653 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6654 | // It will be analyzed later. |
| 6655 | Vars.push_back(RefExpr); |
| 6656 | continue; |
| 6657 | } |
| 6658 | |
| 6659 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6660 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 6661 | // A variable that is part of another variable (such as a field of a |
| 6662 | // structure) but is not an array element or an array section cannot appear |
| 6663 | // in a depend clause. |
| 6664 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 6665 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 6666 | ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 6667 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || (!ASE && !DE) || |
| 6668 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 6669 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 6670 | !ASE->getBase()->getType()->isArrayType())) { |
| 6671 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 6672 | << RefExpr->getSourceRange(); |
| 6673 | continue; |
| 6674 | } |
| 6675 | |
| 6676 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 6677 | } |
| 6678 | |
| 6679 | if (Vars.empty()) |
| 6680 | return nullptr; |
| 6681 | |
| 6682 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 6683 | DepLoc, ColonLoc, Vars); |
| 6684 | } |