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 | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 15 | #include "TreeTransform.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtCXX.h" |
| 22 | #include "clang/AST/StmtOpenMP.h" |
| 23 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 24 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Scope.h" |
| 30 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 31 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Stack of data-sharing attributes for variables |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| 38 | namespace { |
| 39 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 40 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 41 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 42 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 43 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 44 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 45 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 46 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 47 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 48 | bool operator()(T Kind) { |
| 49 | for (auto KindEl : Arr) |
| 50 | if (KindEl == Kind) |
| 51 | return true; |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | ArrayRef<T> Arr; |
| 57 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 58 | struct MatchesAlways { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 59 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 60 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 64 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 65 | |
| 66 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 67 | /// clauses and their data-sharing attributes. |
| 68 | class DSAStackTy { |
| 69 | public: |
| 70 | struct DSAVarData { |
| 71 | OpenMPDirectiveKind DKind; |
| 72 | OpenMPClauseKind CKind; |
| 73 | DeclRefExpr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 74 | SourceLocation ImplicitDSALoc; |
| 75 | DSAVarData() |
| 76 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 77 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 78 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 79 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 80 | private: |
| 81 | struct DSAInfo { |
| 82 | OpenMPClauseKind Attributes; |
| 83 | DeclRefExpr *RefExpr; |
| 84 | }; |
| 85 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 86 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 87 | typedef llvm::DenseSet<VarDecl *> LoopControlVariablesSetTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 88 | |
| 89 | struct SharingMapTy { |
| 90 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 91 | AlignedMapTy AlignedMap; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 92 | LoopControlVariablesSetTy LCVSet; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 93 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 94 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 95 | OpenMPDirectiveKind Directive; |
| 96 | DeclarationNameInfo DirectiveName; |
| 97 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 98 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 99 | /// \brief first argument (Expr *) contains optional argument of the |
| 100 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 101 | /// clause, false otherwise. |
| 102 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 103 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 104 | bool CancelRegion; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 105 | unsigned CollapseNumber; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 106 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 107 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 108 | Scope *CurScope, SourceLocation Loc) |
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(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 111 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 112 | CancelRegion(false), CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 113 | SharingMapTy() |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 114 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 115 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 116 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 117 | CancelRegion(false), CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 121 | |
| 122 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 123 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 124 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 125 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 126 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 127 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 128 | bool ForceCapturing; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 129 | |
| 130 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 131 | |
| 132 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 133 | |
| 134 | /// \brief Checks if the variable is a local for OpenMP region. |
| 135 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 136 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 137 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 138 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 139 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 140 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 141 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 142 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 143 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 144 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 145 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 146 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 147 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 148 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 149 | Scope *CurScope, SourceLocation Loc) { |
| 150 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 151 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void pop() { |
| 155 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 156 | Stack.pop_back(); |
| 157 | } |
| 158 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 159 | /// \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] | 160 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 161 | /// for diagnostics. |
| 162 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 163 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 164 | /// \brief Register specified variable as loop control variable. |
| 165 | void addLoopControlVariable(VarDecl *D); |
| 166 | /// \brief Check if the specified variable is a loop control variable for |
| 167 | /// current region. |
| 168 | bool isLoopControlVariable(VarDecl *D); |
| 169 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 170 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 171 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 172 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 173 | /// \brief Returns data sharing attributes from top of the stack for the |
| 174 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 175 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 176 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 177 | DSAVarData getImplicitDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 178 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 179 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 180 | /// predicate. |
| 181 | template <class ClausesPredicate, class DirectivesPredicate> |
| 182 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 183 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 184 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 185 | /// match specified \a CPred predicate in any innermost directive which |
| 186 | /// matches \a DPred predicate. |
| 187 | template <class ClausesPredicate, class DirectivesPredicate> |
| 188 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 189 | DirectivesPredicate DPred, |
| 190 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 191 | /// \brief Checks if the specified variables has explicit data-sharing |
| 192 | /// attributes which match specified \a CPred predicate at the specified |
| 193 | /// OpenMP region. |
| 194 | bool hasExplicitDSA(VarDecl *D, |
| 195 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 196 | unsigned Level); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 197 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 198 | template <class NamedDirectivesPredicate> |
| 199 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 200 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 201 | /// \brief Returns currently analyzed directive. |
| 202 | OpenMPDirectiveKind getCurrentDirective() const { |
| 203 | return Stack.back().Directive; |
| 204 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 205 | /// \brief Returns parent directive. |
| 206 | OpenMPDirectiveKind getParentDirective() const { |
| 207 | if (Stack.size() > 2) |
| 208 | return Stack[Stack.size() - 2].Directive; |
| 209 | return OMPD_unknown; |
| 210 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 211 | |
| 212 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 213 | void setDefaultDSANone(SourceLocation Loc) { |
| 214 | Stack.back().DefaultAttr = DSA_none; |
| 215 | Stack.back().DefaultAttrLoc = Loc; |
| 216 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 217 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 218 | void setDefaultDSAShared(SourceLocation Loc) { |
| 219 | Stack.back().DefaultAttr = DSA_shared; |
| 220 | Stack.back().DefaultAttrLoc = Loc; |
| 221 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 222 | |
| 223 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 224 | return Stack.back().DefaultAttr; |
| 225 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 226 | SourceLocation getDefaultDSALocation() const { |
| 227 | return Stack.back().DefaultAttrLoc; |
| 228 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 229 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 230 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 231 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 232 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 233 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 236 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 237 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 238 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 239 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 240 | } |
| 241 | /// \brief Returns true, if parent region is ordered (has associated |
| 242 | /// 'ordered' clause), false - otherwise. |
| 243 | bool isParentOrderedRegion() const { |
| 244 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 245 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 246 | return false; |
| 247 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 248 | /// \brief Returns optional parameter for the ordered region. |
| 249 | Expr *getParentOrderedRegionParam() const { |
| 250 | if (Stack.size() > 2) |
| 251 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 252 | return nullptr; |
| 253 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 254 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 255 | void setNowaitRegion(bool IsNowait = true) { |
| 256 | Stack.back().NowaitRegion = IsNowait; |
| 257 | } |
| 258 | /// \brief Returns true, if parent region is nowait (has associated |
| 259 | /// 'nowait' clause), false - otherwise. |
| 260 | bool isParentNowaitRegion() const { |
| 261 | if (Stack.size() > 2) |
| 262 | return Stack[Stack.size() - 2].NowaitRegion; |
| 263 | return false; |
| 264 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 265 | /// \brief Marks parent region as cancel region. |
| 266 | void setParentCancelRegion(bool Cancel = true) { |
| 267 | if (Stack.size() > 2) |
| 268 | Stack[Stack.size() - 2].CancelRegion = |
| 269 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 270 | } |
| 271 | /// \brief Return true if current region has inner cancel construct. |
| 272 | bool isCancelRegion() const { |
| 273 | return Stack.back().CancelRegion; |
| 274 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 275 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 276 | /// \brief Set collapse value for the region. |
| 277 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 278 | /// \brief Return collapse value for region. |
| 279 | unsigned getCollapseNumber() const { |
| 280 | return Stack.back().CollapseNumber; |
| 281 | } |
| 282 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 283 | /// \brief Marks current target region as one with closely nested teams |
| 284 | /// region. |
| 285 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 286 | if (Stack.size() > 2) |
| 287 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 288 | } |
| 289 | /// \brief Returns true, if current region has closely nested teams region. |
| 290 | bool hasInnerTeamsRegion() const { |
| 291 | return getInnerTeamsRegionLoc().isValid(); |
| 292 | } |
| 293 | /// \brief Returns location of the nested teams region (if any). |
| 294 | SourceLocation getInnerTeamsRegionLoc() const { |
| 295 | if (Stack.size() > 1) |
| 296 | return Stack.back().InnerTeamsRegionLoc; |
| 297 | return SourceLocation(); |
| 298 | } |
| 299 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 300 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 301 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 302 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 303 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 304 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 305 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 306 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 307 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 308 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 309 | |
| 310 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 311 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 312 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 313 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 314 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 315 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 316 | // in a region but not in construct] |
| 317 | // File-scope or namespace-scope variables referenced in called routines |
| 318 | // in the region are shared unless they appear in a threadprivate |
| 319 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 320 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 321 | DVar.CKind = OMPC_shared; |
| 322 | |
| 323 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 324 | // in a region but not in construct] |
| 325 | // Variables with static storage duration that are declared in called |
| 326 | // routines in the region are shared. |
| 327 | if (D->hasGlobalStorage()) |
| 328 | DVar.CKind = OMPC_shared; |
| 329 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 330 | return DVar; |
| 331 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 332 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 333 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 334 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 335 | // in a Construct, C/C++, predetermined, p.1] |
| 336 | // Variables with automatic storage duration that are declared in a scope |
| 337 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 338 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 339 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 340 | DVar.CKind = OMPC_private; |
| 341 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 344 | // Explicitly specified attributes and local variables with predetermined |
| 345 | // attributes. |
| 346 | if (Iter->SharingMap.count(D)) { |
| 347 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 348 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 349 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 350 | return DVar; |
| 351 | } |
| 352 | |
| 353 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 354 | // in a Construct, C/C++, implicitly determined, p.1] |
| 355 | // In a parallel or task construct, the data-sharing attributes of these |
| 356 | // variables are determined by the default clause, if present. |
| 357 | switch (Iter->DefaultAttr) { |
| 358 | case DSA_shared: |
| 359 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 360 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 361 | return DVar; |
| 362 | case DSA_none: |
| 363 | return DVar; |
| 364 | case DSA_unspecified: |
| 365 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 366 | // in a Construct, implicitly determined, p.2] |
| 367 | // In a parallel construct, if no default clause is present, these |
| 368 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 369 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 370 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 371 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 372 | DVar.CKind = OMPC_shared; |
| 373 | return DVar; |
| 374 | } |
| 375 | |
| 376 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 377 | // in a Construct, implicitly determined, p.4] |
| 378 | // In a task construct, if no default clause is present, a variable that in |
| 379 | // the enclosing context is determined to be shared by all implicit tasks |
| 380 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 381 | if (DVar.DKind == OMPD_task) { |
| 382 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 383 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 384 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 385 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 386 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 387 | // in a Construct, implicitly determined, p.6] |
| 388 | // In a task construct, if no default clause is present, a variable |
| 389 | // whose data-sharing attribute is not determined by the rules above is |
| 390 | // firstprivate. |
| 391 | DVarTemp = getDSA(I, D); |
| 392 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 393 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 394 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 395 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 396 | return DVar; |
| 397 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 398 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 399 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 400 | } |
| 401 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 402 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 403 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 404 | return DVar; |
| 405 | } |
| 406 | } |
| 407 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 408 | // in a Construct, implicitly determined, p.3] |
| 409 | // For constructs other than task, if no default clause is present, these |
| 410 | // variables inherit their data-sharing attributes from the enclosing |
| 411 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 412 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 415 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 416 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 417 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 418 | auto It = Stack.back().AlignedMap.find(D); |
| 419 | if (It == Stack.back().AlignedMap.end()) { |
| 420 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 421 | Stack.back().AlignedMap[D] = NewDE; |
| 422 | return nullptr; |
| 423 | } else { |
| 424 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 425 | return It->second; |
| 426 | } |
| 427 | return nullptr; |
| 428 | } |
| 429 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 430 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 431 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 432 | D = D->getCanonicalDecl(); |
| 433 | Stack.back().LCVSet.insert(D); |
| 434 | } |
| 435 | |
| 436 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 437 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 438 | D = D->getCanonicalDecl(); |
| 439 | return Stack.back().LCVSet.count(D) > 0; |
| 440 | } |
| 441 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 442 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 443 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 444 | if (A == OMPC_threadprivate) { |
| 445 | Stack[0].SharingMap[D].Attributes = A; |
| 446 | Stack[0].SharingMap[D].RefExpr = E; |
| 447 | } else { |
| 448 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 449 | Stack.back().SharingMap[D].Attributes = A; |
| 450 | Stack.back().SharingMap[D].RefExpr = E; |
| 451 | } |
| 452 | } |
| 453 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 454 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 455 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 456 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 457 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 458 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 459 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 460 | ++I; |
| 461 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 462 | if (I == E) |
| 463 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 464 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 465 | Scope *CurScope = getCurScope(); |
| 466 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 467 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 468 | } |
| 469 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 470 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 471 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 474 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 475 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 476 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 477 | DeclContext *DC = SemaRef.CurContext; |
| 478 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 479 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 480 | VarDecl *Decl = |
| 481 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 482 | if (Attrs) { |
| 483 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 484 | I != E; ++I) |
| 485 | Decl->addAttr(*I); |
| 486 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 487 | Decl->setImplicit(); |
| 488 | return Decl; |
| 489 | } |
| 490 | |
| 491 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 492 | SourceLocation Loc, |
| 493 | bool RefersToCapture = false) { |
| 494 | D->setReferenced(); |
| 495 | D->markUsed(S.Context); |
| 496 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 497 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 498 | VK_LValue); |
| 499 | } |
| 500 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 501 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 502 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 503 | DSAVarData DVar; |
| 504 | |
| 505 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 506 | // in a Construct, C/C++, predetermined, p.1] |
| 507 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 508 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 509 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 510 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 511 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 512 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 513 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 514 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 515 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 516 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 517 | } |
| 518 | if (Stack[0].SharingMap.count(D)) { |
| 519 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 520 | DVar.CKind = OMPC_threadprivate; |
| 521 | return DVar; |
| 522 | } |
| 523 | |
| 524 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 525 | // in a Construct, C/C++, predetermined, p.1] |
| 526 | // Variables with automatic storage duration that are declared in a scope |
| 527 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 528 | OpenMPDirectiveKind Kind = |
| 529 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 530 | auto StartI = std::next(Stack.rbegin()); |
| 531 | auto EndI = std::prev(Stack.rend()); |
| 532 | if (FromParent && StartI != EndI) { |
| 533 | StartI = std::next(StartI); |
| 534 | } |
| 535 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 536 | if (isOpenMPLocal(D, StartI) && |
| 537 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 538 | D->getStorageClass() == SC_None)) || |
| 539 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 540 | DVar.CKind = OMPC_private; |
| 541 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 542 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 543 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 544 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 545 | // in a Construct, C/C++, predetermined, p.4] |
| 546 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 547 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 548 | // in a Construct, C/C++, predetermined, p.7] |
| 549 | // Variables with static storage duration that are declared in a scope |
| 550 | // inside the construct are shared. |
Kelvin Li | 4eea8c6 | 2015-09-15 18:56:58 +0000 | [diff] [blame] | 551 | if (D->isStaticDataMember()) { |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 552 | DSAVarData DVarTemp = |
| 553 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 554 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 555 | return DVar; |
| 556 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 557 | DVar.CKind = OMPC_shared; |
| 558 | return DVar; |
| 559 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 563 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 564 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 565 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 566 | // in a Construct, C/C++, predetermined, p.6] |
| 567 | // Variables with const qualified type having no mutable member are |
| 568 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 569 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 570 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 571 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 572 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 573 | // Variables with const-qualified type having no mutable member may be |
| 574 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 575 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 576 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 577 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 578 | return DVar; |
| 579 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 580 | DVar.CKind = OMPC_shared; |
| 581 | return DVar; |
| 582 | } |
| 583 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 584 | // Explicitly specified attributes and local variables with predetermined |
| 585 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 586 | auto I = std::prev(StartI); |
| 587 | if (I->SharingMap.count(D)) { |
| 588 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 589 | DVar.CKind = I->SharingMap[D].Attributes; |
| 590 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | return DVar; |
| 594 | } |
| 595 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 596 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 597 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 598 | auto StartI = Stack.rbegin(); |
| 599 | auto EndI = std::prev(Stack.rend()); |
| 600 | if (FromParent && StartI != EndI) { |
| 601 | StartI = std::next(StartI); |
| 602 | } |
| 603 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 606 | template <class ClausesPredicate, class DirectivesPredicate> |
| 607 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 608 | DirectivesPredicate DPred, |
| 609 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 610 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 611 | auto StartI = std::next(Stack.rbegin()); |
| 612 | auto EndI = std::prev(Stack.rend()); |
| 613 | if (FromParent && StartI != EndI) { |
| 614 | StartI = std::next(StartI); |
| 615 | } |
| 616 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 617 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 618 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 619 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 620 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 621 | return DVar; |
| 622 | } |
| 623 | return DSAVarData(); |
| 624 | } |
| 625 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 626 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 627 | DSAStackTy::DSAVarData |
| 628 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 629 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 630 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 631 | auto StartI = std::next(Stack.rbegin()); |
| 632 | auto EndI = std::prev(Stack.rend()); |
| 633 | if (FromParent && StartI != EndI) { |
| 634 | StartI = std::next(StartI); |
| 635 | } |
| 636 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 637 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 638 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 639 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 640 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 641 | return DVar; |
| 642 | return DSAVarData(); |
| 643 | } |
| 644 | return DSAVarData(); |
| 645 | } |
| 646 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 647 | bool DSAStackTy::hasExplicitDSA( |
| 648 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 649 | unsigned Level) { |
| 650 | if (CPred(ClauseKindMode)) |
| 651 | return true; |
| 652 | if (isClauseParsingMode()) |
| 653 | ++Level; |
| 654 | D = D->getCanonicalDecl(); |
| 655 | auto StartI = Stack.rbegin(); |
| 656 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 657 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 658 | return false; |
| 659 | std::advance(StartI, Level); |
| 660 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 661 | CPred(StartI->SharingMap[D].Attributes); |
| 662 | } |
| 663 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 664 | template <class NamedDirectivesPredicate> |
| 665 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 666 | auto StartI = std::next(Stack.rbegin()); |
| 667 | auto EndI = std::prev(Stack.rend()); |
| 668 | if (FromParent && StartI != EndI) { |
| 669 | StartI = std::next(StartI); |
| 670 | } |
| 671 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 672 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 673 | return true; |
| 674 | } |
| 675 | return false; |
| 676 | } |
| 677 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 678 | void Sema::InitDataSharingAttributesStack() { |
| 679 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 680 | } |
| 681 | |
| 682 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 683 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 684 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 685 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 686 | VD = VD->getCanonicalDecl(); |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 687 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 688 | (!DSAStack->isClauseParsingMode() || |
| 689 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 690 | if (DSAStack->isLoopControlVariable(VD) || |
| 691 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 692 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 693 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 694 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 695 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 696 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 697 | return true; |
| 698 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 699 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 700 | return DVarPrivate.CKind != OMPC_unknown; |
| 701 | } |
| 702 | return false; |
| 703 | } |
| 704 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 705 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 706 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 707 | return DSAStack->hasExplicitDSA( |
| 708 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 709 | } |
| 710 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 711 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 712 | |
| 713 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 714 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 715 | Scope *CurScope, SourceLocation Loc) { |
| 716 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 717 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 718 | } |
| 719 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 720 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 721 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 724 | void Sema::EndOpenMPClause() { |
| 725 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 728 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 729 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 730 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 731 | // clause requires an accessible, unambiguous default constructor for the |
| 732 | // class type, unless the list item is also specified in a firstprivate |
| 733 | // clause. |
| 734 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 735 | for (auto *C : D->clauses()) { |
| 736 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 737 | SmallVector<Expr *, 8> PrivateCopies; |
| 738 | for (auto *DE : Clause->varlists()) { |
| 739 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 740 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 741 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 742 | } |
| 743 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 744 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 745 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 746 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 747 | // Generate helper private variable and initialize it with the |
| 748 | // default value. The address of the original variable is replaced |
| 749 | // by the address of the new private variable in CodeGen. This new |
| 750 | // variable is not added to IdResolver, so the code in the OpenMP |
| 751 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 752 | auto *VDPrivate = buildVarDecl( |
| 753 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 754 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 755 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 756 | if (VDPrivate->isInvalidDecl()) |
| 757 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 758 | PrivateCopies.push_back(buildDeclRefExpr( |
| 759 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 760 | } else { |
| 761 | // The variable is also a firstprivate, so initialization sequence |
| 762 | // for private copy is generated already. |
| 763 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 764 | } |
| 765 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 766 | // Set initializers to private copies if no errors were found. |
| 767 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 768 | Clause->setPrivateCopies(PrivateCopies); |
| 769 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 774 | DSAStack->pop(); |
| 775 | DiscardCleanupsInEvaluationContext(); |
| 776 | PopExpressionEvaluationContext(); |
| 777 | } |
| 778 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 779 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 780 | Expr *NumIterations, Sema &SemaRef, |
| 781 | Scope *S); |
| 782 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 783 | namespace { |
| 784 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 785 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 786 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 787 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 788 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 789 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 790 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 791 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 792 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 793 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 794 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 795 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 796 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 797 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 798 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 799 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 800 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 801 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 802 | |
| 803 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 804 | CXXScopeSpec &ScopeSpec, |
| 805 | const DeclarationNameInfo &Id) { |
| 806 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 807 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 808 | |
| 809 | if (Lookup.isAmbiguous()) |
| 810 | return ExprError(); |
| 811 | |
| 812 | VarDecl *VD; |
| 813 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 814 | if (TypoCorrection Corrected = CorrectTypo( |
| 815 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 816 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 817 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 818 | PDiag(Lookup.empty() |
| 819 | ? diag::err_undeclared_var_use_suggest |
| 820 | : diag::err_omp_expected_var_arg_suggest) |
| 821 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 822 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 823 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 824 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 825 | : diag::err_omp_expected_var_arg) |
| 826 | << Id.getName(); |
| 827 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 828 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 829 | } else { |
| 830 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 831 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 832 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 833 | return ExprError(); |
| 834 | } |
| 835 | } |
| 836 | Lookup.suppressDiagnostics(); |
| 837 | |
| 838 | // OpenMP [2.9.2, Syntax, C/C++] |
| 839 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 840 | if (!VD->hasGlobalStorage()) { |
| 841 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 842 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 843 | bool IsDecl = |
| 844 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 845 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 846 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 847 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 848 | return ExprError(); |
| 849 | } |
| 850 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 851 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 852 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 853 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 854 | // A threadprivate directive for file-scope variables must appear outside |
| 855 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 856 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 857 | !getCurLexicalContext()->isTranslationUnit()) { |
| 858 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 859 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 860 | bool IsDecl = |
| 861 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 862 | Diag(VD->getLocation(), |
| 863 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 864 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 865 | return ExprError(); |
| 866 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 867 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 868 | // A threadprivate directive for static class member variables must appear |
| 869 | // in the class definition, in the same scope in which the member |
| 870 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 871 | if (CanonicalVD->isStaticDataMember() && |
| 872 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 873 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 874 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 875 | bool IsDecl = |
| 876 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 877 | Diag(VD->getLocation(), |
| 878 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 879 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 880 | return ExprError(); |
| 881 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 882 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 883 | // A threadprivate directive for namespace-scope variables must appear |
| 884 | // outside any definition or declaration other than the namespace |
| 885 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 886 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 887 | (!getCurLexicalContext()->isFileContext() || |
| 888 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 889 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 890 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 891 | bool IsDecl = |
| 892 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 893 | Diag(VD->getLocation(), |
| 894 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 895 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 896 | return ExprError(); |
| 897 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 898 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 899 | // A threadprivate directive for static block-scope variables must appear |
| 900 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 901 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 902 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 903 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 904 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 905 | bool IsDecl = |
| 906 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 907 | Diag(VD->getLocation(), |
| 908 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 909 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 910 | return ExprError(); |
| 911 | } |
| 912 | |
| 913 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 914 | // A threadprivate directive must lexically precede all references to any |
| 915 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 916 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 917 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 918 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 919 | return ExprError(); |
| 920 | } |
| 921 | |
| 922 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 923 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 924 | return DE; |
| 925 | } |
| 926 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 927 | Sema::DeclGroupPtrTy |
| 928 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 929 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 930 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 931 | CurContext->addDecl(D); |
| 932 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 933 | } |
| 934 | return DeclGroupPtrTy(); |
| 935 | } |
| 936 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 937 | namespace { |
| 938 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 939 | Sema &SemaRef; |
| 940 | |
| 941 | public: |
| 942 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 943 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 944 | if (VD->hasLocalStorage()) { |
| 945 | SemaRef.Diag(E->getLocStart(), |
| 946 | diag::err_omp_local_var_in_threadprivate_init) |
| 947 | << E->getSourceRange(); |
| 948 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 949 | << VD << VD->getSourceRange(); |
| 950 | return true; |
| 951 | } |
| 952 | } |
| 953 | return false; |
| 954 | } |
| 955 | bool VisitStmt(const Stmt *S) { |
| 956 | for (auto Child : S->children()) { |
| 957 | if (Child && Visit(Child)) |
| 958 | return true; |
| 959 | } |
| 960 | return false; |
| 961 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 962 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 963 | }; |
| 964 | } // namespace |
| 965 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 966 | OMPThreadPrivateDecl * |
| 967 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 968 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 969 | for (auto &RefExpr : VarList) { |
| 970 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 971 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 972 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 973 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 974 | QualType QType = VD->getType(); |
| 975 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 976 | // It will be analyzed later. |
| 977 | Vars.push_back(DE); |
| 978 | continue; |
| 979 | } |
| 980 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 981 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 982 | // A threadprivate variable must not have an incomplete type. |
| 983 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 984 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 985 | continue; |
| 986 | } |
| 987 | |
| 988 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 989 | // A threadprivate variable must not have a reference type. |
| 990 | if (VD->getType()->isReferenceType()) { |
| 991 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 992 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 993 | bool IsDecl = |
| 994 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 995 | Diag(VD->getLocation(), |
| 996 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 997 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 998 | continue; |
| 999 | } |
| 1000 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1001 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1002 | // the corresponding diagnostic. |
| 1003 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1004 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1005 | getLangOpts().OpenMPUseTLS && |
| 1006 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1007 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1008 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1009 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1010 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1011 | bool IsDecl = |
| 1012 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1013 | Diag(VD->getLocation(), |
| 1014 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1015 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1016 | continue; |
| 1017 | } |
| 1018 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1019 | // Check if initial value of threadprivate variable reference variable with |
| 1020 | // local storage (it is not supported by runtime). |
| 1021 | if (auto Init = VD->getAnyInitializer()) { |
| 1022 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1023 | if (Checker.Visit(Init)) |
| 1024 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1027 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1028 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1029 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1030 | Context, SourceRange(Loc, Loc))); |
| 1031 | if (auto *ML = Context.getASTMutationListener()) |
| 1032 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1033 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1034 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1035 | if (!Vars.empty()) { |
| 1036 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1037 | Vars); |
| 1038 | D->setAccess(AS_public); |
| 1039 | } |
| 1040 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1041 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1042 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1043 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1044 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1045 | bool IsLoopIterVar = false) { |
| 1046 | if (DVar.RefExpr) { |
| 1047 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1048 | << getOpenMPClauseName(DVar.CKind); |
| 1049 | return; |
| 1050 | } |
| 1051 | enum { |
| 1052 | PDSA_StaticMemberShared, |
| 1053 | PDSA_StaticLocalVarShared, |
| 1054 | PDSA_LoopIterVarPrivate, |
| 1055 | PDSA_LoopIterVarLinear, |
| 1056 | PDSA_LoopIterVarLastprivate, |
| 1057 | PDSA_ConstVarShared, |
| 1058 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1059 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1060 | PDSA_LocalVarPrivate, |
| 1061 | PDSA_Implicit |
| 1062 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1063 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1064 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1065 | if (IsLoopIterVar) { |
| 1066 | if (DVar.CKind == OMPC_private) |
| 1067 | Reason = PDSA_LoopIterVarPrivate; |
| 1068 | else if (DVar.CKind == OMPC_lastprivate) |
| 1069 | Reason = PDSA_LoopIterVarLastprivate; |
| 1070 | else |
| 1071 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1072 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1073 | Reason = PDSA_TaskVarFirstprivate; |
| 1074 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1075 | } else if (VD->isStaticLocal()) |
| 1076 | Reason = PDSA_StaticLocalVarShared; |
| 1077 | else if (VD->isStaticDataMember()) |
| 1078 | Reason = PDSA_StaticMemberShared; |
| 1079 | else if (VD->isFileVarDecl()) |
| 1080 | Reason = PDSA_GlobalVarShared; |
| 1081 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1082 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1083 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1084 | ReportHint = true; |
| 1085 | Reason = PDSA_LocalVarPrivate; |
| 1086 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1087 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1088 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1089 | << Reason << ReportHint |
| 1090 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1091 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1092 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1093 | << getOpenMPClauseName(DVar.CKind); |
| 1094 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1097 | namespace { |
| 1098 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1099 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1100 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1101 | bool ErrorFound; |
| 1102 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1103 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1104 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1105 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1106 | public: |
| 1107 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1108 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1109 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1110 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1111 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1112 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1113 | auto DVar = Stack->getTopDSA(VD, false); |
| 1114 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1115 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1116 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1117 | auto ELoc = E->getExprLoc(); |
| 1118 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1119 | // The default(none) clause requires that each variable that is referenced |
| 1120 | // in the construct, and does not have a predetermined data-sharing |
| 1121 | // attribute, must have its data-sharing attribute explicitly determined |
| 1122 | // by being listed in a data-sharing attribute clause. |
| 1123 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1124 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1125 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1126 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1127 | return; |
| 1128 | } |
| 1129 | |
| 1130 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1131 | // A list item that appears in a reduction clause of the innermost |
| 1132 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1133 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1134 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1135 | [](OpenMPDirectiveKind K) -> bool { |
| 1136 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1137 | isOpenMPWorksharingDirective(K) || |
| 1138 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1139 | }, |
| 1140 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1141 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1142 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1143 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1144 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1145 | return; |
| 1146 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1147 | |
| 1148 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1149 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1150 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1151 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1152 | } |
| 1153 | } |
| 1154 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1155 | for (auto *C : S->clauses()) { |
| 1156 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1157 | // for task directives. |
| 1158 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1159 | for (auto *CC : C->children()) { |
| 1160 | if (CC) |
| 1161 | Visit(CC); |
| 1162 | } |
| 1163 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1164 | } |
| 1165 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1166 | for (auto *C : S->children()) { |
| 1167 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1168 | Visit(C); |
| 1169 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1170 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1171 | |
| 1172 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1173 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1174 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1175 | return VarsWithInheritedDSA; |
| 1176 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1177 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1178 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1179 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1180 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1181 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1182 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1183 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1184 | switch (DKind) { |
| 1185 | case OMPD_parallel: { |
| 1186 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1187 | QualType KmpInt32PtrTy = |
| 1188 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1189 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1190 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1191 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1192 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1193 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1194 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1195 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1196 | break; |
| 1197 | } |
| 1198 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1199 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1200 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1201 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1202 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1203 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1204 | break; |
| 1205 | } |
| 1206 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1207 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1208 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1209 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1210 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1211 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1212 | break; |
| 1213 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1214 | case OMPD_for_simd: { |
| 1215 | Sema::CapturedParamNameType Params[] = { |
| 1216 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1217 | }; |
| 1218 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1219 | Params); |
| 1220 | break; |
| 1221 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1222 | case OMPD_sections: { |
| 1223 | Sema::CapturedParamNameType Params[] = { |
| 1224 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1225 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1226 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1227 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1228 | break; |
| 1229 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1230 | case OMPD_section: { |
| 1231 | Sema::CapturedParamNameType Params[] = { |
| 1232 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1233 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1234 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1235 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1236 | break; |
| 1237 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1238 | case OMPD_single: { |
| 1239 | Sema::CapturedParamNameType Params[] = { |
| 1240 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1241 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1242 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1243 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1244 | break; |
| 1245 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1246 | case OMPD_master: { |
| 1247 | Sema::CapturedParamNameType Params[] = { |
| 1248 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1249 | }; |
| 1250 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1251 | Params); |
| 1252 | break; |
| 1253 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1254 | case OMPD_critical: { |
| 1255 | Sema::CapturedParamNameType Params[] = { |
| 1256 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1257 | }; |
| 1258 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1259 | Params); |
| 1260 | break; |
| 1261 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1262 | case OMPD_parallel_for: { |
| 1263 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1264 | QualType KmpInt32PtrTy = |
| 1265 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1266 | Sema::CapturedParamNameType Params[] = { |
| 1267 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1268 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1269 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1270 | }; |
| 1271 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1272 | Params); |
| 1273 | break; |
| 1274 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1275 | case OMPD_parallel_for_simd: { |
| 1276 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1277 | QualType KmpInt32PtrTy = |
| 1278 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1279 | Sema::CapturedParamNameType Params[] = { |
| 1280 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1281 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1282 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1283 | }; |
| 1284 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1285 | Params); |
| 1286 | break; |
| 1287 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1288 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1289 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1290 | QualType KmpInt32PtrTy = |
| 1291 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1292 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1293 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1294 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1295 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1296 | }; |
| 1297 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1298 | Params); |
| 1299 | break; |
| 1300 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1301 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1302 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1303 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1304 | FunctionProtoType::ExtProtoInfo EPI; |
| 1305 | EPI.Variadic = true; |
| 1306 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1307 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1308 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1309 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1310 | std::make_pair(".privates.", |
| 1311 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1312 | std::make_pair( |
| 1313 | ".copy_fn.", |
| 1314 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1315 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1316 | }; |
| 1317 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1318 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1319 | // Mark this captured region as inlined, because we don't use outlined |
| 1320 | // function directly. |
| 1321 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1322 | AlwaysInlineAttr::CreateImplicit( |
| 1323 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1324 | break; |
| 1325 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1326 | case OMPD_ordered: { |
| 1327 | Sema::CapturedParamNameType Params[] = { |
| 1328 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1329 | }; |
| 1330 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1331 | Params); |
| 1332 | break; |
| 1333 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1334 | case OMPD_atomic: { |
| 1335 | Sema::CapturedParamNameType Params[] = { |
| 1336 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1337 | }; |
| 1338 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1339 | Params); |
| 1340 | break; |
| 1341 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1342 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1343 | case OMPD_target: { |
| 1344 | Sema::CapturedParamNameType Params[] = { |
| 1345 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1346 | }; |
| 1347 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1348 | Params); |
| 1349 | break; |
| 1350 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1351 | case OMPD_teams: { |
| 1352 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1353 | QualType KmpInt32PtrTy = |
| 1354 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1355 | Sema::CapturedParamNameType Params[] = { |
| 1356 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1357 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1358 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1359 | }; |
| 1360 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1361 | Params); |
| 1362 | break; |
| 1363 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1364 | case OMPD_taskgroup: { |
| 1365 | Sema::CapturedParamNameType Params[] = { |
| 1366 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1367 | }; |
| 1368 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1369 | Params); |
| 1370 | break; |
| 1371 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1372 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1373 | case OMPD_taskyield: |
| 1374 | case OMPD_barrier: |
| 1375 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1376 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1377 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1378 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1379 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1380 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1381 | llvm_unreachable("Unknown OpenMP directive"); |
| 1382 | } |
| 1383 | } |
| 1384 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1385 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1386 | ArrayRef<OMPClause *> Clauses) { |
| 1387 | if (!S.isUsable()) { |
| 1388 | ActOnCapturedRegionError(); |
| 1389 | return StmtError(); |
| 1390 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1391 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1392 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1393 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1394 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1395 | (getLangOpts().OpenMPUseTLS && |
| 1396 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1397 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1398 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1399 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1400 | for (auto *VarRef : Clause->children()) { |
| 1401 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1402 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1403 | } |
| 1404 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1405 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1406 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1407 | Clause->getClauseKind() == OMPC_schedule) { |
| 1408 | // Mark all variables in private list clauses as used in inner region. |
| 1409 | // Required for proper codegen of combined directives. |
| 1410 | // TODO: add processing for other clauses. |
| 1411 | if (auto *E = cast_or_null<Expr>( |
| 1412 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1413 | MarkDeclarationsReferencedInExpr(E); |
| 1414 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | return ActOnCapturedRegionEnd(S.get()); |
| 1418 | } |
| 1419 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1420 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1421 | OpenMPDirectiveKind CurrentRegion, |
| 1422 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1423 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1424 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1425 | // Allowed nesting of constructs |
| 1426 | // +------------------+-----------------+------------------------------------+ |
| 1427 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1428 | // +------------------+-----------------+------------------------------------+ |
| 1429 | // | parallel | parallel | * | |
| 1430 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1431 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1432 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1433 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1434 | // | parallel | simd | * | |
| 1435 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1436 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1437 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1438 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1439 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1440 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1441 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1442 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1443 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1444 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1445 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1446 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1447 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1448 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1449 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1450 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1451 | // | parallel | cancellation | | |
| 1452 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1453 | // | parallel | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1454 | // +------------------+-----------------+------------------------------------+ |
| 1455 | // | for | parallel | * | |
| 1456 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1457 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1458 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1459 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1460 | // | for | simd | * | |
| 1461 | // | for | sections | + | |
| 1462 | // | for | section | + | |
| 1463 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1464 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1465 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1466 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1467 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1468 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1469 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1470 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1471 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1472 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1473 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1474 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1475 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1476 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1477 | // | for | cancellation | | |
| 1478 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1479 | // | for | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1480 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1481 | // | master | parallel | * | |
| 1482 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1483 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1484 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1485 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1486 | // | master | simd | * | |
| 1487 | // | master | sections | + | |
| 1488 | // | master | section | + | |
| 1489 | // | master | single | + | |
| 1490 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1491 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1492 | // | master |parallel sections| * | |
| 1493 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1494 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1495 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1496 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1497 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1498 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1499 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1500 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1501 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1502 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1503 | // | master | cancellation | | |
| 1504 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1505 | // | master | cancel | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1506 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1507 | // | critical | parallel | * | |
| 1508 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1509 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1510 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1511 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1512 | // | critical | simd | * | |
| 1513 | // | critical | sections | + | |
| 1514 | // | critical | section | + | |
| 1515 | // | critical | single | + | |
| 1516 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1517 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1518 | // | critical |parallel sections| * | |
| 1519 | // | critical | task | * | |
| 1520 | // | critical | taskyield | * | |
| 1521 | // | critical | barrier | + | |
| 1522 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1523 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1524 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1525 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1526 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1527 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1528 | // | critical | cancellation | | |
| 1529 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1530 | // | critical | cancel | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1531 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1532 | // | simd | parallel | | |
| 1533 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1534 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1535 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1536 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1537 | // | simd | simd | | |
| 1538 | // | simd | sections | | |
| 1539 | // | simd | section | | |
| 1540 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1541 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1542 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1543 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1544 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1545 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1546 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1547 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1548 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1549 | // | simd | flush | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1550 | // | simd | ordered | | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1551 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1552 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1553 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1554 | // | simd | cancellation | | |
| 1555 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1556 | // | simd | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1557 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1558 | // | for simd | parallel | | |
| 1559 | // | for simd | for | | |
| 1560 | // | for simd | for simd | | |
| 1561 | // | for simd | master | | |
| 1562 | // | for simd | critical | | |
| 1563 | // | for simd | simd | | |
| 1564 | // | for simd | sections | | |
| 1565 | // | for simd | section | | |
| 1566 | // | for simd | single | | |
| 1567 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1568 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1569 | // | for simd |parallel sections| | |
| 1570 | // | for simd | task | | |
| 1571 | // | for simd | taskyield | | |
| 1572 | // | for simd | barrier | | |
| 1573 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1574 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1575 | // | for simd | flush | | |
| 1576 | // | for simd | ordered | | |
| 1577 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1578 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1579 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1580 | // | for simd | cancellation | | |
| 1581 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1582 | // | for simd | cancel | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1583 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1584 | // | parallel for simd| parallel | | |
| 1585 | // | parallel for simd| for | | |
| 1586 | // | parallel for simd| for simd | | |
| 1587 | // | parallel for simd| master | | |
| 1588 | // | parallel for simd| critical | | |
| 1589 | // | parallel for simd| simd | | |
| 1590 | // | parallel for simd| sections | | |
| 1591 | // | parallel for simd| section | | |
| 1592 | // | parallel for simd| single | | |
| 1593 | // | parallel for simd| parallel for | | |
| 1594 | // | parallel for simd|parallel for simd| | |
| 1595 | // | parallel for simd|parallel sections| | |
| 1596 | // | parallel for simd| task | | |
| 1597 | // | parallel for simd| taskyield | | |
| 1598 | // | parallel for simd| barrier | | |
| 1599 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1600 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1601 | // | parallel for simd| flush | | |
| 1602 | // | parallel for simd| ordered | | |
| 1603 | // | parallel for simd| atomic | | |
| 1604 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1605 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1606 | // | parallel for simd| cancellation | | |
| 1607 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1608 | // | parallel for simd| cancel | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1609 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1610 | // | sections | parallel | * | |
| 1611 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1612 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1613 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1614 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1615 | // | sections | simd | * | |
| 1616 | // | sections | sections | + | |
| 1617 | // | sections | section | * | |
| 1618 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1619 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1620 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1621 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1622 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1623 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1624 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1625 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1626 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1627 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1628 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1629 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1630 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1631 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1632 | // | sections | cancellation | | |
| 1633 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1634 | // | sections | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1635 | // +------------------+-----------------+------------------------------------+ |
| 1636 | // | section | parallel | * | |
| 1637 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1638 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1639 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1640 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1641 | // | section | simd | * | |
| 1642 | // | section | sections | + | |
| 1643 | // | section | section | + | |
| 1644 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1645 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1646 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1647 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1648 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1649 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1650 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1651 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1652 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1653 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1654 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1655 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1656 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1657 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1658 | // | section | cancellation | | |
| 1659 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1660 | // | section | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1661 | // +------------------+-----------------+------------------------------------+ |
| 1662 | // | single | parallel | * | |
| 1663 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1664 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1665 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1666 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1667 | // | single | simd | * | |
| 1668 | // | single | sections | + | |
| 1669 | // | single | section | + | |
| 1670 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1671 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1672 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1673 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1674 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1675 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1676 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1677 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1678 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1679 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1680 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1681 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1682 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1683 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1684 | // | single | cancellation | | |
| 1685 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1686 | // | single | cancel | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1687 | // +------------------+-----------------+------------------------------------+ |
| 1688 | // | parallel for | parallel | * | |
| 1689 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1690 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1691 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1692 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1693 | // | parallel for | simd | * | |
| 1694 | // | parallel for | sections | + | |
| 1695 | // | parallel for | section | + | |
| 1696 | // | parallel for | single | + | |
| 1697 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1698 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1699 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1700 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1701 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1702 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1703 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1704 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1705 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1706 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1707 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1708 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1709 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1710 | // | parallel for | cancellation | | |
| 1711 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1712 | // | parallel for | cancel | ! | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1713 | // +------------------+-----------------+------------------------------------+ |
| 1714 | // | parallel sections| parallel | * | |
| 1715 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1716 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1717 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1718 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1719 | // | parallel sections| simd | * | |
| 1720 | // | parallel sections| sections | + | |
| 1721 | // | parallel sections| section | * | |
| 1722 | // | parallel sections| single | + | |
| 1723 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1724 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1725 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1726 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1727 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1728 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1729 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1730 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1731 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1732 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1733 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1734 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1735 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1736 | // | parallel sections| cancellation | | |
| 1737 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1738 | // | parallel sections| cancel | ! | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1739 | // +------------------+-----------------+------------------------------------+ |
| 1740 | // | task | parallel | * | |
| 1741 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1742 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1743 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1744 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1745 | // | task | simd | * | |
| 1746 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1747 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1748 | // | task | single | + | |
| 1749 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1750 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1751 | // | task |parallel sections| * | |
| 1752 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1753 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1754 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1755 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1756 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1757 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1758 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1759 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1760 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1761 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1762 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1763 | // | | point | ! | |
| 1764 | // | task | cancel | ! | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1765 | // +------------------+-----------------+------------------------------------+ |
| 1766 | // | ordered | parallel | * | |
| 1767 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1768 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1769 | // | ordered | master | * | |
| 1770 | // | ordered | critical | * | |
| 1771 | // | ordered | simd | * | |
| 1772 | // | ordered | sections | + | |
| 1773 | // | ordered | section | + | |
| 1774 | // | ordered | single | + | |
| 1775 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1776 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1777 | // | ordered |parallel sections| * | |
| 1778 | // | ordered | task | * | |
| 1779 | // | ordered | taskyield | * | |
| 1780 | // | ordered | barrier | + | |
| 1781 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1782 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1783 | // | ordered | flush | * | |
| 1784 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1785 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1786 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1787 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1788 | // | ordered | cancellation | | |
| 1789 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1790 | // | ordered | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1791 | // +------------------+-----------------+------------------------------------+ |
| 1792 | // | atomic | parallel | | |
| 1793 | // | atomic | for | | |
| 1794 | // | atomic | for simd | | |
| 1795 | // | atomic | master | | |
| 1796 | // | atomic | critical | | |
| 1797 | // | atomic | simd | | |
| 1798 | // | atomic | sections | | |
| 1799 | // | atomic | section | | |
| 1800 | // | atomic | single | | |
| 1801 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1802 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1803 | // | atomic |parallel sections| | |
| 1804 | // | atomic | task | | |
| 1805 | // | atomic | taskyield | | |
| 1806 | // | atomic | barrier | | |
| 1807 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1808 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1809 | // | atomic | flush | | |
| 1810 | // | atomic | ordered | | |
| 1811 | // | atomic | atomic | | |
| 1812 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1813 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1814 | // | atomic | cancellation | | |
| 1815 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1816 | // | atomic | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1817 | // +------------------+-----------------+------------------------------------+ |
| 1818 | // | target | parallel | * | |
| 1819 | // | target | for | * | |
| 1820 | // | target | for simd | * | |
| 1821 | // | target | master | * | |
| 1822 | // | target | critical | * | |
| 1823 | // | target | simd | * | |
| 1824 | // | target | sections | * | |
| 1825 | // | target | section | * | |
| 1826 | // | target | single | * | |
| 1827 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1828 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1829 | // | target |parallel sections| * | |
| 1830 | // | target | task | * | |
| 1831 | // | target | taskyield | * | |
| 1832 | // | target | barrier | * | |
| 1833 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1834 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1835 | // | target | flush | * | |
| 1836 | // | target | ordered | * | |
| 1837 | // | target | atomic | * | |
| 1838 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1839 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1840 | // | target | cancellation | | |
| 1841 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1842 | // | target | cancel | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1843 | // +------------------+-----------------+------------------------------------+ |
| 1844 | // | teams | parallel | * | |
| 1845 | // | teams | for | + | |
| 1846 | // | teams | for simd | + | |
| 1847 | // | teams | master | + | |
| 1848 | // | teams | critical | + | |
| 1849 | // | teams | simd | + | |
| 1850 | // | teams | sections | + | |
| 1851 | // | teams | section | + | |
| 1852 | // | teams | single | + | |
| 1853 | // | teams | parallel for | * | |
| 1854 | // | teams |parallel for simd| * | |
| 1855 | // | teams |parallel sections| * | |
| 1856 | // | teams | task | + | |
| 1857 | // | teams | taskyield | + | |
| 1858 | // | teams | barrier | + | |
| 1859 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1860 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1861 | // | teams | flush | + | |
| 1862 | // | teams | ordered | + | |
| 1863 | // | teams | atomic | + | |
| 1864 | // | teams | target | + | |
| 1865 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1866 | // | teams | cancellation | | |
| 1867 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1868 | // | teams | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1869 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1870 | if (Stack->getCurScope()) { |
| 1871 | auto ParentRegion = Stack->getParentDirective(); |
| 1872 | bool NestingProhibited = false; |
| 1873 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1874 | enum { |
| 1875 | NoRecommend, |
| 1876 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1877 | ShouldBeInOrderedRegion, |
| 1878 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1879 | } Recommend = NoRecommend; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1880 | if (isOpenMPSimdDirective(ParentRegion)) { |
| 1881 | // OpenMP [2.16, Nesting of Regions] |
| 1882 | // OpenMP constructs may not be nested inside a simd region. |
| 1883 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1884 | return true; |
| 1885 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1886 | if (ParentRegion == OMPD_atomic) { |
| 1887 | // OpenMP [2.16, Nesting of Regions] |
| 1888 | // OpenMP constructs may not be nested inside an atomic region. |
| 1889 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1890 | return true; |
| 1891 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1892 | if (CurrentRegion == OMPD_section) { |
| 1893 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1894 | // Orphaned section directives are prohibited. That is, the section |
| 1895 | // directives must appear within the sections construct and must not be |
| 1896 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1897 | if (ParentRegion != OMPD_sections && |
| 1898 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1899 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1900 | << (ParentRegion != OMPD_unknown) |
| 1901 | << getOpenMPDirectiveName(ParentRegion); |
| 1902 | return true; |
| 1903 | } |
| 1904 | return false; |
| 1905 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1906 | // Allow some constructs to be orphaned (they could be used in functions, |
| 1907 | // called from OpenMP regions with the required preconditions). |
| 1908 | if (ParentRegion == OMPD_unknown) |
| 1909 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1910 | if (CurrentRegion == OMPD_cancellation_point || |
| 1911 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1912 | // OpenMP [2.16, Nesting of Regions] |
| 1913 | // A cancellation point construct for which construct-type-clause is |
| 1914 | // taskgroup must be nested inside a task construct. A cancellation |
| 1915 | // point construct for which construct-type-clause is not taskgroup must |
| 1916 | // be closely nested inside an OpenMP construct that matches the type |
| 1917 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1918 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 1919 | // nested inside a task construct. A cancel construct for which |
| 1920 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 1921 | // OpenMP construct that matches the type specified in |
| 1922 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1923 | NestingProhibited = |
| 1924 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 1925 | (CancelRegion == OMPD_for && |
| 1926 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1927 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 1928 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 1929 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 1930 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1931 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1932 | // OpenMP [2.16, Nesting of Regions] |
| 1933 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1934 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1935 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 1936 | ParentRegion == OMPD_task; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1937 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 1938 | // OpenMP [2.16, Nesting of Regions] |
| 1939 | // A critical region may not be nested (closely or otherwise) inside a |
| 1940 | // critical region with the same name. Note that this restriction is not |
| 1941 | // sufficient to prevent deadlock. |
| 1942 | SourceLocation PreviousCriticalLoc; |
| 1943 | bool DeadLock = |
| 1944 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 1945 | OpenMPDirectiveKind K, |
| 1946 | const DeclarationNameInfo &DNI, |
| 1947 | SourceLocation Loc) |
| 1948 | ->bool { |
| 1949 | if (K == OMPD_critical && |
| 1950 | DNI.getName() == CurrentName.getName()) { |
| 1951 | PreviousCriticalLoc = Loc; |
| 1952 | return true; |
| 1953 | } else |
| 1954 | return false; |
| 1955 | }, |
| 1956 | false /* skip top directive */); |
| 1957 | if (DeadLock) { |
| 1958 | SemaRef.Diag(StartLoc, |
| 1959 | diag::err_omp_prohibited_region_critical_same_name) |
| 1960 | << CurrentName.getName(); |
| 1961 | if (PreviousCriticalLoc.isValid()) |
| 1962 | SemaRef.Diag(PreviousCriticalLoc, |
| 1963 | diag::note_omp_previous_critical_region); |
| 1964 | return true; |
| 1965 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1966 | } else if (CurrentRegion == OMPD_barrier) { |
| 1967 | // OpenMP [2.16, Nesting of Regions] |
| 1968 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1969 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1970 | NestingProhibited = |
| 1971 | isOpenMPWorksharingDirective(ParentRegion) || |
| 1972 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1973 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1974 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1975 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1976 | // OpenMP [2.16, Nesting of Regions] |
| 1977 | // A worksharing region may not be closely nested inside a worksharing, |
| 1978 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1979 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1980 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1981 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1982 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
| 1983 | Recommend = ShouldBeInParallelRegion; |
| 1984 | } else if (CurrentRegion == OMPD_ordered) { |
| 1985 | // OpenMP [2.16, Nesting of Regions] |
| 1986 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1987 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1988 | // An ordered region must be closely nested inside a loop region (or |
| 1989 | // parallel loop region) with an ordered clause. |
| 1990 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1991 | ParentRegion == OMPD_task || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1992 | !Stack->isParentOrderedRegion(); |
| 1993 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1994 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 1995 | // OpenMP [2.16, Nesting of Regions] |
| 1996 | // If specified, a teams construct must be contained within a target |
| 1997 | // construct. |
| 1998 | NestingProhibited = ParentRegion != OMPD_target; |
| 1999 | Recommend = ShouldBeInTargetRegion; |
| 2000 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2001 | } |
| 2002 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2003 | // OpenMP [2.16, Nesting of Regions] |
| 2004 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2005 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2006 | // constructs that can be closely nested in the teams region. |
| 2007 | // TODO: add distribute directive. |
| 2008 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 2009 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2010 | } |
| 2011 | if (NestingProhibited) { |
| 2012 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2013 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2014 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2015 | return true; |
| 2016 | } |
| 2017 | } |
| 2018 | return false; |
| 2019 | } |
| 2020 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2021 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2022 | ArrayRef<OMPClause *> Clauses, |
| 2023 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2024 | bool ErrorFound = false; |
| 2025 | unsigned NamedModifiersNumber = 0; |
| 2026 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2027 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2028 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2029 | for (const auto *C : Clauses) { |
| 2030 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2031 | // At most one if clause without a directive-name-modifier can appear on |
| 2032 | // the directive. |
| 2033 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2034 | if (FoundNameModifiers[CurNM]) { |
| 2035 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2036 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2037 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2038 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2039 | } else if (CurNM != OMPD_unknown) { |
| 2040 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2041 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2042 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2043 | FoundNameModifiers[CurNM] = IC; |
| 2044 | if (CurNM == OMPD_unknown) |
| 2045 | continue; |
| 2046 | // Check if the specified name modifier is allowed for the current |
| 2047 | // directive. |
| 2048 | // At most one if clause with the particular directive-name-modifier can |
| 2049 | // appear on the directive. |
| 2050 | bool MatchFound = false; |
| 2051 | for (auto NM : AllowedNameModifiers) { |
| 2052 | if (CurNM == NM) { |
| 2053 | MatchFound = true; |
| 2054 | break; |
| 2055 | } |
| 2056 | } |
| 2057 | if (!MatchFound) { |
| 2058 | S.Diag(IC->getNameModifierLoc(), |
| 2059 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2060 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2061 | ErrorFound = true; |
| 2062 | } |
| 2063 | } |
| 2064 | } |
| 2065 | // If any if clause on the directive includes a directive-name-modifier then |
| 2066 | // all if clauses on the directive must include a directive-name-modifier. |
| 2067 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2068 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2069 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2070 | diag::err_omp_no_more_if_clause); |
| 2071 | } else { |
| 2072 | std::string Values; |
| 2073 | std::string Sep(", "); |
| 2074 | unsigned AllowedCnt = 0; |
| 2075 | unsigned TotalAllowedNum = |
| 2076 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2077 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2078 | ++Cnt) { |
| 2079 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2080 | if (!FoundNameModifiers[NM]) { |
| 2081 | Values += "'"; |
| 2082 | Values += getOpenMPDirectiveName(NM); |
| 2083 | Values += "'"; |
| 2084 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2085 | Values += " or "; |
| 2086 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2087 | Values += Sep; |
| 2088 | ++AllowedCnt; |
| 2089 | } |
| 2090 | } |
| 2091 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2092 | diag::err_omp_unnamed_if_clause) |
| 2093 | << (TotalAllowedNum > 1) << Values; |
| 2094 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2095 | for (auto Loc : NameModifierLoc) { |
| 2096 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2097 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2098 | ErrorFound = true; |
| 2099 | } |
| 2100 | return ErrorFound; |
| 2101 | } |
| 2102 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2103 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2104 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2105 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2106 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2107 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2108 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2109 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2110 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2111 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2112 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2113 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2114 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2115 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2116 | if (AStmt) { |
| 2117 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2118 | |
| 2119 | // Check default data sharing attributes for referenced variables. |
| 2120 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2121 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2122 | if (DSAChecker.isErrorFound()) |
| 2123 | return StmtError(); |
| 2124 | // Generate list of implicitly defined firstprivate variables. |
| 2125 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2126 | |
| 2127 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2128 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2129 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2130 | SourceLocation(), SourceLocation())) { |
| 2131 | ClausesWithImplicit.push_back(Implicit); |
| 2132 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2133 | DSAChecker.getImplicitFirstprivate().size(); |
| 2134 | } else |
| 2135 | ErrorFound = true; |
| 2136 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2137 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2138 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2139 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2140 | switch (Kind) { |
| 2141 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2142 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2143 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2144 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2145 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2146 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2147 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2148 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2149 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2150 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2151 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2152 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2153 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2154 | case OMPD_for_simd: |
| 2155 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2156 | EndLoc, VarsWithInheritedDSA); |
| 2157 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2158 | case OMPD_sections: |
| 2159 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2160 | EndLoc); |
| 2161 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2162 | case OMPD_section: |
| 2163 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2164 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2165 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2166 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2167 | case OMPD_single: |
| 2168 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2169 | EndLoc); |
| 2170 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2171 | case OMPD_master: |
| 2172 | assert(ClausesWithImplicit.empty() && |
| 2173 | "No clauses are allowed for 'omp master' directive"); |
| 2174 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2175 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2176 | case OMPD_critical: |
| 2177 | assert(ClausesWithImplicit.empty() && |
| 2178 | "No clauses are allowed for 'omp critical' directive"); |
| 2179 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2180 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2181 | case OMPD_parallel_for: |
| 2182 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2183 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2184 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2185 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2186 | case OMPD_parallel_for_simd: |
| 2187 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2188 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2189 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2190 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2191 | case OMPD_parallel_sections: |
| 2192 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2193 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2194 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2195 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2196 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2197 | Res = |
| 2198 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2199 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2200 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2201 | case OMPD_taskyield: |
| 2202 | assert(ClausesWithImplicit.empty() && |
| 2203 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2204 | assert(AStmt == nullptr && |
| 2205 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2206 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2207 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2208 | case OMPD_barrier: |
| 2209 | assert(ClausesWithImplicit.empty() && |
| 2210 | "No clauses are allowed for 'omp barrier' directive"); |
| 2211 | assert(AStmt == nullptr && |
| 2212 | "No associated statement allowed for 'omp barrier' directive"); |
| 2213 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2214 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2215 | case OMPD_taskwait: |
| 2216 | assert(ClausesWithImplicit.empty() && |
| 2217 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2218 | assert(AStmt == nullptr && |
| 2219 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2220 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2221 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2222 | case OMPD_taskgroup: |
| 2223 | assert(ClausesWithImplicit.empty() && |
| 2224 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2225 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2226 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2227 | case OMPD_flush: |
| 2228 | assert(AStmt == nullptr && |
| 2229 | "No associated statement allowed for 'omp flush' directive"); |
| 2230 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2231 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2232 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2233 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2234 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2235 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2236 | case OMPD_atomic: |
| 2237 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2238 | EndLoc); |
| 2239 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2240 | case OMPD_teams: |
| 2241 | Res = |
| 2242 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2243 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2244 | case OMPD_target: |
| 2245 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2246 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2247 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2248 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2249 | case OMPD_cancellation_point: |
| 2250 | assert(ClausesWithImplicit.empty() && |
| 2251 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2252 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2253 | "cancellation point' directive"); |
| 2254 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2255 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2256 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2257 | assert(AStmt == nullptr && |
| 2258 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2259 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2260 | CancelRegion); |
| 2261 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2262 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2263 | case OMPD_target_data: |
| 2264 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2265 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2266 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2267 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2268 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2269 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2270 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2271 | llvm_unreachable("Unknown OpenMP directive"); |
| 2272 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2273 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2274 | for (auto P : VarsWithInheritedDSA) { |
| 2275 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2276 | << P.first << P.second->getSourceRange(); |
| 2277 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2278 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2279 | |
| 2280 | if (!AllowedNameModifiers.empty()) |
| 2281 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2282 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2283 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2284 | if (ErrorFound) |
| 2285 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2286 | return Res; |
| 2287 | } |
| 2288 | |
| 2289 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2290 | Stmt *AStmt, |
| 2291 | SourceLocation StartLoc, |
| 2292 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2293 | if (!AStmt) |
| 2294 | return StmtError(); |
| 2295 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2296 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2297 | // 1.2.2 OpenMP Language Terminology |
| 2298 | // Structured block - An executable statement with a single entry at the |
| 2299 | // top and a single exit at the bottom. |
| 2300 | // The point of exit cannot be a branch out of the structured block. |
| 2301 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2302 | CS->getCapturedDecl()->setNothrow(); |
| 2303 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2304 | getCurFunction()->setHasBranchProtectedScope(); |
| 2305 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2306 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2307 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2308 | } |
| 2309 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2310 | namespace { |
| 2311 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2312 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2313 | /// for IR generation. |
| 2314 | class OpenMPIterationSpaceChecker { |
| 2315 | /// \brief Reference to Sema. |
| 2316 | Sema &SemaRef; |
| 2317 | /// \brief A location for diagnostics (when there is no some better location). |
| 2318 | SourceLocation DefaultLoc; |
| 2319 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2320 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2321 | /// \brief A source location for referring to loop init later. |
| 2322 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2323 | /// \brief A source location for referring to condition later. |
| 2324 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2325 | /// \brief A source location for referring to increment later. |
| 2326 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2327 | /// \brief Loop variable. |
| 2328 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2329 | /// \brief Reference to loop variable. |
| 2330 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2331 | /// \brief Lower bound (initializer for the var). |
| 2332 | Expr *LB; |
| 2333 | /// \brief Upper bound. |
| 2334 | Expr *UB; |
| 2335 | /// \brief Loop step (increment). |
| 2336 | Expr *Step; |
| 2337 | /// \brief This flag is true when condition is one of: |
| 2338 | /// Var < UB |
| 2339 | /// Var <= UB |
| 2340 | /// UB > Var |
| 2341 | /// UB >= Var |
| 2342 | bool TestIsLessOp; |
| 2343 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2344 | bool TestIsStrictOp; |
| 2345 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2346 | bool SubtractStep; |
| 2347 | |
| 2348 | public: |
| 2349 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2350 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2351 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2352 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2353 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2354 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2355 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2356 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2357 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2358 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2359 | /// for less/greater and for strict/non-strict comparison. |
| 2360 | bool CheckCond(Expr *S); |
| 2361 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2362 | /// does not conform, otherwise save loop step (#Step). |
| 2363 | bool CheckInc(Expr *S); |
| 2364 | /// \brief Return the loop counter variable. |
| 2365 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2366 | /// \brief Return the reference expression to loop counter variable. |
| 2367 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2368 | /// \brief Source range of the loop init. |
| 2369 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2370 | /// \brief Source range of the loop condition. |
| 2371 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2372 | /// \brief Source range of the loop increment. |
| 2373 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2374 | /// \brief True if the step should be subtracted. |
| 2375 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2376 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2377 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2378 | /// \brief Build the precondition expression for the loops. |
| 2379 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2380 | /// \brief Build reference expression to the counter be used for codegen. |
| 2381 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2382 | /// \brief Build reference expression to the private counter be used for |
| 2383 | /// codegen. |
| 2384 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2385 | /// \brief Build initization of the counter be used for codegen. |
| 2386 | Expr *BuildCounterInit() const; |
| 2387 | /// \brief Build step of the counter be used for codegen. |
| 2388 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2389 | /// \brief Return true if any expression is dependent. |
| 2390 | bool Dependent() const; |
| 2391 | |
| 2392 | private: |
| 2393 | /// \brief Check the right-hand side of an assignment in the increment |
| 2394 | /// expression. |
| 2395 | bool CheckIncRHS(Expr *RHS); |
| 2396 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2397 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2398 | /// \brief Helper to set upper bound. |
| 2399 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2400 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2401 | /// \brief Helper to set loop increment. |
| 2402 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2403 | }; |
| 2404 | |
| 2405 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2406 | if (!Var) { |
| 2407 | assert(!LB && !UB && !Step); |
| 2408 | return false; |
| 2409 | } |
| 2410 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2411 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2412 | } |
| 2413 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2414 | template <typename T> |
| 2415 | static T *getExprAsWritten(T *E) { |
| 2416 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2417 | E = ExprTemp->getSubExpr(); |
| 2418 | |
| 2419 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2420 | E = MTE->GetTemporaryExpr(); |
| 2421 | |
| 2422 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2423 | E = Binder->getSubExpr(); |
| 2424 | |
| 2425 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2426 | E = ICE->getSubExprAsWritten(); |
| 2427 | return E->IgnoreParens(); |
| 2428 | } |
| 2429 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2430 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2431 | DeclRefExpr *NewVarRefExpr, |
| 2432 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2433 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2434 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2435 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2436 | if (!NewVar || !NewLB) |
| 2437 | return true; |
| 2438 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2439 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2440 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2441 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2442 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2443 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2444 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2445 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2446 | LB = NewLB; |
| 2447 | return false; |
| 2448 | } |
| 2449 | |
| 2450 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| 2451 | const SourceRange &SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2452 | SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2453 | // State consistency checking to ensure correct usage. |
| 2454 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2455 | !TestIsLessOp && !TestIsStrictOp); |
| 2456 | if (!NewUB) |
| 2457 | return true; |
| 2458 | UB = NewUB; |
| 2459 | TestIsLessOp = LessOp; |
| 2460 | TestIsStrictOp = StrictOp; |
| 2461 | ConditionSrcRange = SR; |
| 2462 | ConditionLoc = SL; |
| 2463 | return false; |
| 2464 | } |
| 2465 | |
| 2466 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2467 | // State consistency checking to ensure correct usage. |
| 2468 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2469 | if (!NewStep) |
| 2470 | return true; |
| 2471 | if (!NewStep->isValueDependent()) { |
| 2472 | // Check that the step is integer expression. |
| 2473 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2474 | ExprResult Val = |
| 2475 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2476 | if (Val.isInvalid()) |
| 2477 | return true; |
| 2478 | NewStep = Val.get(); |
| 2479 | |
| 2480 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2481 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2482 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2483 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2484 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2485 | // the loop. |
| 2486 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2487 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2488 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2489 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2490 | // the loop. |
| 2491 | llvm::APSInt Result; |
| 2492 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2493 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2494 | bool IsConstNeg = |
| 2495 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2496 | bool IsConstPos = |
| 2497 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2498 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2499 | if (UB && (IsConstZero || |
| 2500 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2501 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2502 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2503 | diag::err_omp_loop_incr_not_compatible) |
| 2504 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2505 | SemaRef.Diag(ConditionLoc, |
| 2506 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2507 | << TestIsLessOp << ConditionSrcRange; |
| 2508 | return true; |
| 2509 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2510 | if (TestIsLessOp == Subtract) { |
| 2511 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2512 | NewStep).get(); |
| 2513 | Subtract = !Subtract; |
| 2514 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | Step = NewStep; |
| 2518 | SubtractStep = Subtract; |
| 2519 | return false; |
| 2520 | } |
| 2521 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2522 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2523 | // Check init-expr for canonical loop form and save loop counter |
| 2524 | // variable - #Var and its initialization value - #LB. |
| 2525 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2526 | // var = lb |
| 2527 | // integer-type var = lb |
| 2528 | // random-access-iterator-type var = lb |
| 2529 | // pointer-type var = lb |
| 2530 | // |
| 2531 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2532 | if (EmitDiags) { |
| 2533 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2534 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2535 | return true; |
| 2536 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2537 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2538 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2539 | S = E->IgnoreParens(); |
| 2540 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2541 | if (BO->getOpcode() == BO_Assign) |
| 2542 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2543 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2544 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2545 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2546 | if (DS->isSingleDecl()) { |
| 2547 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2548 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2549 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2550 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2551 | SemaRef.Diag(S->getLocStart(), |
| 2552 | diag::ext_omp_loop_not_canonical_init) |
| 2553 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2554 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2555 | } |
| 2556 | } |
| 2557 | } |
| 2558 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2559 | if (CE->getOperator() == OO_Equal) |
| 2560 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2561 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2562 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2563 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2564 | if (EmitDiags) { |
| 2565 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2566 | << S->getSourceRange(); |
| 2567 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2568 | return true; |
| 2569 | } |
| 2570 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2571 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2572 | /// variable (which may be the loop variable) if possible. |
| 2573 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2574 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2575 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2576 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2577 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2578 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2579 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2580 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2581 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2582 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2583 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2584 | if (!DRE) |
| 2585 | return nullptr; |
| 2586 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2587 | } |
| 2588 | |
| 2589 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2590 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2591 | // less/greater and for strict/non-strict comparison. |
| 2592 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2593 | // var relational-op b |
| 2594 | // b relational-op var |
| 2595 | // |
| 2596 | if (!S) { |
| 2597 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2598 | return true; |
| 2599 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2600 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2601 | SourceLocation CondLoc = S->getLocStart(); |
| 2602 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2603 | if (BO->isRelationalOp()) { |
| 2604 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2605 | return SetUB(BO->getRHS(), |
| 2606 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2607 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2608 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2609 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2610 | return SetUB(BO->getLHS(), |
| 2611 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2612 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2613 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2614 | } |
| 2615 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2616 | if (CE->getNumArgs() == 2) { |
| 2617 | auto Op = CE->getOperator(); |
| 2618 | switch (Op) { |
| 2619 | case OO_Greater: |
| 2620 | case OO_GreaterEqual: |
| 2621 | case OO_Less: |
| 2622 | case OO_LessEqual: |
| 2623 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2624 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2625 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2626 | CE->getOperatorLoc()); |
| 2627 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2628 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2629 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2630 | CE->getOperatorLoc()); |
| 2631 | break; |
| 2632 | default: |
| 2633 | break; |
| 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2638 | << S->getSourceRange() << Var; |
| 2639 | return true; |
| 2640 | } |
| 2641 | |
| 2642 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2643 | // RHS of canonical loop form increment can be: |
| 2644 | // var + incr |
| 2645 | // incr + var |
| 2646 | // var - incr |
| 2647 | // |
| 2648 | RHS = RHS->IgnoreParenImpCasts(); |
| 2649 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2650 | if (BO->isAdditiveOp()) { |
| 2651 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2652 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2653 | return SetStep(BO->getRHS(), !IsAdd); |
| 2654 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2655 | return SetStep(BO->getLHS(), false); |
| 2656 | } |
| 2657 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2658 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2659 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2660 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2661 | return SetStep(CE->getArg(1), !IsAdd); |
| 2662 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2663 | return SetStep(CE->getArg(0), false); |
| 2664 | } |
| 2665 | } |
| 2666 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2667 | << RHS->getSourceRange() << Var; |
| 2668 | return true; |
| 2669 | } |
| 2670 | |
| 2671 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2672 | // Check incr-expr for canonical loop form and return true if it |
| 2673 | // does not conform. |
| 2674 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2675 | // ++var |
| 2676 | // var++ |
| 2677 | // --var |
| 2678 | // var-- |
| 2679 | // var += incr |
| 2680 | // var -= incr |
| 2681 | // var = var + incr |
| 2682 | // var = incr + var |
| 2683 | // var = var - incr |
| 2684 | // |
| 2685 | if (!S) { |
| 2686 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2687 | return true; |
| 2688 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2689 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2690 | S = S->IgnoreParens(); |
| 2691 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2692 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2693 | return SetStep( |
| 2694 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2695 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2696 | false); |
| 2697 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2698 | switch (BO->getOpcode()) { |
| 2699 | case BO_AddAssign: |
| 2700 | case BO_SubAssign: |
| 2701 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2702 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2703 | break; |
| 2704 | case BO_Assign: |
| 2705 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2706 | return CheckIncRHS(BO->getRHS()); |
| 2707 | break; |
| 2708 | default: |
| 2709 | break; |
| 2710 | } |
| 2711 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2712 | switch (CE->getOperator()) { |
| 2713 | case OO_PlusPlus: |
| 2714 | case OO_MinusMinus: |
| 2715 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2716 | return SetStep( |
| 2717 | SemaRef.ActOnIntegerConstant( |
| 2718 | CE->getLocStart(), |
| 2719 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2720 | false); |
| 2721 | break; |
| 2722 | case OO_PlusEqual: |
| 2723 | case OO_MinusEqual: |
| 2724 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2725 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2726 | break; |
| 2727 | case OO_Equal: |
| 2728 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2729 | return CheckIncRHS(CE->getArg(1)); |
| 2730 | break; |
| 2731 | default: |
| 2732 | break; |
| 2733 | } |
| 2734 | } |
| 2735 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2736 | << S->getSourceRange() << Var; |
| 2737 | return true; |
| 2738 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2739 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2740 | namespace { |
| 2741 | // Transform variables declared in GNU statement expressions to new ones to |
| 2742 | // avoid crash on codegen. |
| 2743 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 2744 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 2745 | |
| 2746 | public: |
| 2747 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 2748 | |
| 2749 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 2750 | if (auto *VD = cast<VarDecl>(D)) |
| 2751 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 2752 | !isa<ImplicitParamDecl>(D)) { |
| 2753 | auto *NewVD = VarDecl::Create( |
| 2754 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 2755 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 2756 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 2757 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 2758 | NewVD->setInit(VD->getInit()); |
| 2759 | NewVD->setInitStyle(VD->getInitStyle()); |
| 2760 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 2761 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 2762 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 2763 | NewVD->setConstexpr(VD->isConstexpr()); |
| 2764 | NewVD->setInitCapture(VD->isInitCapture()); |
| 2765 | NewVD->setPreviousDeclInSameBlockScope( |
| 2766 | VD->isPreviousDeclInSameBlockScope()); |
| 2767 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 2768 | if (VD->hasAttrs()) |
| 2769 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2770 | transformedLocalDecl(VD, NewVD); |
| 2771 | return NewVD; |
| 2772 | } |
| 2773 | return BaseTransform::TransformDefinition(Loc, D); |
| 2774 | } |
| 2775 | |
| 2776 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 2777 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 2778 | if (E->getDecl() != NewD) { |
| 2779 | NewD->setReferenced(); |
| 2780 | NewD->markUsed(SemaRef.Context); |
| 2781 | return DeclRefExpr::Create( |
| 2782 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 2783 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 2784 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 2785 | } |
| 2786 | return BaseTransform::TransformDeclRefExpr(E); |
| 2787 | } |
| 2788 | }; |
| 2789 | } |
| 2790 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2791 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2792 | Expr * |
| 2793 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2794 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2795 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2796 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2797 | auto VarType = Var->getType().getNonReferenceType(); |
| 2798 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2799 | SemaRef.getLangOpts().CPlusPlus) { |
| 2800 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2801 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 2802 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 2803 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 2804 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 2805 | if (!Upper || !Lower) |
| 2806 | return nullptr; |
| 2807 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 2808 | Sema::AA_Converting, |
| 2809 | /*AllowExplicit=*/true) |
| 2810 | .get(); |
| 2811 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 2812 | Sema::AA_Converting, |
| 2813 | /*AllowExplicit=*/true) |
| 2814 | .get(); |
| 2815 | if (!Upper || !Lower) |
| 2816 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2817 | |
| 2818 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2819 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2820 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2821 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2822 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2823 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2824 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2825 | return nullptr; |
| 2826 | } |
| 2827 | } |
| 2828 | |
| 2829 | if (!Diff.isUsable()) |
| 2830 | return nullptr; |
| 2831 | |
| 2832 | // Upper - Lower [- 1] |
| 2833 | if (TestIsStrictOp) |
| 2834 | Diff = SemaRef.BuildBinOp( |
| 2835 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2836 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2837 | if (!Diff.isUsable()) |
| 2838 | return nullptr; |
| 2839 | |
| 2840 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2841 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2842 | if (NewStep.isInvalid()) |
| 2843 | return nullptr; |
| 2844 | NewStep = SemaRef.PerformImplicitConversion( |
| 2845 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2846 | /*AllowExplicit=*/true); |
| 2847 | if (NewStep.isInvalid()) |
| 2848 | return nullptr; |
| 2849 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2850 | if (!Diff.isUsable()) |
| 2851 | return nullptr; |
| 2852 | |
| 2853 | // Parentheses (for dumping/debugging purposes only). |
| 2854 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 2855 | if (!Diff.isUsable()) |
| 2856 | return nullptr; |
| 2857 | |
| 2858 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2859 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2860 | if (NewStep.isInvalid()) |
| 2861 | return nullptr; |
| 2862 | NewStep = SemaRef.PerformImplicitConversion( |
| 2863 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2864 | /*AllowExplicit=*/true); |
| 2865 | if (NewStep.isInvalid()) |
| 2866 | return nullptr; |
| 2867 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2868 | if (!Diff.isUsable()) |
| 2869 | return nullptr; |
| 2870 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2871 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2872 | QualType Type = Diff.get()->getType(); |
| 2873 | auto &C = SemaRef.Context; |
| 2874 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 2875 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 2876 | if (!Type->isIntegerType() || UseVarType) { |
| 2877 | unsigned NewSize = |
| 2878 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 2879 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 2880 | : Type->hasSignedIntegerRepresentation(); |
| 2881 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 2882 | Diff = SemaRef.PerformImplicitConversion( |
| 2883 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 2884 | if (!Diff.isUsable()) |
| 2885 | return nullptr; |
| 2886 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2887 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2888 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 2889 | if (NewSize != C.getTypeSize(Type)) { |
| 2890 | if (NewSize < C.getTypeSize(Type)) { |
| 2891 | assert(NewSize == 64 && "incorrect loop var size"); |
| 2892 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 2893 | << InitSrcRange << ConditionSrcRange; |
| 2894 | } |
| 2895 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2896 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 2897 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2898 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 2899 | Sema::AA_Converting, true); |
| 2900 | if (!Diff.isUsable()) |
| 2901 | return nullptr; |
| 2902 | } |
| 2903 | } |
| 2904 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2905 | return Diff.get(); |
| 2906 | } |
| 2907 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2908 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 2909 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 2910 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 2911 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2912 | TransformToNewDefs Transform(SemaRef); |
| 2913 | |
| 2914 | auto NewLB = Transform.TransformExpr(LB); |
| 2915 | auto NewUB = Transform.TransformExpr(UB); |
| 2916 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 2917 | return Cond; |
| 2918 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 2919 | Sema::AA_Converting, |
| 2920 | /*AllowExplicit=*/true); |
| 2921 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 2922 | Sema::AA_Converting, |
| 2923 | /*AllowExplicit=*/true); |
| 2924 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 2925 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2926 | auto CondExpr = SemaRef.BuildBinOp( |
| 2927 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 2928 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2929 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2930 | if (CondExpr.isUsable()) { |
| 2931 | CondExpr = SemaRef.PerformImplicitConversion( |
| 2932 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 2933 | /*AllowExplicit=*/true); |
| 2934 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2935 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 2936 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 2937 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 2938 | } |
| 2939 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2940 | /// \brief Build reference expression to the counter be used for codegen. |
| 2941 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2942 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 2943 | DefaultLoc); |
| 2944 | } |
| 2945 | |
| 2946 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 2947 | if (Var && !Var->isInvalidDecl()) { |
| 2948 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 2949 | auto *PrivateVar = |
| 2950 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 2951 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2952 | if (PrivateVar->isInvalidDecl()) |
| 2953 | return nullptr; |
| 2954 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 2955 | } |
| 2956 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2957 | } |
| 2958 | |
| 2959 | /// \brief Build initization of the counter be used for codegen. |
| 2960 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 2961 | |
| 2962 | /// \brief Build step of the counter be used for codegen. |
| 2963 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 2964 | |
| 2965 | /// \brief Iteration space of a single for loop. |
| 2966 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2967 | /// \brief Condition of the loop. |
| 2968 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2969 | /// \brief This expression calculates the number of iterations in the loop. |
| 2970 | /// It is always possible to calculate it before starting the loop. |
| 2971 | Expr *NumIterations; |
| 2972 | /// \brief The loop counter variable. |
| 2973 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2974 | /// \brief Private loop counter variable. |
| 2975 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2976 | /// \brief This is initializer for the initial value of #CounterVar. |
| 2977 | Expr *CounterInit; |
| 2978 | /// \brief This is step for the #CounterVar used to generate its update: |
| 2979 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 2980 | Expr *CounterStep; |
| 2981 | /// \brief Should step be subtracted? |
| 2982 | bool Subtract; |
| 2983 | /// \brief Source range of the loop init. |
| 2984 | SourceRange InitSrcRange; |
| 2985 | /// \brief Source range of the loop condition. |
| 2986 | SourceRange CondSrcRange; |
| 2987 | /// \brief Source range of the loop increment. |
| 2988 | SourceRange IncSrcRange; |
| 2989 | }; |
| 2990 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2991 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2992 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2993 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 2994 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 2995 | assert(Init && "Expected loop in canonical form."); |
| 2996 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 2997 | if (CollapseIteration > 0 && |
| 2998 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 2999 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 3000 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3001 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 3002 | } |
| 3003 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 3004 | } |
| 3005 | } |
| 3006 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3007 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3008 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3009 | static bool CheckOpenMPIterationSpace( |
| 3010 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3011 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3012 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3013 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3014 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3015 | // OpenMP [2.6, Canonical Loop Form] |
| 3016 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3017 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3018 | if (!For) { |
| 3019 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3020 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3021 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3022 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3023 | if (NestedLoopCount > 1) { |
| 3024 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3025 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3026 | diag::note_omp_collapse_ordered_expr) |
| 3027 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3028 | << OrderedLoopCountExpr->getSourceRange(); |
| 3029 | else if (CollapseLoopCountExpr) |
| 3030 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3031 | diag::note_omp_collapse_ordered_expr) |
| 3032 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3033 | else |
| 3034 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3035 | diag::note_omp_collapse_ordered_expr) |
| 3036 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3037 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3038 | return true; |
| 3039 | } |
| 3040 | assert(For->getBody()); |
| 3041 | |
| 3042 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3043 | |
| 3044 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3045 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3046 | if (ISC.CheckInit(Init)) { |
| 3047 | return true; |
| 3048 | } |
| 3049 | |
| 3050 | bool HasErrors = false; |
| 3051 | |
| 3052 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3053 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3054 | |
| 3055 | // OpenMP [2.6, Canonical Loop Form] |
| 3056 | // Var is one of the following: |
| 3057 | // A variable of signed or unsigned integer type. |
| 3058 | // For C++, a variable of a random access iterator type. |
| 3059 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3060 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3061 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3062 | !VarType->isPointerType() && |
| 3063 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3064 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3065 | << SemaRef.getLangOpts().CPlusPlus; |
| 3066 | HasErrors = true; |
| 3067 | } |
| 3068 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3069 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3070 | // Construct |
| 3071 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3072 | // parallel for construct is (are) private. |
| 3073 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3074 | // with just one associated for-loop is linear with a constant-linear-step |
| 3075 | // that is the increment of the associated for-loop. |
| 3076 | // Exclude loop var from the list of variables with implicitly defined data |
| 3077 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3078 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3079 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3080 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3081 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3082 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3083 | // with just one associated for-loop may be listed in a linear clause with a |
| 3084 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3085 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3086 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3087 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3088 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3089 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3090 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3091 | auto PredeterminedCKind = |
| 3092 | isOpenMPSimdDirective(DKind) |
| 3093 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3094 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3095 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3096 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3097 | (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && |
| 3098 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3099 | DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) && |
| 3100 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 3101 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3102 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3103 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3104 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3105 | if (DVar.RefExpr == nullptr) |
| 3106 | DVar.CKind = PredeterminedCKind; |
| 3107 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3108 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3109 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3110 | // Make the loop iteration variable private (for worksharing constructs), |
| 3111 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3112 | // lastprivate (for simd directives with several collapsed or ordered |
| 3113 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3114 | if (DVar.CKind == OMPC_unknown) |
| 3115 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3116 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3117 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3120 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3121 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3122 | // Check test-expr. |
| 3123 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3124 | |
| 3125 | // Check incr-expr. |
| 3126 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3127 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3128 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3129 | return HasErrors; |
| 3130 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3131 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3132 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3133 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
| 3134 | DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3135 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3136 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3137 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3138 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3139 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3140 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3141 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3142 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3143 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3144 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3145 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3146 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3147 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3148 | ResultIterSpace.CounterInit == nullptr || |
| 3149 | ResultIterSpace.CounterStep == nullptr); |
| 3150 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3151 | return HasErrors; |
| 3152 | } |
| 3153 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3154 | /// \brief Build 'VarRef = Start. |
| 3155 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3156 | ExprResult VarRef, ExprResult Start) { |
| 3157 | TransformToNewDefs Transform(SemaRef); |
| 3158 | // Build 'VarRef = Start. |
| 3159 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3160 | if (NewStart.isInvalid()) |
| 3161 | return ExprError(); |
| 3162 | NewStart = SemaRef.PerformImplicitConversion( |
| 3163 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3164 | Sema::AA_Converting, |
| 3165 | /*AllowExplicit=*/true); |
| 3166 | if (NewStart.isInvalid()) |
| 3167 | return ExprError(); |
| 3168 | NewStart = SemaRef.PerformImplicitConversion( |
| 3169 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3170 | /*AllowExplicit=*/true); |
| 3171 | if (!NewStart.isUsable()) |
| 3172 | return ExprError(); |
| 3173 | |
| 3174 | auto Init = |
| 3175 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3176 | return Init; |
| 3177 | } |
| 3178 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3179 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3180 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3181 | SourceLocation Loc, ExprResult VarRef, |
| 3182 | ExprResult Start, ExprResult Iter, |
| 3183 | ExprResult Step, bool Subtract) { |
| 3184 | // Add parentheses (for debugging purposes only). |
| 3185 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3186 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3187 | !Step.isUsable()) |
| 3188 | return ExprError(); |
| 3189 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3190 | TransformToNewDefs Transform(SemaRef); |
| 3191 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3192 | if (NewStep.isInvalid()) |
| 3193 | return ExprError(); |
| 3194 | NewStep = SemaRef.PerformImplicitConversion( |
| 3195 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3196 | Sema::AA_Converting, |
| 3197 | /*AllowExplicit=*/true); |
| 3198 | if (NewStep.isInvalid()) |
| 3199 | return ExprError(); |
| 3200 | ExprResult Update = |
| 3201 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3202 | if (!Update.isUsable()) |
| 3203 | return ExprError(); |
| 3204 | |
| 3205 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3206 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3207 | if (NewStart.isInvalid()) |
| 3208 | return ExprError(); |
| 3209 | NewStart = SemaRef.PerformImplicitConversion( |
| 3210 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3211 | Sema::AA_Converting, |
| 3212 | /*AllowExplicit=*/true); |
| 3213 | if (NewStart.isInvalid()) |
| 3214 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3215 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3216 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3217 | if (!Update.isUsable()) |
| 3218 | return ExprError(); |
| 3219 | |
| 3220 | Update = SemaRef.PerformImplicitConversion( |
| 3221 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3222 | if (!Update.isUsable()) |
| 3223 | return ExprError(); |
| 3224 | |
| 3225 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3226 | return Update; |
| 3227 | } |
| 3228 | |
| 3229 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3230 | /// bits. |
| 3231 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3232 | Sema &SemaRef) { |
| 3233 | if (E == nullptr) |
| 3234 | return ExprError(); |
| 3235 | auto &C = SemaRef.Context; |
| 3236 | QualType OldType = E->getType(); |
| 3237 | unsigned HasBits = C.getTypeSize(OldType); |
| 3238 | if (HasBits >= Bits) |
| 3239 | return ExprResult(E); |
| 3240 | // OK to convert to signed, because new type has more bits than old. |
| 3241 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3242 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3243 | true); |
| 3244 | } |
| 3245 | |
| 3246 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3247 | /// into \a Bits bits. |
| 3248 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3249 | if (E == nullptr) |
| 3250 | return false; |
| 3251 | llvm::APSInt Result; |
| 3252 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3253 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3254 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | /// \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] | 3258 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3259 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3260 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3261 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3262 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3263 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3264 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3265 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3266 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3267 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3268 | // Found 'collapse' clause - calculate collapse number. |
| 3269 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3270 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 3271 | NestedLoopCount += Result.getLimitedValue() - 1; |
| 3272 | } |
| 3273 | if (OrderedLoopCountExpr) { |
| 3274 | // Found 'ordered' clause - calculate collapse number. |
| 3275 | llvm::APSInt Result; |
| 3276 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 3277 | NestedLoopCount += Result.getLimitedValue() - 1; |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3278 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3279 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3280 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3281 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3282 | IterSpaces.resize(NestedLoopCount); |
| 3283 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3284 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3285 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3286 | NestedLoopCount, CollapseLoopCountExpr, |
| 3287 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3288 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3289 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3290 | // 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] | 3291 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3292 | // All loops associated with the construct must be perfectly nested; that |
| 3293 | // is, there must be no intervening code nor any OpenMP directive between |
| 3294 | // any two loops. |
| 3295 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3298 | Built.clear(/* size */ NestedLoopCount); |
| 3299 | |
| 3300 | if (SemaRef.CurContext->isDependentContext()) |
| 3301 | return NestedLoopCount; |
| 3302 | |
| 3303 | // An example of what is generated for the following code: |
| 3304 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3305 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3306 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3307 | // for (k = 0; k < NK; ++k) |
| 3308 | // for (j = J0; j < NJ; j+=2) { |
| 3309 | // <loop body> |
| 3310 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3311 | // |
| 3312 | // We generate the code below. |
| 3313 | // Note: the loop body may be outlined in CodeGen. |
| 3314 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3315 | // iterations and operator+= to calculate counter value. |
| 3316 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3317 | // or i64 is currently supported). |
| 3318 | // |
| 3319 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3320 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3321 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3322 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3323 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3324 | // <loop body (using local i and j)> |
| 3325 | // } |
| 3326 | // i = NI; // assign final values of counters |
| 3327 | // j = NJ; |
| 3328 | // |
| 3329 | |
| 3330 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3331 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3332 | // Precondition tests if there is at least one iteration (all conditions are |
| 3333 | // true). |
| 3334 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3335 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3336 | ExprResult LastIteration32 = WidenIterationCount( |
| 3337 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3338 | N0->IgnoreImpCasts(), N0->getType(), |
| 3339 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3340 | .get(), |
| 3341 | SemaRef); |
| 3342 | ExprResult LastIteration64 = WidenIterationCount( |
| 3343 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3344 | N0->IgnoreImpCasts(), N0->getType(), |
| 3345 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3346 | .get(), |
| 3347 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3348 | |
| 3349 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3350 | return NestedLoopCount; |
| 3351 | |
| 3352 | auto &C = SemaRef.Context; |
| 3353 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3354 | |
| 3355 | Scope *CurScope = DSA.getCurScope(); |
| 3356 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3357 | if (PreCond.isUsable()) { |
| 3358 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3359 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3360 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3361 | auto N = IterSpaces[Cnt].NumIterations; |
| 3362 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3363 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3364 | LastIteration32 = SemaRef.BuildBinOp( |
| 3365 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3366 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3367 | Sema::AA_Converting, |
| 3368 | /*AllowExplicit=*/true) |
| 3369 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3370 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3371 | LastIteration64 = SemaRef.BuildBinOp( |
| 3372 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3373 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3374 | Sema::AA_Converting, |
| 3375 | /*AllowExplicit=*/true) |
| 3376 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | // Choose either the 32-bit or 64-bit version. |
| 3380 | ExprResult LastIteration = LastIteration64; |
| 3381 | if (LastIteration32.isUsable() && |
| 3382 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3383 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3384 | FitsInto( |
| 3385 | 32 /* Bits */, |
| 3386 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3387 | LastIteration64.get(), SemaRef))) |
| 3388 | LastIteration = LastIteration32; |
| 3389 | |
| 3390 | if (!LastIteration.isUsable()) |
| 3391 | return 0; |
| 3392 | |
| 3393 | // Save the number of iterations. |
| 3394 | ExprResult NumIterations = LastIteration; |
| 3395 | { |
| 3396 | LastIteration = SemaRef.BuildBinOp( |
| 3397 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3398 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3399 | if (!LastIteration.isUsable()) |
| 3400 | return 0; |
| 3401 | } |
| 3402 | |
| 3403 | // Calculate the last iteration number beforehand instead of doing this on |
| 3404 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3405 | llvm::APSInt Result; |
| 3406 | bool IsConstant = |
| 3407 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3408 | ExprResult CalcLastIteration; |
| 3409 | if (!IsConstant) { |
| 3410 | SourceLocation SaveLoc; |
| 3411 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3412 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3413 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3414 | ExprResult SaveRef = buildDeclRefExpr( |
| 3415 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3416 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3417 | SaveRef.get(), LastIteration.get()); |
| 3418 | LastIteration = SaveRef; |
| 3419 | |
| 3420 | // Prepare SaveRef + 1. |
| 3421 | NumIterations = SemaRef.BuildBinOp( |
| 3422 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3423 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3424 | if (!NumIterations.isUsable()) |
| 3425 | return 0; |
| 3426 | } |
| 3427 | |
| 3428 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3429 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3430 | QualType VType = LastIteration.get()->getType(); |
| 3431 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3432 | ExprResult LB, UB, IL, ST, EUB; |
| 3433 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3434 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3435 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3436 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3437 | SemaRef.AddInitializerToDecl( |
| 3438 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3439 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3440 | |
| 3441 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3442 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3443 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3444 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3445 | /*DirectInit*/ false, |
| 3446 | /*TypeMayContainAuto*/ false); |
| 3447 | |
| 3448 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3449 | // This will be used to implement clause 'lastprivate'. |
| 3450 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3451 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3452 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3453 | SemaRef.AddInitializerToDecl( |
| 3454 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3455 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3456 | |
| 3457 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3458 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3459 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3460 | SemaRef.AddInitializerToDecl( |
| 3461 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3462 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3463 | |
| 3464 | // Build expression: UB = min(UB, LastIteration) |
| 3465 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3466 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3467 | UB.get(), LastIteration.get()); |
| 3468 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3469 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3470 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3471 | CondOp.get()); |
| 3472 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3473 | } |
| 3474 | |
| 3475 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3476 | ExprResult IV; |
| 3477 | ExprResult Init; |
| 3478 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3479 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3480 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3481 | Expr *RHS = isOpenMPWorksharingDirective(DKind) |
| 3482 | ? LB.get() |
| 3483 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3484 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3485 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3486 | } |
| 3487 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3488 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3489 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3490 | ExprResult Cond = |
| 3491 | isOpenMPWorksharingDirective(DKind) |
| 3492 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3493 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3494 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3495 | |
| 3496 | // Loop increment (IV = IV + 1) |
| 3497 | SourceLocation IncLoc; |
| 3498 | ExprResult Inc = |
| 3499 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3500 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3501 | if (!Inc.isUsable()) |
| 3502 | return 0; |
| 3503 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3504 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3505 | if (!Inc.isUsable()) |
| 3506 | return 0; |
| 3507 | |
| 3508 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3509 | // Used for directives with static scheduling. |
| 3510 | ExprResult NextLB, NextUB; |
| 3511 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3512 | // LB + ST |
| 3513 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3514 | if (!NextLB.isUsable()) |
| 3515 | return 0; |
| 3516 | // LB = LB + ST |
| 3517 | NextLB = |
| 3518 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3519 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3520 | if (!NextLB.isUsable()) |
| 3521 | return 0; |
| 3522 | // UB + ST |
| 3523 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3524 | if (!NextUB.isUsable()) |
| 3525 | return 0; |
| 3526 | // UB = UB + ST |
| 3527 | NextUB = |
| 3528 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3529 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3530 | if (!NextUB.isUsable()) |
| 3531 | return 0; |
| 3532 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3533 | |
| 3534 | // Build updates and final values of the loop counters. |
| 3535 | bool HasErrors = false; |
| 3536 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3537 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3538 | Built.Updates.resize(NestedLoopCount); |
| 3539 | Built.Finals.resize(NestedLoopCount); |
| 3540 | { |
| 3541 | ExprResult Div; |
| 3542 | // Go from inner nested loop to outer. |
| 3543 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3544 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3545 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3546 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3547 | // where Div is product of previous iterations' IS.NumIters. |
| 3548 | ExprResult Iter; |
| 3549 | if (Div.isUsable()) { |
| 3550 | Iter = |
| 3551 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3552 | } else { |
| 3553 | Iter = IV; |
| 3554 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3555 | "unusable div expected on first iteration only"); |
| 3556 | } |
| 3557 | |
| 3558 | if (Cnt != 0 && Iter.isUsable()) |
| 3559 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3560 | IS.NumIterations); |
| 3561 | if (!Iter.isUsable()) { |
| 3562 | HasErrors = true; |
| 3563 | break; |
| 3564 | } |
| 3565 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3566 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3567 | auto *CounterVar = buildDeclRefExpr( |
| 3568 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3569 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3570 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3571 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3572 | IS.CounterInit); |
| 3573 | if (!Init.isUsable()) { |
| 3574 | HasErrors = true; |
| 3575 | break; |
| 3576 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3577 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3578 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3579 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3580 | if (!Update.isUsable()) { |
| 3581 | HasErrors = true; |
| 3582 | break; |
| 3583 | } |
| 3584 | |
| 3585 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3586 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3587 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3588 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3589 | if (!Final.isUsable()) { |
| 3590 | HasErrors = true; |
| 3591 | break; |
| 3592 | } |
| 3593 | |
| 3594 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3595 | if (Cnt != 0) { |
| 3596 | if (Div.isUnset()) |
| 3597 | Div = IS.NumIterations; |
| 3598 | else |
| 3599 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3600 | IS.NumIterations); |
| 3601 | |
| 3602 | // Add parentheses (for debugging purposes only). |
| 3603 | if (Div.isUsable()) |
| 3604 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3605 | if (!Div.isUsable()) { |
| 3606 | HasErrors = true; |
| 3607 | break; |
| 3608 | } |
| 3609 | } |
| 3610 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3611 | HasErrors = true; |
| 3612 | break; |
| 3613 | } |
| 3614 | // Save results |
| 3615 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3616 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3617 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3618 | Built.Updates[Cnt] = Update.get(); |
| 3619 | Built.Finals[Cnt] = Final.get(); |
| 3620 | } |
| 3621 | } |
| 3622 | |
| 3623 | if (HasErrors) |
| 3624 | return 0; |
| 3625 | |
| 3626 | // Save results |
| 3627 | Built.IterationVarRef = IV.get(); |
| 3628 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3629 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3630 | Built.CalcLastIteration = |
| 3631 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3632 | Built.PreCond = PreCond.get(); |
| 3633 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3634 | Built.Init = Init.get(); |
| 3635 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3636 | Built.LB = LB.get(); |
| 3637 | Built.UB = UB.get(); |
| 3638 | Built.IL = IL.get(); |
| 3639 | Built.ST = ST.get(); |
| 3640 | Built.EUB = EUB.get(); |
| 3641 | Built.NLB = NextLB.get(); |
| 3642 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3643 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3644 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3645 | } |
| 3646 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3647 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3648 | auto CollapseClauses = |
| 3649 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 3650 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 3651 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3652 | return nullptr; |
| 3653 | } |
| 3654 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3655 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3656 | auto OrderedClauses = |
| 3657 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 3658 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 3659 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3660 | return nullptr; |
| 3661 | } |
| 3662 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3663 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 3664 | const Expr *Safelen) { |
| 3665 | llvm::APSInt SimdlenRes, SafelenRes; |
| 3666 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 3667 | Simdlen->isInstantiationDependent() || |
| 3668 | Simdlen->containsUnexpandedParameterPack()) |
| 3669 | return false; |
| 3670 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 3671 | Safelen->isInstantiationDependent() || |
| 3672 | Safelen->containsUnexpandedParameterPack()) |
| 3673 | return false; |
| 3674 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 3675 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 3676 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3677 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3678 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3679 | if (SimdlenRes > SafelenRes) { |
| 3680 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 3681 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 3682 | return true; |
| 3683 | } |
| 3684 | return false; |
| 3685 | } |
| 3686 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3687 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3688 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3689 | SourceLocation EndLoc, |
| 3690 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3691 | if (!AStmt) |
| 3692 | return StmtError(); |
| 3693 | |
| 3694 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3695 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3696 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3697 | // define the nested loops number. |
| 3698 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3699 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3700 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3701 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3702 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3703 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3704 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3705 | "omp simd loop exprs were not built"); |
| 3706 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3707 | if (!CurContext->isDependentContext()) { |
| 3708 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3709 | for (auto C : Clauses) { |
| 3710 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3711 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3712 | B.NumIterations, *this, CurScope)) |
| 3713 | return StmtError(); |
| 3714 | } |
| 3715 | } |
| 3716 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3717 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3718 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3719 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3720 | OMPSafelenClause *Safelen = nullptr; |
| 3721 | OMPSimdlenClause *Simdlen = nullptr; |
| 3722 | for (auto *Clause : Clauses) { |
| 3723 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3724 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3725 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3726 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3727 | if (Safelen && Simdlen) |
| 3728 | break; |
| 3729 | } |
| 3730 | if (Simdlen && Safelen && |
| 3731 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3732 | Safelen->getSafelen())) |
| 3733 | return StmtError(); |
| 3734 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3735 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3736 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3737 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3738 | } |
| 3739 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3740 | StmtResult Sema::ActOnOpenMPForDirective( |
| 3741 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3742 | SourceLocation EndLoc, |
| 3743 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3744 | if (!AStmt) |
| 3745 | return StmtError(); |
| 3746 | |
| 3747 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3748 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3749 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3750 | // define the nested loops number. |
| 3751 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3752 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3753 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3754 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3755 | return StmtError(); |
| 3756 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3757 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3758 | "omp for loop exprs were not built"); |
| 3759 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 3760 | if (!CurContext->isDependentContext()) { |
| 3761 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3762 | for (auto C : Clauses) { |
| 3763 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3764 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3765 | B.NumIterations, *this, CurScope)) |
| 3766 | return StmtError(); |
| 3767 | } |
| 3768 | } |
| 3769 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3770 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3771 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3772 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3775 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 3776 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3777 | SourceLocation EndLoc, |
| 3778 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3779 | if (!AStmt) |
| 3780 | return StmtError(); |
| 3781 | |
| 3782 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3783 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3784 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3785 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3786 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3787 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 3788 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3789 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3790 | if (NestedLoopCount == 0) |
| 3791 | return StmtError(); |
| 3792 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3793 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3794 | "omp for simd loop exprs were not built"); |
| 3795 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 3796 | if (!CurContext->isDependentContext()) { |
| 3797 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3798 | for (auto C : Clauses) { |
| 3799 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3800 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3801 | B.NumIterations, *this, CurScope)) |
| 3802 | return StmtError(); |
| 3803 | } |
| 3804 | } |
| 3805 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3806 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3807 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3808 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3809 | OMPSafelenClause *Safelen = nullptr; |
| 3810 | OMPSimdlenClause *Simdlen = nullptr; |
| 3811 | for (auto *Clause : Clauses) { |
| 3812 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3813 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3814 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3815 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3816 | if (Safelen && Simdlen) |
| 3817 | break; |
| 3818 | } |
| 3819 | if (Simdlen && Safelen && |
| 3820 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3821 | Safelen->getSafelen())) |
| 3822 | return StmtError(); |
| 3823 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3824 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3825 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3826 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3827 | } |
| 3828 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3829 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3830 | Stmt *AStmt, |
| 3831 | SourceLocation StartLoc, |
| 3832 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3833 | if (!AStmt) |
| 3834 | return StmtError(); |
| 3835 | |
| 3836 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3837 | auto BaseStmt = AStmt; |
| 3838 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3839 | BaseStmt = CS->getCapturedStmt(); |
| 3840 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3841 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3842 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3843 | return StmtError(); |
| 3844 | // All associated statements must be '#pragma omp section' except for |
| 3845 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3846 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3847 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3848 | if (SectionStmt) |
| 3849 | Diag(SectionStmt->getLocStart(), |
| 3850 | diag::err_omp_sections_substmt_not_section); |
| 3851 | return StmtError(); |
| 3852 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3853 | cast<OMPSectionDirective>(SectionStmt) |
| 3854 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3855 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3856 | } else { |
| 3857 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 3858 | return StmtError(); |
| 3859 | } |
| 3860 | |
| 3861 | getCurFunction()->setHasBranchProtectedScope(); |
| 3862 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3863 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3864 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3865 | } |
| 3866 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3867 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 3868 | SourceLocation StartLoc, |
| 3869 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3870 | if (!AStmt) |
| 3871 | return StmtError(); |
| 3872 | |
| 3873 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3874 | |
| 3875 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3876 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3877 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3878 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 3879 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3880 | } |
| 3881 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3882 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 3883 | Stmt *AStmt, |
| 3884 | SourceLocation StartLoc, |
| 3885 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3886 | if (!AStmt) |
| 3887 | return StmtError(); |
| 3888 | |
| 3889 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3890 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3891 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3892 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 3893 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 3894 | // The copyprivate clause must not be used with the nowait clause. |
| 3895 | OMPClause *Nowait = nullptr; |
| 3896 | OMPClause *Copyprivate = nullptr; |
| 3897 | for (auto *Clause : Clauses) { |
| 3898 | if (Clause->getClauseKind() == OMPC_nowait) |
| 3899 | Nowait = Clause; |
| 3900 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 3901 | Copyprivate = Clause; |
| 3902 | if (Copyprivate && Nowait) { |
| 3903 | Diag(Copyprivate->getLocStart(), |
| 3904 | diag::err_omp_single_copyprivate_with_nowait); |
| 3905 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 3906 | return StmtError(); |
| 3907 | } |
| 3908 | } |
| 3909 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3910 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3911 | } |
| 3912 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3913 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 3914 | SourceLocation StartLoc, |
| 3915 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3916 | if (!AStmt) |
| 3917 | return StmtError(); |
| 3918 | |
| 3919 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3920 | |
| 3921 | getCurFunction()->setHasBranchProtectedScope(); |
| 3922 | |
| 3923 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3924 | } |
| 3925 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3926 | StmtResult |
| 3927 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 3928 | Stmt *AStmt, SourceLocation StartLoc, |
| 3929 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3930 | if (!AStmt) |
| 3931 | return StmtError(); |
| 3932 | |
| 3933 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3934 | |
| 3935 | getCurFunction()->setHasBranchProtectedScope(); |
| 3936 | |
| 3937 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 3938 | AStmt); |
| 3939 | } |
| 3940 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3941 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 3942 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3943 | SourceLocation EndLoc, |
| 3944 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3945 | if (!AStmt) |
| 3946 | return StmtError(); |
| 3947 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3948 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3949 | // 1.2.2 OpenMP Language Terminology |
| 3950 | // Structured block - An executable statement with a single entry at the |
| 3951 | // top and a single exit at the bottom. |
| 3952 | // The point of exit cannot be a branch out of the structured block. |
| 3953 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3954 | CS->getCapturedDecl()->setNothrow(); |
| 3955 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3956 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3957 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3958 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3959 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3960 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 3961 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3962 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3963 | if (NestedLoopCount == 0) |
| 3964 | return StmtError(); |
| 3965 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3966 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3967 | "omp parallel for loop exprs were not built"); |
| 3968 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 3969 | if (!CurContext->isDependentContext()) { |
| 3970 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3971 | for (auto C : Clauses) { |
| 3972 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3973 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3974 | B.NumIterations, *this, CurScope)) |
| 3975 | return StmtError(); |
| 3976 | } |
| 3977 | } |
| 3978 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3979 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3980 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3981 | NestedLoopCount, Clauses, AStmt, B, |
| 3982 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3983 | } |
| 3984 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3985 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 3986 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3987 | SourceLocation EndLoc, |
| 3988 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3989 | if (!AStmt) |
| 3990 | return StmtError(); |
| 3991 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3992 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3993 | // 1.2.2 OpenMP Language Terminology |
| 3994 | // Structured block - An executable statement with a single entry at the |
| 3995 | // top and a single exit at the bottom. |
| 3996 | // The point of exit cannot be a branch out of the structured block. |
| 3997 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3998 | CS->getCapturedDecl()->setNothrow(); |
| 3999 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4000 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4001 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4002 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4003 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4004 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4005 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4006 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4007 | if (NestedLoopCount == 0) |
| 4008 | return StmtError(); |
| 4009 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4010 | if (!CurContext->isDependentContext()) { |
| 4011 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4012 | for (auto C : Clauses) { |
| 4013 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4014 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4015 | B.NumIterations, *this, CurScope)) |
| 4016 | return StmtError(); |
| 4017 | } |
| 4018 | } |
| 4019 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4020 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4021 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4022 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4023 | OMPSafelenClause *Safelen = nullptr; |
| 4024 | OMPSimdlenClause *Simdlen = nullptr; |
| 4025 | for (auto *Clause : Clauses) { |
| 4026 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4027 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4028 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4029 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4030 | if (Safelen && Simdlen) |
| 4031 | break; |
| 4032 | } |
| 4033 | if (Simdlen && Safelen && |
| 4034 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4035 | Safelen->getSafelen())) |
| 4036 | return StmtError(); |
| 4037 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4038 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4039 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4040 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4041 | } |
| 4042 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4043 | StmtResult |
| 4044 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4045 | Stmt *AStmt, SourceLocation StartLoc, |
| 4046 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4047 | if (!AStmt) |
| 4048 | return StmtError(); |
| 4049 | |
| 4050 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4051 | auto BaseStmt = AStmt; |
| 4052 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4053 | BaseStmt = CS->getCapturedStmt(); |
| 4054 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4055 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4056 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4057 | return StmtError(); |
| 4058 | // All associated statements must be '#pragma omp section' except for |
| 4059 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4060 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4061 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4062 | if (SectionStmt) |
| 4063 | Diag(SectionStmt->getLocStart(), |
| 4064 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4065 | return StmtError(); |
| 4066 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4067 | cast<OMPSectionDirective>(SectionStmt) |
| 4068 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4069 | } |
| 4070 | } else { |
| 4071 | Diag(AStmt->getLocStart(), |
| 4072 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4073 | return StmtError(); |
| 4074 | } |
| 4075 | |
| 4076 | getCurFunction()->setHasBranchProtectedScope(); |
| 4077 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4078 | return OMPParallelSectionsDirective::Create( |
| 4079 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4080 | } |
| 4081 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4082 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4083 | Stmt *AStmt, SourceLocation StartLoc, |
| 4084 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4085 | if (!AStmt) |
| 4086 | return StmtError(); |
| 4087 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4088 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4089 | // 1.2.2 OpenMP Language Terminology |
| 4090 | // Structured block - An executable statement with a single entry at the |
| 4091 | // top and a single exit at the bottom. |
| 4092 | // The point of exit cannot be a branch out of the structured block. |
| 4093 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4094 | CS->getCapturedDecl()->setNothrow(); |
| 4095 | |
| 4096 | getCurFunction()->setHasBranchProtectedScope(); |
| 4097 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4098 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4099 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4102 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4103 | SourceLocation EndLoc) { |
| 4104 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4105 | } |
| 4106 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4107 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4108 | SourceLocation EndLoc) { |
| 4109 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4110 | } |
| 4111 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4112 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4113 | SourceLocation EndLoc) { |
| 4114 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4115 | } |
| 4116 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4117 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4118 | SourceLocation StartLoc, |
| 4119 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4120 | if (!AStmt) |
| 4121 | return StmtError(); |
| 4122 | |
| 4123 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4124 | |
| 4125 | getCurFunction()->setHasBranchProtectedScope(); |
| 4126 | |
| 4127 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4128 | } |
| 4129 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4130 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4131 | SourceLocation StartLoc, |
| 4132 | SourceLocation EndLoc) { |
| 4133 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4134 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4135 | } |
| 4136 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4137 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4138 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4139 | SourceLocation StartLoc, |
| 4140 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4141 | if (!AStmt) |
| 4142 | return StmtError(); |
| 4143 | |
| 4144 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4145 | |
| 4146 | getCurFunction()->setHasBranchProtectedScope(); |
| 4147 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4148 | OMPThreadsClause *TC = nullptr; |
| 4149 | for (auto *C: Clauses) { |
| 4150 | if (C->getClauseKind() == OMPC_threads) |
| 4151 | TC = cast<OMPThreadsClause>(C); |
| 4152 | } |
| 4153 | |
| 4154 | // TODO: this must happen only if 'threads' clause specified or if no clauses |
| 4155 | // is specified. |
| 4156 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4157 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4158 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) << (TC != nullptr); |
| 4159 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4160 | return StmtError(); |
| 4161 | } |
| 4162 | |
| 4163 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4164 | } |
| 4165 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4166 | namespace { |
| 4167 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4168 | /// construct. |
| 4169 | class OpenMPAtomicUpdateChecker { |
| 4170 | /// \brief Error results for atomic update expressions. |
| 4171 | enum ExprAnalysisErrorCode { |
| 4172 | /// \brief A statement is not an expression statement. |
| 4173 | NotAnExpression, |
| 4174 | /// \brief Expression is not builtin binary or unary operation. |
| 4175 | NotABinaryOrUnaryExpression, |
| 4176 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4177 | NotAnUnaryIncDecExpression, |
| 4178 | /// \brief An expression is not of scalar type. |
| 4179 | NotAScalarType, |
| 4180 | /// \brief A binary operation is not an assignment operation. |
| 4181 | NotAnAssignmentOp, |
| 4182 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4183 | NotABinaryExpression, |
| 4184 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4185 | /// expression. |
| 4186 | NotABinaryOperator, |
| 4187 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4188 | /// part. |
| 4189 | NotAnUpdateExpression, |
| 4190 | /// \brief No errors is found. |
| 4191 | NoError |
| 4192 | }; |
| 4193 | /// \brief Reference to Sema. |
| 4194 | Sema &SemaRef; |
| 4195 | /// \brief A location for note diagnostics (when error is found). |
| 4196 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4197 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4198 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4199 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4200 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4201 | /// \brief Helper expression of the form |
| 4202 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4203 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4204 | Expr *UpdateExpr; |
| 4205 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4206 | /// important for non-associative operations. |
| 4207 | bool IsXLHSInRHSPart; |
| 4208 | BinaryOperatorKind Op; |
| 4209 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4210 | /// \brief true if the source expression is a postfix unary operation, false |
| 4211 | /// if it is a prefix unary operation. |
| 4212 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4213 | |
| 4214 | public: |
| 4215 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4216 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4217 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4218 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4219 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4220 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4221 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4222 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4223 | /// \param NoteId Diagnostic note for the main error message. |
| 4224 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4225 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4226 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4227 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4228 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4229 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4230 | /// \brief Return the update expression used in calculation of the updated |
| 4231 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4232 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4233 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4234 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4235 | /// false otherwise. |
| 4236 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4237 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4238 | /// \brief true if the source expression is a postfix unary operation, false |
| 4239 | /// if it is a prefix unary operation. |
| 4240 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4241 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4242 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4243 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4244 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4245 | }; |
| 4246 | } // namespace |
| 4247 | |
| 4248 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4249 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4250 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4251 | SourceLocation ErrorLoc, NoteLoc; |
| 4252 | SourceRange ErrorRange, NoteRange; |
| 4253 | // Allowed constructs are: |
| 4254 | // x = x binop expr; |
| 4255 | // x = expr binop x; |
| 4256 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4257 | X = AtomicBinOp->getLHS(); |
| 4258 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4259 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4260 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4261 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4262 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4263 | Op = AtomicInnerBinOp->getOpcode(); |
| 4264 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4265 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4266 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4267 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4268 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4269 | /*Canonical=*/true); |
| 4270 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4271 | /*Canonical=*/true); |
| 4272 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4273 | /*Canonical=*/true); |
| 4274 | if (XId == LHSId) { |
| 4275 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4276 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4277 | } else if (XId == RHSId) { |
| 4278 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4279 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4280 | } else { |
| 4281 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4282 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4283 | NoteLoc = X->getExprLoc(); |
| 4284 | NoteRange = X->getSourceRange(); |
| 4285 | ErrorFound = NotAnUpdateExpression; |
| 4286 | } |
| 4287 | } else { |
| 4288 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4289 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4290 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4291 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4292 | ErrorFound = NotABinaryOperator; |
| 4293 | } |
| 4294 | } else { |
| 4295 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4296 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4297 | ErrorFound = NotABinaryExpression; |
| 4298 | } |
| 4299 | } else { |
| 4300 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4301 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4302 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4303 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4304 | ErrorFound = NotAnAssignmentOp; |
| 4305 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4306 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4307 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4308 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4309 | return true; |
| 4310 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4311 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4312 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4316 | unsigned NoteId) { |
| 4317 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4318 | SourceLocation ErrorLoc, NoteLoc; |
| 4319 | SourceRange ErrorRange, NoteRange; |
| 4320 | // Allowed constructs are: |
| 4321 | // x++; |
| 4322 | // x--; |
| 4323 | // ++x; |
| 4324 | // --x; |
| 4325 | // x binop= expr; |
| 4326 | // x = x binop expr; |
| 4327 | // x = expr binop x; |
| 4328 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4329 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4330 | if (AtomicBody->getType()->isScalarType() || |
| 4331 | AtomicBody->isInstantiationDependent()) { |
| 4332 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4333 | AtomicBody->IgnoreParenImpCasts())) { |
| 4334 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4335 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4336 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4337 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4338 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4339 | X = AtomicCompAssignOp->getLHS(); |
| 4340 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4341 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4342 | AtomicBody->IgnoreParenImpCasts())) { |
| 4343 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4344 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4345 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4346 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4347 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4348 | // Check for Unary Operation |
| 4349 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4350 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4351 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4352 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4353 | X = AtomicUnaryOp->getSubExpr(); |
| 4354 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4355 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4356 | } else { |
| 4357 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4358 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4359 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4360 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4361 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4362 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4363 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4364 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4365 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4366 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4367 | } |
| 4368 | } else { |
| 4369 | ErrorFound = NotAScalarType; |
| 4370 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4371 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4372 | } |
| 4373 | } else { |
| 4374 | ErrorFound = NotAnExpression; |
| 4375 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4376 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4377 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4378 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4379 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4380 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4381 | return true; |
| 4382 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4383 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4384 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4385 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4386 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4387 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4388 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4389 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4390 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4391 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4392 | auto Update = |
| 4393 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4394 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4395 | if (Update.isInvalid()) |
| 4396 | return true; |
| 4397 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4398 | Sema::AA_Casting); |
| 4399 | if (Update.isInvalid()) |
| 4400 | return true; |
| 4401 | UpdateExpr = Update.get(); |
| 4402 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4403 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4404 | } |
| 4405 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4406 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4407 | Stmt *AStmt, |
| 4408 | SourceLocation StartLoc, |
| 4409 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4410 | if (!AStmt) |
| 4411 | return StmtError(); |
| 4412 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4413 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4414 | // 1.2.2 OpenMP Language Terminology |
| 4415 | // Structured block - An executable statement with a single entry at the |
| 4416 | // top and a single exit at the bottom. |
| 4417 | // The point of exit cannot be a branch out of the structured block. |
| 4418 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4419 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4420 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4421 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4422 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4423 | C->getClauseKind() == OMPC_update || |
| 4424 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4425 | if (AtomicKind != OMPC_unknown) { |
| 4426 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4427 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4428 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4429 | << getOpenMPClauseName(AtomicKind); |
| 4430 | } else { |
| 4431 | AtomicKind = C->getClauseKind(); |
| 4432 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4433 | } |
| 4434 | } |
| 4435 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4436 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4437 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4438 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4439 | Body = EWC->getSubExpr(); |
| 4440 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4441 | Expr *X = nullptr; |
| 4442 | Expr *V = nullptr; |
| 4443 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4444 | Expr *UE = nullptr; |
| 4445 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4446 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4447 | // OpenMP [2.12.6, atomic Construct] |
| 4448 | // In the next expressions: |
| 4449 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4450 | // * During the execution of an atomic region, multiple syntactic |
| 4451 | // occurrences of x must designate the same storage location. |
| 4452 | // * Neither of v and expr (as applicable) may access the storage location |
| 4453 | // designated by x. |
| 4454 | // * Neither of x and expr (as applicable) may access the storage location |
| 4455 | // designated by v. |
| 4456 | // * expr is an expression with scalar type. |
| 4457 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4458 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4459 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4460 | // (expr). This requirement is satisfied if the operators in expr have |
| 4461 | // precedence greater than binop, or by using parentheses around expr or |
| 4462 | // subexpressions of expr. |
| 4463 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4464 | // binop x. This requirement is satisfied if the operators in expr have |
| 4465 | // precedence equal to or greater than binop, or by using parentheses around |
| 4466 | // expr or subexpressions of expr. |
| 4467 | // * For forms that allow multiple occurrences of x, the number of times |
| 4468 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4469 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4470 | enum { |
| 4471 | NotAnExpression, |
| 4472 | NotAnAssignmentOp, |
| 4473 | NotAScalarType, |
| 4474 | NotAnLValue, |
| 4475 | NoError |
| 4476 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4477 | SourceLocation ErrorLoc, NoteLoc; |
| 4478 | SourceRange ErrorRange, NoteRange; |
| 4479 | // If clause is read: |
| 4480 | // v = x; |
| 4481 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4482 | auto AtomicBinOp = |
| 4483 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4484 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4485 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4486 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4487 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4488 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4489 | if (!X->isLValue() || !V->isLValue()) { |
| 4490 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4491 | ErrorFound = NotAnLValue; |
| 4492 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4493 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4494 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4495 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4496 | } |
| 4497 | } else if (!X->isInstantiationDependent() || |
| 4498 | !V->isInstantiationDependent()) { |
| 4499 | auto NotScalarExpr = |
| 4500 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4501 | ? V |
| 4502 | : X; |
| 4503 | ErrorFound = NotAScalarType; |
| 4504 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4505 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4506 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4507 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4508 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4509 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4510 | ErrorFound = NotAnAssignmentOp; |
| 4511 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4512 | ErrorRange = AtomicBody->getSourceRange(); |
| 4513 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4514 | : AtomicBody->getExprLoc(); |
| 4515 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4516 | : AtomicBody->getSourceRange(); |
| 4517 | } |
| 4518 | } else { |
| 4519 | ErrorFound = NotAnExpression; |
| 4520 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4521 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4522 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4523 | if (ErrorFound != NoError) { |
| 4524 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4525 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4526 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4527 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4528 | return StmtError(); |
| 4529 | } else if (CurContext->isDependentContext()) |
| 4530 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4531 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4532 | enum { |
| 4533 | NotAnExpression, |
| 4534 | NotAnAssignmentOp, |
| 4535 | NotAScalarType, |
| 4536 | NotAnLValue, |
| 4537 | NoError |
| 4538 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4539 | SourceLocation ErrorLoc, NoteLoc; |
| 4540 | SourceRange ErrorRange, NoteRange; |
| 4541 | // If clause is write: |
| 4542 | // x = expr; |
| 4543 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4544 | auto AtomicBinOp = |
| 4545 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4546 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4547 | X = AtomicBinOp->getLHS(); |
| 4548 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4549 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4550 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4551 | if (!X->isLValue()) { |
| 4552 | ErrorFound = NotAnLValue; |
| 4553 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4554 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4555 | NoteLoc = X->getExprLoc(); |
| 4556 | NoteRange = X->getSourceRange(); |
| 4557 | } |
| 4558 | } else if (!X->isInstantiationDependent() || |
| 4559 | !E->isInstantiationDependent()) { |
| 4560 | auto NotScalarExpr = |
| 4561 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4562 | ? E |
| 4563 | : X; |
| 4564 | ErrorFound = NotAScalarType; |
| 4565 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4566 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4567 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4568 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4569 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4570 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4571 | ErrorFound = NotAnAssignmentOp; |
| 4572 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4573 | ErrorRange = AtomicBody->getSourceRange(); |
| 4574 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4575 | : AtomicBody->getExprLoc(); |
| 4576 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4577 | : AtomicBody->getSourceRange(); |
| 4578 | } |
| 4579 | } else { |
| 4580 | ErrorFound = NotAnExpression; |
| 4581 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4582 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4583 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4584 | if (ErrorFound != NoError) { |
| 4585 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4586 | << ErrorRange; |
| 4587 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4588 | << NoteRange; |
| 4589 | return StmtError(); |
| 4590 | } else if (CurContext->isDependentContext()) |
| 4591 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4592 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4593 | // If clause is update: |
| 4594 | // x++; |
| 4595 | // x--; |
| 4596 | // ++x; |
| 4597 | // --x; |
| 4598 | // x binop= expr; |
| 4599 | // x = x binop expr; |
| 4600 | // x = expr binop x; |
| 4601 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4602 | if (Checker.checkStatement( |
| 4603 | Body, (AtomicKind == OMPC_update) |
| 4604 | ? diag::err_omp_atomic_update_not_expression_statement |
| 4605 | : diag::err_omp_atomic_not_expression_statement, |
| 4606 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4607 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4608 | if (!CurContext->isDependentContext()) { |
| 4609 | E = Checker.getExpr(); |
| 4610 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4611 | UE = Checker.getUpdateExpr(); |
| 4612 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4613 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4614 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4615 | enum { |
| 4616 | NotAnAssignmentOp, |
| 4617 | NotACompoundStatement, |
| 4618 | NotTwoSubstatements, |
| 4619 | NotASpecificExpression, |
| 4620 | NoError |
| 4621 | } ErrorFound = NoError; |
| 4622 | SourceLocation ErrorLoc, NoteLoc; |
| 4623 | SourceRange ErrorRange, NoteRange; |
| 4624 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 4625 | // If clause is a capture: |
| 4626 | // v = x++; |
| 4627 | // v = x--; |
| 4628 | // v = ++x; |
| 4629 | // v = --x; |
| 4630 | // v = x binop= expr; |
| 4631 | // v = x = x binop expr; |
| 4632 | // v = x = expr binop x; |
| 4633 | auto *AtomicBinOp = |
| 4634 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4635 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4636 | V = AtomicBinOp->getLHS(); |
| 4637 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4638 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4639 | if (Checker.checkStatement( |
| 4640 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 4641 | diag::note_omp_atomic_update)) |
| 4642 | return StmtError(); |
| 4643 | E = Checker.getExpr(); |
| 4644 | X = Checker.getX(); |
| 4645 | UE = Checker.getUpdateExpr(); |
| 4646 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 4647 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4648 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4649 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4650 | ErrorRange = AtomicBody->getSourceRange(); |
| 4651 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4652 | : AtomicBody->getExprLoc(); |
| 4653 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4654 | : AtomicBody->getSourceRange(); |
| 4655 | ErrorFound = NotAnAssignmentOp; |
| 4656 | } |
| 4657 | if (ErrorFound != NoError) { |
| 4658 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 4659 | << ErrorRange; |
| 4660 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4661 | return StmtError(); |
| 4662 | } else if (CurContext->isDependentContext()) { |
| 4663 | UE = V = E = X = nullptr; |
| 4664 | } |
| 4665 | } else { |
| 4666 | // If clause is a capture: |
| 4667 | // { v = x; x = expr; } |
| 4668 | // { v = x; x++; } |
| 4669 | // { v = x; x--; } |
| 4670 | // { v = x; ++x; } |
| 4671 | // { v = x; --x; } |
| 4672 | // { v = x; x binop= expr; } |
| 4673 | // { v = x; x = x binop expr; } |
| 4674 | // { v = x; x = expr binop x; } |
| 4675 | // { x++; v = x; } |
| 4676 | // { x--; v = x; } |
| 4677 | // { ++x; v = x; } |
| 4678 | // { --x; v = x; } |
| 4679 | // { x binop= expr; v = x; } |
| 4680 | // { x = x binop expr; v = x; } |
| 4681 | // { x = expr binop x; v = x; } |
| 4682 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 4683 | // Check that this is { expr1; expr2; } |
| 4684 | if (CS->size() == 2) { |
| 4685 | auto *First = CS->body_front(); |
| 4686 | auto *Second = CS->body_back(); |
| 4687 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 4688 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4689 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 4690 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4691 | // Need to find what subexpression is 'v' and what is 'x'. |
| 4692 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4693 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 4694 | BinaryOperator *BinOp = nullptr; |
| 4695 | if (IsUpdateExprFound) { |
| 4696 | BinOp = dyn_cast<BinaryOperator>(First); |
| 4697 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4698 | } |
| 4699 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4700 | // { v = x; x++; } |
| 4701 | // { v = x; x--; } |
| 4702 | // { v = x; ++x; } |
| 4703 | // { v = x; --x; } |
| 4704 | // { v = x; x binop= expr; } |
| 4705 | // { v = x; x = x binop expr; } |
| 4706 | // { v = x; x = expr binop x; } |
| 4707 | // Check that the first expression has form v = x. |
| 4708 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4709 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4710 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4711 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4712 | IsUpdateExprFound = XId == PossibleXId; |
| 4713 | if (IsUpdateExprFound) { |
| 4714 | V = BinOp->getLHS(); |
| 4715 | X = Checker.getX(); |
| 4716 | E = Checker.getExpr(); |
| 4717 | UE = Checker.getUpdateExpr(); |
| 4718 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4719 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4720 | } |
| 4721 | } |
| 4722 | if (!IsUpdateExprFound) { |
| 4723 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 4724 | BinOp = nullptr; |
| 4725 | if (IsUpdateExprFound) { |
| 4726 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 4727 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4728 | } |
| 4729 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4730 | // { x++; v = x; } |
| 4731 | // { x--; v = x; } |
| 4732 | // { ++x; v = x; } |
| 4733 | // { --x; v = x; } |
| 4734 | // { x binop= expr; v = x; } |
| 4735 | // { x = x binop expr; v = x; } |
| 4736 | // { x = expr binop x; v = x; } |
| 4737 | // Check that the second expression has form v = x. |
| 4738 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4739 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4740 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4741 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4742 | IsUpdateExprFound = XId == PossibleXId; |
| 4743 | if (IsUpdateExprFound) { |
| 4744 | V = BinOp->getLHS(); |
| 4745 | X = Checker.getX(); |
| 4746 | E = Checker.getExpr(); |
| 4747 | UE = Checker.getUpdateExpr(); |
| 4748 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4749 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4750 | } |
| 4751 | } |
| 4752 | } |
| 4753 | if (!IsUpdateExprFound) { |
| 4754 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4755 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 4756 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 4757 | if (!FirstExpr || !SecondExpr || |
| 4758 | !(FirstExpr->isInstantiationDependent() || |
| 4759 | SecondExpr->isInstantiationDependent())) { |
| 4760 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 4761 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4762 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4763 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 4764 | : First->getLocStart(); |
| 4765 | NoteRange = ErrorRange = FirstBinOp |
| 4766 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4767 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4768 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4769 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 4770 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 4771 | ErrorFound = NotAnAssignmentOp; |
| 4772 | NoteLoc = ErrorLoc = SecondBinOp |
| 4773 | ? SecondBinOp->getOperatorLoc() |
| 4774 | : Second->getLocStart(); |
| 4775 | NoteRange = ErrorRange = |
| 4776 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 4777 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4778 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4779 | auto *PossibleXRHSInFirst = |
| 4780 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4781 | auto *PossibleXLHSInSecond = |
| 4782 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4783 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 4784 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 4785 | /*Canonical=*/true); |
| 4786 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 4787 | /*Canonical=*/true); |
| 4788 | IsUpdateExprFound = X1Id == X2Id; |
| 4789 | if (IsUpdateExprFound) { |
| 4790 | V = FirstBinOp->getLHS(); |
| 4791 | X = SecondBinOp->getLHS(); |
| 4792 | E = SecondBinOp->getRHS(); |
| 4793 | UE = nullptr; |
| 4794 | IsXLHSInRHSPart = false; |
| 4795 | IsPostfixUpdate = true; |
| 4796 | } else { |
| 4797 | ErrorFound = NotASpecificExpression; |
| 4798 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 4799 | ErrorRange = FirstBinOp->getSourceRange(); |
| 4800 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 4801 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 4802 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4803 | } |
| 4804 | } |
| 4805 | } |
| 4806 | } |
| 4807 | } else { |
| 4808 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4809 | NoteRange = ErrorRange = |
| 4810 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4811 | ErrorFound = NotTwoSubstatements; |
| 4812 | } |
| 4813 | } else { |
| 4814 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4815 | NoteRange = ErrorRange = |
| 4816 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4817 | ErrorFound = NotACompoundStatement; |
| 4818 | } |
| 4819 | if (ErrorFound != NoError) { |
| 4820 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 4821 | << ErrorRange; |
| 4822 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4823 | return StmtError(); |
| 4824 | } else if (CurContext->isDependentContext()) { |
| 4825 | UE = V = E = X = nullptr; |
| 4826 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4827 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4828 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4829 | |
| 4830 | getCurFunction()->setHasBranchProtectedScope(); |
| 4831 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4832 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4833 | X, V, E, UE, IsXLHSInRHSPart, |
| 4834 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4835 | } |
| 4836 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4837 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 4838 | Stmt *AStmt, |
| 4839 | SourceLocation StartLoc, |
| 4840 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4841 | if (!AStmt) |
| 4842 | return StmtError(); |
| 4843 | |
| 4844 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4845 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4846 | // OpenMP [2.16, Nesting of Regions] |
| 4847 | // If specified, a teams construct must be contained within a target |
| 4848 | // construct. That target construct must contain no statements or directives |
| 4849 | // outside of the teams construct. |
| 4850 | if (DSAStack->hasInnerTeamsRegion()) { |
| 4851 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 4852 | bool OMPTeamsFound = true; |
| 4853 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 4854 | auto I = CS->body_begin(); |
| 4855 | while (I != CS->body_end()) { |
| 4856 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 4857 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 4858 | OMPTeamsFound = false; |
| 4859 | break; |
| 4860 | } |
| 4861 | ++I; |
| 4862 | } |
| 4863 | assert(I != CS->body_end() && "Not found statement"); |
| 4864 | S = *I; |
| 4865 | } |
| 4866 | if (!OMPTeamsFound) { |
| 4867 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 4868 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 4869 | diag::note_omp_nested_teams_construct_here); |
| 4870 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 4871 | << isa<OMPExecutableDirective>(S); |
| 4872 | return StmtError(); |
| 4873 | } |
| 4874 | } |
| 4875 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4876 | getCurFunction()->setHasBranchProtectedScope(); |
| 4877 | |
| 4878 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4879 | } |
| 4880 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4881 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 4882 | Stmt *AStmt, |
| 4883 | SourceLocation StartLoc, |
| 4884 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4885 | if (!AStmt) |
| 4886 | return StmtError(); |
| 4887 | |
| 4888 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4889 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4890 | getCurFunction()->setHasBranchProtectedScope(); |
| 4891 | |
| 4892 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 4893 | AStmt); |
| 4894 | } |
| 4895 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4896 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 4897 | Stmt *AStmt, SourceLocation StartLoc, |
| 4898 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4899 | if (!AStmt) |
| 4900 | return StmtError(); |
| 4901 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4902 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4903 | // 1.2.2 OpenMP Language Terminology |
| 4904 | // Structured block - An executable statement with a single entry at the |
| 4905 | // top and a single exit at the bottom. |
| 4906 | // The point of exit cannot be a branch out of the structured block. |
| 4907 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4908 | CS->getCapturedDecl()->setNothrow(); |
| 4909 | |
| 4910 | getCurFunction()->setHasBranchProtectedScope(); |
| 4911 | |
| 4912 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4913 | } |
| 4914 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4915 | StmtResult |
| 4916 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 4917 | SourceLocation EndLoc, |
| 4918 | OpenMPDirectiveKind CancelRegion) { |
| 4919 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4920 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4921 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4922 | << getOpenMPDirectiveName(CancelRegion); |
| 4923 | return StmtError(); |
| 4924 | } |
| 4925 | if (DSAStack->isParentNowaitRegion()) { |
| 4926 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 4927 | return StmtError(); |
| 4928 | } |
| 4929 | if (DSAStack->isParentOrderedRegion()) { |
| 4930 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 4931 | return StmtError(); |
| 4932 | } |
| 4933 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 4934 | CancelRegion); |
| 4935 | } |
| 4936 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 4937 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 4938 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4939 | SourceLocation EndLoc, |
| 4940 | OpenMPDirectiveKind CancelRegion) { |
| 4941 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4942 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4943 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4944 | << getOpenMPDirectiveName(CancelRegion); |
| 4945 | return StmtError(); |
| 4946 | } |
| 4947 | if (DSAStack->isParentNowaitRegion()) { |
| 4948 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 4949 | return StmtError(); |
| 4950 | } |
| 4951 | if (DSAStack->isParentOrderedRegion()) { |
| 4952 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 4953 | return StmtError(); |
| 4954 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4955 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 4956 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 4957 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4958 | } |
| 4959 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4960 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4961 | SourceLocation StartLoc, |
| 4962 | SourceLocation LParenLoc, |
| 4963 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4964 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4965 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4966 | case OMPC_final: |
| 4967 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4968 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4969 | case OMPC_num_threads: |
| 4970 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4971 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4972 | case OMPC_safelen: |
| 4973 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4974 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4975 | case OMPC_simdlen: |
| 4976 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4977 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4978 | case OMPC_collapse: |
| 4979 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4980 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4981 | case OMPC_ordered: |
| 4982 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 4983 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 4984 | case OMPC_device: |
| 4985 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4986 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4987 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4988 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4989 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4990 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4991 | case OMPC_private: |
| 4992 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4993 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4994 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4995 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4996 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4997 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4998 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4999 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5000 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5001 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5002 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5003 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5004 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5005 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5006 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5007 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5008 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5009 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5010 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5011 | case OMPC_threads: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5012 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5013 | llvm_unreachable("Clause is not allowed."); |
| 5014 | } |
| 5015 | return Res; |
| 5016 | } |
| 5017 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5018 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5019 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5020 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5021 | SourceLocation NameModifierLoc, |
| 5022 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5023 | SourceLocation EndLoc) { |
| 5024 | Expr *ValExpr = Condition; |
| 5025 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5026 | !Condition->isInstantiationDependent() && |
| 5027 | !Condition->containsUnexpandedParameterPack()) { |
| 5028 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5029 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5030 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5031 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5032 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5033 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5034 | } |
| 5035 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5036 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5037 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5040 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5041 | SourceLocation StartLoc, |
| 5042 | SourceLocation LParenLoc, |
| 5043 | SourceLocation EndLoc) { |
| 5044 | Expr *ValExpr = Condition; |
| 5045 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5046 | !Condition->isInstantiationDependent() && |
| 5047 | !Condition->containsUnexpandedParameterPack()) { |
| 5048 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5049 | Condition->getExprLoc(), Condition); |
| 5050 | if (Val.isInvalid()) |
| 5051 | return nullptr; |
| 5052 | |
| 5053 | ValExpr = Val.get(); |
| 5054 | } |
| 5055 | |
| 5056 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5057 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5058 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5059 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5060 | if (!Op) |
| 5061 | return ExprError(); |
| 5062 | |
| 5063 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5064 | public: |
| 5065 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5066 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5067 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5068 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5069 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5070 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5071 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5072 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5073 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5074 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5075 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5076 | QualType T, |
| 5077 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5078 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5079 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5080 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5081 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5082 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5083 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5084 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5085 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5086 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5087 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5088 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5089 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5090 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5091 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5092 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5093 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5094 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5095 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5096 | llvm_unreachable("conversion functions are permitted"); |
| 5097 | } |
| 5098 | } ConvertDiagnoser; |
| 5099 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5100 | } |
| 5101 | |
| 5102 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5103 | SourceLocation StartLoc, |
| 5104 | SourceLocation LParenLoc, |
| 5105 | SourceLocation EndLoc) { |
| 5106 | Expr *ValExpr = NumThreads; |
| 5107 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5108 | !NumThreads->containsUnexpandedParameterPack()) { |
| 5109 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 5110 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5111 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5112 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5113 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5114 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5115 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5116 | |
| 5117 | // OpenMP [2.5, Restrictions] |
| 5118 | // The num_threads expression must evaluate to a positive integer value. |
| 5119 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5120 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 5121 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5122 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 5123 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5124 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5125 | } |
| 5126 | } |
| 5127 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5128 | return new (Context) |
| 5129 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5130 | } |
| 5131 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5132 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 5133 | OpenMPClauseKind CKind) { |
| 5134 | if (!E) |
| 5135 | return ExprError(); |
| 5136 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5137 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5138 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5139 | llvm::APSInt Result; |
| 5140 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5141 | if (ICE.isInvalid()) |
| 5142 | return ExprError(); |
| 5143 | if (!Result.isStrictlyPositive()) { |
| 5144 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 5145 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 5146 | return ExprError(); |
| 5147 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5148 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5149 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5150 | << E->getSourceRange(); |
| 5151 | return ExprError(); |
| 5152 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5153 | if (CKind == OMPC_collapse) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5154 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 5155 | Result.getExtValue()); |
| 5156 | } else if (CKind == OMPC_ordered) { |
| 5157 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 5158 | Result.getExtValue()); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5159 | } |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5160 | return ICE; |
| 5161 | } |
| 5162 | |
| 5163 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5164 | SourceLocation LParenLoc, |
| 5165 | SourceLocation EndLoc) { |
| 5166 | // OpenMP [2.8.1, simd construct, Description] |
| 5167 | // The parameter of the safelen clause must be a constant |
| 5168 | // positive integer expression. |
| 5169 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5170 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5171 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5172 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5173 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5174 | } |
| 5175 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5176 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5177 | SourceLocation LParenLoc, |
| 5178 | SourceLocation EndLoc) { |
| 5179 | // OpenMP [2.8.1, simd construct, Description] |
| 5180 | // The parameter of the simdlen clause must be a constant |
| 5181 | // positive integer expression. |
| 5182 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5183 | if (Simdlen.isInvalid()) |
| 5184 | return nullptr; |
| 5185 | return new (Context) |
| 5186 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5187 | } |
| 5188 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5189 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5190 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5191 | SourceLocation LParenLoc, |
| 5192 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5193 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5194 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5195 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5196 | // The parameter of the collapse clause must be a constant |
| 5197 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5198 | ExprResult NumForLoopsResult = |
| 5199 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5200 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5201 | return nullptr; |
| 5202 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5203 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5204 | } |
| 5205 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5206 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5207 | SourceLocation EndLoc, |
| 5208 | SourceLocation LParenLoc, |
| 5209 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5210 | // OpenMP [2.7.1, loop construct, Description] |
| 5211 | // OpenMP [2.8.1, simd construct, Description] |
| 5212 | // OpenMP [2.9.6, distribute construct, Description] |
| 5213 | // The parameter of the ordered clause must be a constant |
| 5214 | // positive integer expression if any. |
| 5215 | if (NumForLoops && LParenLoc.isValid()) { |
| 5216 | ExprResult NumForLoopsResult = |
| 5217 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5218 | if (NumForLoopsResult.isInvalid()) |
| 5219 | return nullptr; |
| 5220 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5221 | } else |
| 5222 | NumForLoops = nullptr; |
| 5223 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5224 | return new (Context) |
| 5225 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5226 | } |
| 5227 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5228 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5229 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5230 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5231 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5232 | switch (Kind) { |
| 5233 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5234 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5235 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5236 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5237 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5238 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5239 | Res = ActOnOpenMPProcBindClause( |
| 5240 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5241 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5242 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5243 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5244 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5245 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5246 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5247 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5248 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5249 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5250 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5251 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5252 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5253 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5254 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5255 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5256 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5257 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5258 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5259 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5260 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5261 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5262 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5263 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5264 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5265 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5266 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5267 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5268 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5269 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5270 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5271 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5272 | case OMPC_threads: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5273 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5274 | llvm_unreachable("Clause is not allowed."); |
| 5275 | } |
| 5276 | return Res; |
| 5277 | } |
| 5278 | |
| 5279 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 5280 | SourceLocation KindKwLoc, |
| 5281 | SourceLocation StartLoc, |
| 5282 | SourceLocation LParenLoc, |
| 5283 | SourceLocation EndLoc) { |
| 5284 | if (Kind == OMPC_DEFAULT_unknown) { |
| 5285 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5286 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 5287 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 5288 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5289 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5290 | Values += "'"; |
| 5291 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 5292 | Values += "'"; |
| 5293 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5294 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5295 | Values += " or "; |
| 5296 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5297 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5298 | break; |
| 5299 | default: |
| 5300 | Values += Sep; |
| 5301 | break; |
| 5302 | } |
| 5303 | } |
| 5304 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5305 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5306 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5307 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5308 | switch (Kind) { |
| 5309 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5310 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5311 | break; |
| 5312 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5313 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5314 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5315 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5316 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5317 | break; |
| 5318 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5319 | return new (Context) |
| 5320 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5321 | } |
| 5322 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5323 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5324 | SourceLocation KindKwLoc, |
| 5325 | SourceLocation StartLoc, |
| 5326 | SourceLocation LParenLoc, |
| 5327 | SourceLocation EndLoc) { |
| 5328 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5329 | std::string Values; |
| 5330 | std::string Sep(", "); |
| 5331 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 5332 | Values += "'"; |
| 5333 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 5334 | Values += "'"; |
| 5335 | switch (i) { |
| 5336 | case OMPC_PROC_BIND_unknown - 2: |
| 5337 | Values += " or "; |
| 5338 | break; |
| 5339 | case OMPC_PROC_BIND_unknown - 1: |
| 5340 | break; |
| 5341 | default: |
| 5342 | Values += Sep; |
| 5343 | break; |
| 5344 | } |
| 5345 | } |
| 5346 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5347 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5348 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5349 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5350 | return new (Context) |
| 5351 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5352 | } |
| 5353 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5354 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 5355 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 5356 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5357 | SourceLocation ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5358 | SourceLocation EndLoc) { |
| 5359 | OMPClause *Res = nullptr; |
| 5360 | switch (Kind) { |
| 5361 | case OMPC_schedule: |
| 5362 | Res = ActOnOpenMPScheduleClause( |
| 5363 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5364 | LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5365 | break; |
| 5366 | case OMPC_if: |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5367 | Res = |
| 5368 | ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr, |
| 5369 | StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
| 5370 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5371 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5372 | case OMPC_num_threads: |
| 5373 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5374 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5375 | case OMPC_collapse: |
| 5376 | case OMPC_default: |
| 5377 | case OMPC_proc_bind: |
| 5378 | case OMPC_private: |
| 5379 | case OMPC_firstprivate: |
| 5380 | case OMPC_lastprivate: |
| 5381 | case OMPC_shared: |
| 5382 | case OMPC_reduction: |
| 5383 | case OMPC_linear: |
| 5384 | case OMPC_aligned: |
| 5385 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5386 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5387 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5388 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5389 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5390 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5391 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5392 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5393 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5394 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5395 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5396 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5397 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5398 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5399 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5400 | case OMPC_threads: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5401 | case OMPC_unknown: |
| 5402 | llvm_unreachable("Clause is not allowed."); |
| 5403 | } |
| 5404 | return Res; |
| 5405 | } |
| 5406 | |
| 5407 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 5408 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 5409 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 5410 | SourceLocation EndLoc) { |
| 5411 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 5412 | std::string Values; |
| 5413 | std::string Sep(", "); |
| 5414 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 5415 | Values += "'"; |
| 5416 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 5417 | Values += "'"; |
| 5418 | switch (i) { |
| 5419 | case OMPC_SCHEDULE_unknown - 2: |
| 5420 | Values += " or "; |
| 5421 | break; |
| 5422 | case OMPC_SCHEDULE_unknown - 1: |
| 5423 | break; |
| 5424 | default: |
| 5425 | Values += Sep; |
| 5426 | break; |
| 5427 | } |
| 5428 | } |
| 5429 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 5430 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 5431 | return nullptr; |
| 5432 | } |
| 5433 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5434 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5435 | if (ChunkSize) { |
| 5436 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 5437 | !ChunkSize->isInstantiationDependent() && |
| 5438 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 5439 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 5440 | ExprResult Val = |
| 5441 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 5442 | if (Val.isInvalid()) |
| 5443 | return nullptr; |
| 5444 | |
| 5445 | ValExpr = Val.get(); |
| 5446 | |
| 5447 | // OpenMP [2.7.1, Restrictions] |
| 5448 | // chunk_size must be a loop invariant integer expression with a positive |
| 5449 | // value. |
| 5450 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5451 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 5452 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 5453 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 5454 | << "schedule" << ChunkSize->getSourceRange(); |
| 5455 | return nullptr; |
| 5456 | } |
| 5457 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 5458 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 5459 | ChunkSize->getType(), ".chunk."); |
| 5460 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 5461 | ChunkSize->getExprLoc(), |
| 5462 | /*RefersToCapture=*/true); |
| 5463 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5464 | } |
| 5465 | } |
| 5466 | } |
| 5467 | |
| 5468 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5469 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5470 | } |
| 5471 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5472 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 5473 | SourceLocation StartLoc, |
| 5474 | SourceLocation EndLoc) { |
| 5475 | OMPClause *Res = nullptr; |
| 5476 | switch (Kind) { |
| 5477 | case OMPC_ordered: |
| 5478 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 5479 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5480 | case OMPC_nowait: |
| 5481 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 5482 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5483 | case OMPC_untied: |
| 5484 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 5485 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5486 | case OMPC_mergeable: |
| 5487 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 5488 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5489 | case OMPC_read: |
| 5490 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 5491 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5492 | case OMPC_write: |
| 5493 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 5494 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5495 | case OMPC_update: |
| 5496 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 5497 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5498 | case OMPC_capture: |
| 5499 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 5500 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5501 | case OMPC_seq_cst: |
| 5502 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 5503 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5504 | case OMPC_threads: |
| 5505 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 5506 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5507 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5508 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5509 | case OMPC_num_threads: |
| 5510 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5511 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5512 | case OMPC_collapse: |
| 5513 | case OMPC_schedule: |
| 5514 | case OMPC_private: |
| 5515 | case OMPC_firstprivate: |
| 5516 | case OMPC_lastprivate: |
| 5517 | case OMPC_shared: |
| 5518 | case OMPC_reduction: |
| 5519 | case OMPC_linear: |
| 5520 | case OMPC_aligned: |
| 5521 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5522 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5523 | case OMPC_default: |
| 5524 | case OMPC_proc_bind: |
| 5525 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5526 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5527 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5528 | case OMPC_device: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5529 | case OMPC_unknown: |
| 5530 | llvm_unreachable("Clause is not allowed."); |
| 5531 | } |
| 5532 | return Res; |
| 5533 | } |
| 5534 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5535 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 5536 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5537 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5538 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 5539 | } |
| 5540 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5541 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 5542 | SourceLocation EndLoc) { |
| 5543 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 5544 | } |
| 5545 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5546 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 5547 | SourceLocation EndLoc) { |
| 5548 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 5549 | } |
| 5550 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5551 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 5552 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5553 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 5554 | } |
| 5555 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5556 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 5557 | SourceLocation EndLoc) { |
| 5558 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 5559 | } |
| 5560 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5561 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 5562 | SourceLocation EndLoc) { |
| 5563 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 5564 | } |
| 5565 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5566 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 5567 | SourceLocation EndLoc) { |
| 5568 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 5569 | } |
| 5570 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5571 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 5572 | SourceLocation EndLoc) { |
| 5573 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 5574 | } |
| 5575 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5576 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 5577 | SourceLocation EndLoc) { |
| 5578 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 5579 | } |
| 5580 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5581 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 5582 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 5583 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 5584 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5585 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5586 | OpenMPLinearClauseKind LinKind, SourceLocation DepLinLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5587 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5588 | switch (Kind) { |
| 5589 | case OMPC_private: |
| 5590 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5591 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5592 | case OMPC_firstprivate: |
| 5593 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5594 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5595 | case OMPC_lastprivate: |
| 5596 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5597 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5598 | case OMPC_shared: |
| 5599 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5600 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5601 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5602 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 5603 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5604 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5605 | case OMPC_linear: |
| 5606 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5607 | LinKind, DepLinLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5608 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5609 | case OMPC_aligned: |
| 5610 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 5611 | ColonLoc, EndLoc); |
| 5612 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5613 | case OMPC_copyin: |
| 5614 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5615 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5616 | case OMPC_copyprivate: |
| 5617 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5618 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5619 | case OMPC_flush: |
| 5620 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5621 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5622 | case OMPC_depend: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5623 | Res = ActOnOpenMPDependClause(DepKind, DepLinLoc, ColonLoc, VarList, StartLoc, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5624 | LParenLoc, EndLoc); |
| 5625 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5626 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5627 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5628 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5629 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5630 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5631 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5632 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5633 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5634 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5635 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5636 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5637 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5638 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5639 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5640 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5641 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5642 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5643 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5644 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5645 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5646 | case OMPC_threads: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5647 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5648 | llvm_unreachable("Clause is not allowed."); |
| 5649 | } |
| 5650 | return Res; |
| 5651 | } |
| 5652 | |
| 5653 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 5654 | SourceLocation StartLoc, |
| 5655 | SourceLocation LParenLoc, |
| 5656 | SourceLocation EndLoc) { |
| 5657 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5658 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5659 | for (auto &RefExpr : VarList) { |
| 5660 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 5661 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5662 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5663 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5664 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5665 | continue; |
| 5666 | } |
| 5667 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5668 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5669 | // OpenMP [2.1, C/C++] |
| 5670 | // A list item is a variable name. |
| 5671 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5672 | // A variable that is part of another variable (as an array or |
| 5673 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5674 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5675 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5676 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5677 | continue; |
| 5678 | } |
| 5679 | Decl *D = DE->getDecl(); |
| 5680 | VarDecl *VD = cast<VarDecl>(D); |
| 5681 | |
| 5682 | QualType Type = VD->getType(); |
| 5683 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5684 | // It will be analyzed later. |
| 5685 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5686 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5687 | continue; |
| 5688 | } |
| 5689 | |
| 5690 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5691 | // A variable that appears in a private clause must not have an incomplete |
| 5692 | // type or a reference type. |
| 5693 | if (RequireCompleteType(ELoc, Type, |
| 5694 | diag::err_omp_private_incomplete_type)) { |
| 5695 | continue; |
| 5696 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5697 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5698 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5699 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5700 | // in a Construct] |
| 5701 | // Variables with the predetermined data-sharing attributes may not be |
| 5702 | // listed in data-sharing attributes clauses, except for the cases |
| 5703 | // listed below. For these exceptions only, listing a predetermined |
| 5704 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5705 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5706 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5707 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5708 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5709 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5710 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5711 | continue; |
| 5712 | } |
| 5713 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5714 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5715 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5716 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5717 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5718 | << getOpenMPClauseName(OMPC_private) << Type |
| 5719 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5720 | bool IsDecl = |
| 5721 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5722 | Diag(VD->getLocation(), |
| 5723 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5724 | << VD; |
| 5725 | continue; |
| 5726 | } |
| 5727 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5728 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 5729 | // A variable of class type (or array thereof) that appears in a private |
| 5730 | // clause requires an accessible, unambiguous default constructor for the |
| 5731 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5732 | // Generate helper private variable and initialize it with the default |
| 5733 | // value. The address of the original variable is replaced by the address of |
| 5734 | // the new private variable in CodeGen. This new variable is not added to |
| 5735 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 5736 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5737 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 5738 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 5739 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5740 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5741 | if (VDPrivate->isInvalidDecl()) |
| 5742 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5743 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5744 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5745 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5746 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5747 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5748 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5749 | } |
| 5750 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5751 | if (Vars.empty()) |
| 5752 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5753 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5754 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 5755 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5756 | } |
| 5757 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5758 | namespace { |
| 5759 | class DiagsUninitializedSeveretyRAII { |
| 5760 | private: |
| 5761 | DiagnosticsEngine &Diags; |
| 5762 | SourceLocation SavedLoc; |
| 5763 | bool IsIgnored; |
| 5764 | |
| 5765 | public: |
| 5766 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 5767 | bool IsIgnored) |
| 5768 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 5769 | if (!IsIgnored) { |
| 5770 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 5771 | /*Map*/ diag::Severity::Ignored, Loc); |
| 5772 | } |
| 5773 | } |
| 5774 | ~DiagsUninitializedSeveretyRAII() { |
| 5775 | if (!IsIgnored) |
| 5776 | Diags.popMappings(SavedLoc); |
| 5777 | } |
| 5778 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 5779 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5780 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5781 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 5782 | SourceLocation StartLoc, |
| 5783 | SourceLocation LParenLoc, |
| 5784 | SourceLocation EndLoc) { |
| 5785 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5786 | SmallVector<Expr *, 8> PrivateCopies; |
| 5787 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5788 | bool IsImplicitClause = |
| 5789 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 5790 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 5791 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5792 | for (auto &RefExpr : VarList) { |
| 5793 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 5794 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5795 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5796 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5797 | PrivateCopies.push_back(nullptr); |
| 5798 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5799 | continue; |
| 5800 | } |
| 5801 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5802 | SourceLocation ELoc = |
| 5803 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5804 | // OpenMP [2.1, C/C++] |
| 5805 | // A list item is a variable name. |
| 5806 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5807 | // A variable that is part of another variable (as an array or |
| 5808 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5809 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5810 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5811 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5812 | continue; |
| 5813 | } |
| 5814 | Decl *D = DE->getDecl(); |
| 5815 | VarDecl *VD = cast<VarDecl>(D); |
| 5816 | |
| 5817 | QualType Type = VD->getType(); |
| 5818 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5819 | // It will be analyzed later. |
| 5820 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5821 | PrivateCopies.push_back(nullptr); |
| 5822 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5823 | continue; |
| 5824 | } |
| 5825 | |
| 5826 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5827 | // A variable that appears in a private clause must not have an incomplete |
| 5828 | // type or a reference type. |
| 5829 | if (RequireCompleteType(ELoc, Type, |
| 5830 | diag::err_omp_firstprivate_incomplete_type)) { |
| 5831 | continue; |
| 5832 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5833 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5834 | |
| 5835 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 5836 | // 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] | 5837 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5838 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5839 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5840 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5841 | // If an implicit firstprivate variable found it was checked already. |
| 5842 | if (!IsImplicitClause) { |
| 5843 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5844 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5845 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 5846 | // A list item that specifies a given variable may not appear in more |
| 5847 | // than one clause on the same directive, except that a variable may be |
| 5848 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5849 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5850 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5851 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5852 | << getOpenMPClauseName(DVar.CKind) |
| 5853 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5854 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5855 | continue; |
| 5856 | } |
| 5857 | |
| 5858 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5859 | // in a Construct] |
| 5860 | // Variables with the predetermined data-sharing attributes may not be |
| 5861 | // listed in data-sharing attributes clauses, except for the cases |
| 5862 | // listed below. For these exceptions only, listing a predetermined |
| 5863 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5864 | // the variable's predetermined data-sharing attributes. |
| 5865 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5866 | // in a Construct, C/C++, p.2] |
| 5867 | // Variables with const-qualified type having no mutable member may be |
| 5868 | // listed in a firstprivate clause, even if they are static data members. |
| 5869 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 5870 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 5871 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5872 | << getOpenMPClauseName(DVar.CKind) |
| 5873 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5874 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5875 | continue; |
| 5876 | } |
| 5877 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5878 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5879 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 5880 | // A list item that is private within a parallel region must not appear |
| 5881 | // in a firstprivate clause on a worksharing construct if any of the |
| 5882 | // worksharing regions arising from the worksharing construct ever bind |
| 5883 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5884 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5885 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5886 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 5887 | if (DVar.CKind != OMPC_shared && |
| 5888 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5889 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5890 | Diag(ELoc, diag::err_omp_required_access) |
| 5891 | << getOpenMPClauseName(OMPC_firstprivate) |
| 5892 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5893 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5894 | continue; |
| 5895 | } |
| 5896 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5897 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 5898 | // A list item that appears in a reduction clause of a parallel construct |
| 5899 | // must not appear in a firstprivate clause on a worksharing or task |
| 5900 | // construct if any of the worksharing or task regions arising from the |
| 5901 | // worksharing or task construct ever bind to any of the parallel regions |
| 5902 | // arising from the parallel construct. |
| 5903 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 5904 | // A list item that appears in a reduction clause in worksharing |
| 5905 | // construct must not appear in a firstprivate clause in a task construct |
| 5906 | // encountered during execution of any of the worksharing regions arising |
| 5907 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5908 | if (CurrDir == OMPD_task) { |
| 5909 | DVar = |
| 5910 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 5911 | [](OpenMPDirectiveKind K) -> bool { |
| 5912 | return isOpenMPParallelDirective(K) || |
| 5913 | isOpenMPWorksharingDirective(K); |
| 5914 | }, |
| 5915 | false); |
| 5916 | if (DVar.CKind == OMPC_reduction && |
| 5917 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5918 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 5919 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 5920 | << getOpenMPDirectiveName(DVar.DKind); |
| 5921 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 5922 | continue; |
| 5923 | } |
| 5924 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5925 | } |
| 5926 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5927 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5928 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5929 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5930 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5931 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 5932 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5933 | bool IsDecl = |
| 5934 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5935 | Diag(VD->getLocation(), |
| 5936 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5937 | << VD; |
| 5938 | continue; |
| 5939 | } |
| 5940 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5941 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 5942 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 5943 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5944 | // Generate helper private variable and initialize it with the value of the |
| 5945 | // original variable. The address of the original variable is replaced by |
| 5946 | // the address of the new private variable in the CodeGen. This new variable |
| 5947 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 5948 | // original variable for proper diagnostics and variable capturing. |
| 5949 | Expr *VDInitRefExpr = nullptr; |
| 5950 | // For arrays generate initializer for single element and replace it by the |
| 5951 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5952 | if (Type->isArrayType()) { |
| 5953 | auto VDInit = |
| 5954 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 5955 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5956 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5957 | ElemType = ElemType.getUnqualifiedType(); |
| 5958 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 5959 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5960 | InitializedEntity Entity = |
| 5961 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5962 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 5963 | |
| 5964 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 5965 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 5966 | if (Result.isInvalid()) |
| 5967 | VDPrivate->setInvalidDecl(); |
| 5968 | else |
| 5969 | VDPrivate->setInit(Result.getAs<Expr>()); |
| 5970 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5971 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5972 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5973 | VDInitRefExpr = |
| 5974 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5975 | AddInitializerToDecl(VDPrivate, |
| 5976 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 5977 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5978 | } |
| 5979 | if (VDPrivate->isInvalidDecl()) { |
| 5980 | if (IsImplicitClause) { |
| 5981 | Diag(DE->getExprLoc(), |
| 5982 | diag::note_omp_task_predetermined_firstprivate_here); |
| 5983 | } |
| 5984 | continue; |
| 5985 | } |
| 5986 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5987 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5988 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5989 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 5990 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5991 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 5992 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5993 | } |
| 5994 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5995 | if (Vars.empty()) |
| 5996 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5997 | |
| 5998 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5999 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6000 | } |
| 6001 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6002 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6003 | SourceLocation StartLoc, |
| 6004 | SourceLocation LParenLoc, |
| 6005 | SourceLocation EndLoc) { |
| 6006 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6007 | SmallVector<Expr *, 8> SrcExprs; |
| 6008 | SmallVector<Expr *, 8> DstExprs; |
| 6009 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6010 | for (auto &RefExpr : VarList) { |
| 6011 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 6012 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6013 | // It will be analyzed later. |
| 6014 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6015 | SrcExprs.push_back(nullptr); |
| 6016 | DstExprs.push_back(nullptr); |
| 6017 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6018 | continue; |
| 6019 | } |
| 6020 | |
| 6021 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6022 | // OpenMP [2.1, C/C++] |
| 6023 | // A list item is a variable name. |
| 6024 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 6025 | // A variable that is part of another variable (as an array or structure |
| 6026 | // element) cannot appear in a lastprivate clause. |
| 6027 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 6028 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6029 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6030 | continue; |
| 6031 | } |
| 6032 | Decl *D = DE->getDecl(); |
| 6033 | VarDecl *VD = cast<VarDecl>(D); |
| 6034 | |
| 6035 | QualType Type = VD->getType(); |
| 6036 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6037 | // It will be analyzed later. |
| 6038 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6039 | SrcExprs.push_back(nullptr); |
| 6040 | DstExprs.push_back(nullptr); |
| 6041 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6042 | continue; |
| 6043 | } |
| 6044 | |
| 6045 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6046 | // A variable that appears in a lastprivate clause must not have an |
| 6047 | // incomplete type or a reference type. |
| 6048 | if (RequireCompleteType(ELoc, Type, |
| 6049 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6050 | continue; |
| 6051 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6052 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6053 | |
| 6054 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6055 | // in a Construct] |
| 6056 | // Variables with the predetermined data-sharing attributes may not be |
| 6057 | // listed in data-sharing attributes clauses, except for the cases |
| 6058 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6059 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6060 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6061 | DVar.CKind != OMPC_firstprivate && |
| 6062 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6063 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6064 | << getOpenMPClauseName(DVar.CKind) |
| 6065 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6066 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6067 | continue; |
| 6068 | } |
| 6069 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6070 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6071 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6072 | // A list item that is private within a parallel region, or that appears in |
| 6073 | // the reduction clause of a parallel construct, must not appear in a |
| 6074 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6075 | // worksharing regions ever binds to any of the corresponding parallel |
| 6076 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6077 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6078 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6079 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6080 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6081 | if (DVar.CKind != OMPC_shared) { |
| 6082 | Diag(ELoc, diag::err_omp_required_access) |
| 6083 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6084 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6085 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6086 | continue; |
| 6087 | } |
| 6088 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6089 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6090 | // A variable of class type (or array thereof) that appears in a |
| 6091 | // lastprivate clause requires an accessible, unambiguous default |
| 6092 | // constructor for the class type, unless the list item is also specified |
| 6093 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6094 | // A variable of class type (or array thereof) that appears in a |
| 6095 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6096 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6097 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6098 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6099 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6100 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6101 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6102 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6103 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6104 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6105 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6106 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6107 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6108 | // For arrays generate assignment operation for single element and replace |
| 6109 | // it by the original array element in CodeGen. |
| 6110 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6111 | PseudoDstExpr, PseudoSrcExpr); |
| 6112 | if (AssignmentOp.isInvalid()) |
| 6113 | continue; |
| 6114 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6115 | /*DiscardedValue=*/true); |
| 6116 | if (AssignmentOp.isInvalid()) |
| 6117 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6118 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6119 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6120 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6121 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6122 | SrcExprs.push_back(PseudoSrcExpr); |
| 6123 | DstExprs.push_back(PseudoDstExpr); |
| 6124 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6125 | } |
| 6126 | |
| 6127 | if (Vars.empty()) |
| 6128 | return nullptr; |
| 6129 | |
| 6130 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6131 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6132 | } |
| 6133 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6134 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 6135 | SourceLocation StartLoc, |
| 6136 | SourceLocation LParenLoc, |
| 6137 | SourceLocation EndLoc) { |
| 6138 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6139 | for (auto &RefExpr : VarList) { |
| 6140 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6141 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6142 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6143 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6144 | continue; |
| 6145 | } |
| 6146 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6147 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6148 | // OpenMP [2.1, C/C++] |
| 6149 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 6150 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 6151 | // A variable that is part of another variable (as an array or structure |
| 6152 | // element) cannot appear in a shared unless it is a static data member |
| 6153 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6154 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6155 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6156 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6157 | continue; |
| 6158 | } |
| 6159 | Decl *D = DE->getDecl(); |
| 6160 | VarDecl *VD = cast<VarDecl>(D); |
| 6161 | |
| 6162 | QualType Type = VD->getType(); |
| 6163 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6164 | // It will be analyzed later. |
| 6165 | Vars.push_back(DE); |
| 6166 | continue; |
| 6167 | } |
| 6168 | |
| 6169 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6170 | // in a Construct] |
| 6171 | // Variables with the predetermined data-sharing attributes may not be |
| 6172 | // listed in data-sharing attributes clauses, except for the cases |
| 6173 | // listed below. For these exceptions only, listing a predetermined |
| 6174 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6175 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6176 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6177 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 6178 | DVar.RefExpr) { |
| 6179 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6180 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6181 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6182 | continue; |
| 6183 | } |
| 6184 | |
| 6185 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 6186 | Vars.push_back(DE); |
| 6187 | } |
| 6188 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6189 | if (Vars.empty()) |
| 6190 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6191 | |
| 6192 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 6193 | } |
| 6194 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6195 | namespace { |
| 6196 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 6197 | DSAStackTy *Stack; |
| 6198 | |
| 6199 | public: |
| 6200 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 6201 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6202 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6203 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 6204 | return false; |
| 6205 | if (DVar.CKind != OMPC_unknown) |
| 6206 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6207 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6208 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6209 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6210 | return true; |
| 6211 | return false; |
| 6212 | } |
| 6213 | return false; |
| 6214 | } |
| 6215 | bool VisitStmt(Stmt *S) { |
| 6216 | for (auto Child : S->children()) { |
| 6217 | if (Child && Visit(Child)) |
| 6218 | return true; |
| 6219 | } |
| 6220 | return false; |
| 6221 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6222 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6223 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6224 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6225 | |
| 6226 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 6227 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 6228 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 6229 | CXXScopeSpec &ReductionIdScopeSpec, |
| 6230 | const DeclarationNameInfo &ReductionId) { |
| 6231 | // TODO: Allow scope specification search when 'declare reduction' is |
| 6232 | // supported. |
| 6233 | assert(ReductionIdScopeSpec.isEmpty() && |
| 6234 | "No support for scoped reduction identifiers yet."); |
| 6235 | |
| 6236 | auto DN = ReductionId.getName(); |
| 6237 | auto OOK = DN.getCXXOverloadedOperator(); |
| 6238 | BinaryOperatorKind BOK = BO_Comma; |
| 6239 | |
| 6240 | // OpenMP [2.14.3.6, reduction clause] |
| 6241 | // C |
| 6242 | // reduction-identifier is either an identifier or one of the following |
| 6243 | // operators: +, -, *, &, |, ^, && and || |
| 6244 | // C++ |
| 6245 | // reduction-identifier is either an id-expression or one of the following |
| 6246 | // operators: +, -, *, &, |, ^, && and || |
| 6247 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 6248 | switch (OOK) { |
| 6249 | case OO_Plus: |
| 6250 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6251 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6252 | break; |
| 6253 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6254 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6255 | break; |
| 6256 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6257 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6258 | break; |
| 6259 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6260 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6261 | break; |
| 6262 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6263 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6264 | break; |
| 6265 | case OO_AmpAmp: |
| 6266 | BOK = BO_LAnd; |
| 6267 | break; |
| 6268 | case OO_PipePipe: |
| 6269 | BOK = BO_LOr; |
| 6270 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6271 | case OO_New: |
| 6272 | case OO_Delete: |
| 6273 | case OO_Array_New: |
| 6274 | case OO_Array_Delete: |
| 6275 | case OO_Slash: |
| 6276 | case OO_Percent: |
| 6277 | case OO_Tilde: |
| 6278 | case OO_Exclaim: |
| 6279 | case OO_Equal: |
| 6280 | case OO_Less: |
| 6281 | case OO_Greater: |
| 6282 | case OO_LessEqual: |
| 6283 | case OO_GreaterEqual: |
| 6284 | case OO_PlusEqual: |
| 6285 | case OO_MinusEqual: |
| 6286 | case OO_StarEqual: |
| 6287 | case OO_SlashEqual: |
| 6288 | case OO_PercentEqual: |
| 6289 | case OO_CaretEqual: |
| 6290 | case OO_AmpEqual: |
| 6291 | case OO_PipeEqual: |
| 6292 | case OO_LessLess: |
| 6293 | case OO_GreaterGreater: |
| 6294 | case OO_LessLessEqual: |
| 6295 | case OO_GreaterGreaterEqual: |
| 6296 | case OO_EqualEqual: |
| 6297 | case OO_ExclaimEqual: |
| 6298 | case OO_PlusPlus: |
| 6299 | case OO_MinusMinus: |
| 6300 | case OO_Comma: |
| 6301 | case OO_ArrowStar: |
| 6302 | case OO_Arrow: |
| 6303 | case OO_Call: |
| 6304 | case OO_Subscript: |
| 6305 | case OO_Conditional: |
| 6306 | case NUM_OVERLOADED_OPERATORS: |
| 6307 | llvm_unreachable("Unexpected reduction identifier"); |
| 6308 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6309 | if (auto II = DN.getAsIdentifierInfo()) { |
| 6310 | if (II->isStr("max")) |
| 6311 | BOK = BO_GT; |
| 6312 | else if (II->isStr("min")) |
| 6313 | BOK = BO_LT; |
| 6314 | } |
| 6315 | break; |
| 6316 | } |
| 6317 | SourceRange ReductionIdRange; |
| 6318 | if (ReductionIdScopeSpec.isValid()) { |
| 6319 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 6320 | } |
| 6321 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 6322 | if (BOK == BO_Comma) { |
| 6323 | // Not allowed reduction identifier is found. |
| 6324 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 6325 | << ReductionIdRange; |
| 6326 | return nullptr; |
| 6327 | } |
| 6328 | |
| 6329 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6330 | SmallVector<Expr *, 8> LHSs; |
| 6331 | SmallVector<Expr *, 8> RHSs; |
| 6332 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6333 | for (auto RefExpr : VarList) { |
| 6334 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 6335 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6336 | // It will be analyzed later. |
| 6337 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6338 | LHSs.push_back(nullptr); |
| 6339 | RHSs.push_back(nullptr); |
| 6340 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6341 | continue; |
| 6342 | } |
| 6343 | |
| 6344 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6345 | RefExpr->isInstantiationDependent() || |
| 6346 | RefExpr->containsUnexpandedParameterPack()) { |
| 6347 | // It will be analyzed later. |
| 6348 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6349 | LHSs.push_back(nullptr); |
| 6350 | RHSs.push_back(nullptr); |
| 6351 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6352 | continue; |
| 6353 | } |
| 6354 | |
| 6355 | auto ELoc = RefExpr->getExprLoc(); |
| 6356 | auto ERange = RefExpr->getSourceRange(); |
| 6357 | // OpenMP [2.1, C/C++] |
| 6358 | // A list item is a variable or array section, subject to the restrictions |
| 6359 | // specified in Section 2.4 on page 42 and in each of the sections |
| 6360 | // describing clauses and directives for which a list appears. |
| 6361 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6362 | // A variable that is part of another variable (as an array or |
| 6363 | // structure element) cannot appear in a private clause. |
| 6364 | auto DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6365 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6366 | Diag(ELoc, diag::err_omp_expected_var_name) << ERange; |
| 6367 | continue; |
| 6368 | } |
| 6369 | auto D = DE->getDecl(); |
| 6370 | auto VD = cast<VarDecl>(D); |
| 6371 | auto Type = VD->getType(); |
| 6372 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6373 | // A variable that appears in a private clause must not have an incomplete |
| 6374 | // type or a reference type. |
| 6375 | if (RequireCompleteType(ELoc, Type, |
| 6376 | diag::err_omp_reduction_incomplete_type)) |
| 6377 | continue; |
| 6378 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6379 | // Arrays may not appear in a reduction clause. |
| 6380 | if (Type.getNonReferenceType()->isArrayType()) { |
| 6381 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
| 6382 | bool IsDecl = |
| 6383 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6384 | Diag(VD->getLocation(), |
| 6385 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6386 | << VD; |
| 6387 | continue; |
| 6388 | } |
| 6389 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6390 | // A list item that appears in a reduction clause must not be |
| 6391 | // const-qualified. |
| 6392 | if (Type.getNonReferenceType().isConstant(Context)) { |
| 6393 | Diag(ELoc, diag::err_omp_const_variable) |
| 6394 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
| 6395 | bool IsDecl = |
| 6396 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6397 | Diag(VD->getLocation(), |
| 6398 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6399 | << VD; |
| 6400 | continue; |
| 6401 | } |
| 6402 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 6403 | // If a list-item is a reference type then it must bind to the same object |
| 6404 | // for all threads of the team. |
| 6405 | VarDecl *VDDef = VD->getDefinition(); |
| 6406 | if (Type->isReferenceType() && VDDef) { |
| 6407 | DSARefChecker Check(DSAStack); |
| 6408 | if (Check.Visit(VDDef->getInit())) { |
| 6409 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 6410 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 6411 | continue; |
| 6412 | } |
| 6413 | } |
| 6414 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6415 | // The type of a list item that appears in a reduction clause must be valid |
| 6416 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 6417 | // of the list item must be an allowed arithmetic data type: char, int, |
| 6418 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 6419 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 6420 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 6421 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 6422 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 6423 | !(Type->isScalarType() || |
| 6424 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 6425 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 6426 | << getLangOpts().CPlusPlus; |
| 6427 | bool IsDecl = |
| 6428 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6429 | Diag(VD->getLocation(), |
| 6430 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6431 | << VD; |
| 6432 | continue; |
| 6433 | } |
| 6434 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 6435 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 6436 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 6437 | bool IsDecl = |
| 6438 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6439 | Diag(VD->getLocation(), |
| 6440 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6441 | << VD; |
| 6442 | continue; |
| 6443 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6444 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6445 | // in a Construct] |
| 6446 | // Variables with the predetermined data-sharing attributes may not be |
| 6447 | // listed in data-sharing attributes clauses, except for the cases |
| 6448 | // listed below. For these exceptions only, listing a predetermined |
| 6449 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6450 | // the variable's predetermined data-sharing attributes. |
| 6451 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 6452 | // Any number of reduction clauses can be specified on the directive, |
| 6453 | // but a list item can appear only once in the reduction clauses for that |
| 6454 | // directive. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6455 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6456 | if (DVar.CKind == OMPC_reduction) { |
| 6457 | Diag(ELoc, diag::err_omp_once_referenced) |
| 6458 | << getOpenMPClauseName(OMPC_reduction); |
| 6459 | if (DVar.RefExpr) { |
| 6460 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 6461 | } |
| 6462 | } else if (DVar.CKind != OMPC_unknown) { |
| 6463 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6464 | << getOpenMPClauseName(DVar.CKind) |
| 6465 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6466 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6467 | continue; |
| 6468 | } |
| 6469 | |
| 6470 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 6471 | // A list item that appears in a reduction clause of a worksharing |
| 6472 | // construct must be shared in the parallel regions to which any of the |
| 6473 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6474 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6475 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6476 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6477 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6478 | if (DVar.CKind != OMPC_shared) { |
| 6479 | Diag(ELoc, diag::err_omp_required_access) |
| 6480 | << getOpenMPClauseName(OMPC_reduction) |
| 6481 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6482 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6483 | continue; |
| 6484 | } |
| 6485 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6486 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6487 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 6488 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 6489 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6490 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6491 | // Add initializer for private variable. |
| 6492 | Expr *Init = nullptr; |
| 6493 | switch (BOK) { |
| 6494 | case BO_Add: |
| 6495 | case BO_Xor: |
| 6496 | case BO_Or: |
| 6497 | case BO_LOr: |
| 6498 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 6499 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6500 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6501 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6502 | break; |
| 6503 | case BO_Mul: |
| 6504 | case BO_LAnd: |
| 6505 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6506 | // '*' and '&&' reduction ops - initializer is '1'. |
| 6507 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 6508 | } |
| 6509 | break; |
| 6510 | case BO_And: { |
| 6511 | // '&' reduction op - initializer is '~0'. |
| 6512 | QualType OrigType = Type; |
| 6513 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 6514 | Type = ComplexTy->getElementType(); |
| 6515 | } |
| 6516 | if (Type->isRealFloatingType()) { |
| 6517 | llvm::APFloat InitValue = |
| 6518 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 6519 | /*isIEEE=*/true); |
| 6520 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6521 | Type, ELoc); |
| 6522 | } else if (Type->isScalarType()) { |
| 6523 | auto Size = Context.getTypeSize(Type); |
| 6524 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 6525 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 6526 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6527 | } |
| 6528 | if (Init && OrigType->isAnyComplexType()) { |
| 6529 | // Init = 0xFFFF + 0xFFFFi; |
| 6530 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 6531 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 6532 | } |
| 6533 | Type = OrigType; |
| 6534 | break; |
| 6535 | } |
| 6536 | case BO_LT: |
| 6537 | case BO_GT: { |
| 6538 | // 'min' reduction op - initializer is 'Largest representable number in |
| 6539 | // the reduction list item type'. |
| 6540 | // 'max' reduction op - initializer is 'Least representable number in |
| 6541 | // the reduction list item type'. |
| 6542 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 6543 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 6544 | auto Size = Context.getTypeSize(Type); |
| 6545 | QualType IntTy = |
| 6546 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 6547 | llvm::APInt InitValue = |
| 6548 | (BOK != BO_LT) |
| 6549 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 6550 | : llvm::APInt::getMinValue(Size) |
| 6551 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 6552 | : llvm::APInt::getMaxValue(Size); |
| 6553 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6554 | if (Type->isPointerType()) { |
| 6555 | // Cast to pointer type. |
| 6556 | auto CastExpr = BuildCStyleCastExpr( |
| 6557 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 6558 | SourceLocation(), Init); |
| 6559 | if (CastExpr.isInvalid()) |
| 6560 | continue; |
| 6561 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6562 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6563 | } else if (Type->isRealFloatingType()) { |
| 6564 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 6565 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 6566 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6567 | Type, ELoc); |
| 6568 | } |
| 6569 | break; |
| 6570 | } |
| 6571 | case BO_PtrMemD: |
| 6572 | case BO_PtrMemI: |
| 6573 | case BO_MulAssign: |
| 6574 | case BO_Div: |
| 6575 | case BO_Rem: |
| 6576 | case BO_Sub: |
| 6577 | case BO_Shl: |
| 6578 | case BO_Shr: |
| 6579 | case BO_LE: |
| 6580 | case BO_GE: |
| 6581 | case BO_EQ: |
| 6582 | case BO_NE: |
| 6583 | case BO_AndAssign: |
| 6584 | case BO_XorAssign: |
| 6585 | case BO_OrAssign: |
| 6586 | case BO_Assign: |
| 6587 | case BO_AddAssign: |
| 6588 | case BO_SubAssign: |
| 6589 | case BO_DivAssign: |
| 6590 | case BO_RemAssign: |
| 6591 | case BO_ShlAssign: |
| 6592 | case BO_ShrAssign: |
| 6593 | case BO_Comma: |
| 6594 | llvm_unreachable("Unexpected reduction operation"); |
| 6595 | } |
| 6596 | if (Init) { |
| 6597 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 6598 | /*TypeMayContainAuto=*/false); |
| 6599 | } else { |
| 6600 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
| 6601 | } |
| 6602 | if (!RHSVD->hasInit()) { |
| 6603 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 6604 | << ReductionIdRange; |
| 6605 | bool IsDecl = |
| 6606 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6607 | Diag(VD->getLocation(), |
| 6608 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6609 | << VD; |
| 6610 | continue; |
| 6611 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6612 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 6613 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6614 | ExprResult ReductionOp = |
| 6615 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 6616 | LHSDRE, RHSDRE); |
| 6617 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 6618 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6619 | ReductionOp = |
| 6620 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6621 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 6622 | } else { |
| 6623 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 6624 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 6625 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 6626 | ReductionOp = |
| 6627 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6628 | BO_Assign, LHSDRE, ConditionalOp); |
| 6629 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6630 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6631 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6632 | if (ReductionOp.isInvalid()) |
| 6633 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6634 | |
| 6635 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 6636 | Vars.push_back(DE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6637 | LHSs.push_back(LHSDRE); |
| 6638 | RHSs.push_back(RHSDRE); |
| 6639 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6640 | } |
| 6641 | |
| 6642 | if (Vars.empty()) |
| 6643 | return nullptr; |
| 6644 | |
| 6645 | return OMPReductionClause::Create( |
| 6646 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6647 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, LHSs, |
| 6648 | RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6649 | } |
| 6650 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6651 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 6652 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 6653 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 6654 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6655 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6656 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6657 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6658 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 6659 | LinKind == OMPC_LINEAR_unknown) { |
| 6660 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 6661 | LinKind = OMPC_LINEAR_val; |
| 6662 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6663 | for (auto &RefExpr : VarList) { |
| 6664 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 6665 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6666 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6667 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6668 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6669 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6670 | continue; |
| 6671 | } |
| 6672 | |
| 6673 | // OpenMP [2.14.3.7, linear clause] |
| 6674 | // A list item that appears in a linear clause is subject to the private |
| 6675 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 6676 | // noted. In addition, the value of the new list item on each iteration |
| 6677 | // of the associated loop(s) corresponds to the value of the original |
| 6678 | // list item before entering the construct plus the logical number of |
| 6679 | // the iteration times linear-step. |
| 6680 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6681 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6682 | // OpenMP [2.1, C/C++] |
| 6683 | // A list item is a variable name. |
| 6684 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6685 | // A variable that is part of another variable (as an array or |
| 6686 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6687 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6688 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6689 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6690 | continue; |
| 6691 | } |
| 6692 | |
| 6693 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6694 | |
| 6695 | // OpenMP [2.14.3.7, linear clause] |
| 6696 | // A list-item cannot appear in more than one linear clause. |
| 6697 | // A list-item that appears in a linear clause cannot appear in any |
| 6698 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6699 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6700 | if (DVar.RefExpr) { |
| 6701 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6702 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6703 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6704 | continue; |
| 6705 | } |
| 6706 | |
| 6707 | QualType QType = VD->getType(); |
| 6708 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 6709 | // It will be analyzed later. |
| 6710 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6711 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6712 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6713 | continue; |
| 6714 | } |
| 6715 | |
| 6716 | // A variable must not have an incomplete type or a reference type. |
| 6717 | if (RequireCompleteType(ELoc, QType, |
| 6718 | diag::err_omp_linear_incomplete_type)) { |
| 6719 | continue; |
| 6720 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 6721 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 6722 | !QType->isReferenceType()) { |
| 6723 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 6724 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 6725 | continue; |
| 6726 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6727 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6728 | |
| 6729 | // A list item must not be const-qualified. |
| 6730 | if (QType.isConstant(Context)) { |
| 6731 | Diag(ELoc, diag::err_omp_const_variable) |
| 6732 | << getOpenMPClauseName(OMPC_linear); |
| 6733 | bool IsDecl = |
| 6734 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6735 | Diag(VD->getLocation(), |
| 6736 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6737 | << VD; |
| 6738 | continue; |
| 6739 | } |
| 6740 | |
| 6741 | // A list item must be of integral or pointer type. |
| 6742 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 6743 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6744 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 6745 | !Ty->isPointerType())) { |
| 6746 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 6747 | bool IsDecl = |
| 6748 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6749 | Diag(VD->getLocation(), |
| 6750 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6751 | << VD; |
| 6752 | continue; |
| 6753 | } |
| 6754 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6755 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6756 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 6757 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6758 | auto *PrivateRef = buildDeclRefExpr( |
| 6759 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6760 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6761 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6762 | Expr *InitExpr; |
| 6763 | if (LinKind == OMPC_LINEAR_uval) |
| 6764 | InitExpr = VD->getInit(); |
| 6765 | else |
| 6766 | InitExpr = DE; |
| 6767 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6768 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6769 | auto InitRef = buildDeclRefExpr( |
| 6770 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6771 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 6772 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6773 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6774 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6775 | } |
| 6776 | |
| 6777 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6778 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6779 | |
| 6780 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6781 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6782 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 6783 | !Step->isInstantiationDependent() && |
| 6784 | !Step->containsUnexpandedParameterPack()) { |
| 6785 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6786 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6787 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6788 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6789 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6790 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6791 | // Build var to save the step value. |
| 6792 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6793 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6794 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6795 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6796 | ExprResult CalcStep = |
| 6797 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6798 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6799 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6800 | // Warn about zero linear step (it would be probably better specified as |
| 6801 | // making corresponding variables 'const'). |
| 6802 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6803 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 6804 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6805 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 6806 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6807 | if (!IsConstant && CalcStep.isUsable()) { |
| 6808 | // Calculate the step beforehand instead of doing this on each iteration. |
| 6809 | // (This is not used if the number of iterations may be kfold-ed). |
| 6810 | CalcStepExpr = CalcStep.get(); |
| 6811 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6812 | } |
| 6813 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6814 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 6815 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 6816 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6817 | } |
| 6818 | |
| 6819 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 6820 | Expr *NumIterations, Sema &SemaRef, |
| 6821 | Scope *S) { |
| 6822 | // Walk the vars and build update/final expressions for the CodeGen. |
| 6823 | SmallVector<Expr *, 8> Updates; |
| 6824 | SmallVector<Expr *, 8> Finals; |
| 6825 | Expr *Step = Clause.getStep(); |
| 6826 | Expr *CalcStep = Clause.getCalcStep(); |
| 6827 | // OpenMP [2.14.3.7, linear clause] |
| 6828 | // If linear-step is not specified it is assumed to be 1. |
| 6829 | if (Step == nullptr) |
| 6830 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 6831 | else if (CalcStep) |
| 6832 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 6833 | bool HasErrors = false; |
| 6834 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6835 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6836 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6837 | for (auto &RefExpr : Clause.varlists()) { |
| 6838 | Expr *InitExpr = *CurInit; |
| 6839 | |
| 6840 | // Build privatized reference to the current linear var. |
| 6841 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6842 | Expr *CapturedRef; |
| 6843 | if (LinKind == OMPC_LINEAR_uval) |
| 6844 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 6845 | else |
| 6846 | CapturedRef = |
| 6847 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 6848 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 6849 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6850 | |
| 6851 | // Build update: Var = InitExpr + IV * Step |
| 6852 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6853 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6854 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6855 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 6856 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6857 | |
| 6858 | // Build final: Var = InitExpr + NumIterations * Step |
| 6859 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6860 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6861 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6862 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 6863 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6864 | if (!Update.isUsable() || !Final.isUsable()) { |
| 6865 | Updates.push_back(nullptr); |
| 6866 | Finals.push_back(nullptr); |
| 6867 | HasErrors = true; |
| 6868 | } else { |
| 6869 | Updates.push_back(Update.get()); |
| 6870 | Finals.push_back(Final.get()); |
| 6871 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6872 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6873 | } |
| 6874 | Clause.setUpdates(Updates); |
| 6875 | Clause.setFinals(Finals); |
| 6876 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6877 | } |
| 6878 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6879 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 6880 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 6881 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 6882 | |
| 6883 | SmallVector<Expr *, 8> Vars; |
| 6884 | for (auto &RefExpr : VarList) { |
| 6885 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 6886 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6887 | // It will be analyzed later. |
| 6888 | Vars.push_back(RefExpr); |
| 6889 | continue; |
| 6890 | } |
| 6891 | |
| 6892 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6893 | // OpenMP [2.1, C/C++] |
| 6894 | // A list item is a variable name. |
| 6895 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6896 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6897 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6898 | continue; |
| 6899 | } |
| 6900 | |
| 6901 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6902 | |
| 6903 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6904 | // The type of list items appearing in the aligned clause must be |
| 6905 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6906 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6907 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6908 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6909 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 6910 | !Ty->isPointerType())) { |
| 6911 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 6912 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 6913 | bool IsDecl = |
| 6914 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6915 | Diag(VD->getLocation(), |
| 6916 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6917 | << VD; |
| 6918 | continue; |
| 6919 | } |
| 6920 | |
| 6921 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6922 | // A list-item cannot appear in more than one aligned clause. |
| 6923 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 6924 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 6925 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 6926 | << getOpenMPClauseName(OMPC_aligned); |
| 6927 | continue; |
| 6928 | } |
| 6929 | |
| 6930 | Vars.push_back(DE); |
| 6931 | } |
| 6932 | |
| 6933 | // OpenMP [2.8.1, simd construct, Description] |
| 6934 | // The parameter of the aligned clause, alignment, must be a constant |
| 6935 | // positive integer expression. |
| 6936 | // If no optional parameter is specified, implementation-defined default |
| 6937 | // alignments for SIMD instructions on the target platforms are assumed. |
| 6938 | if (Alignment != nullptr) { |
| 6939 | ExprResult AlignResult = |
| 6940 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 6941 | if (AlignResult.isInvalid()) |
| 6942 | return nullptr; |
| 6943 | Alignment = AlignResult.get(); |
| 6944 | } |
| 6945 | if (Vars.empty()) |
| 6946 | return nullptr; |
| 6947 | |
| 6948 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 6949 | EndLoc, Vars, Alignment); |
| 6950 | } |
| 6951 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6952 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 6953 | SourceLocation StartLoc, |
| 6954 | SourceLocation LParenLoc, |
| 6955 | SourceLocation EndLoc) { |
| 6956 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6957 | SmallVector<Expr *, 8> SrcExprs; |
| 6958 | SmallVector<Expr *, 8> DstExprs; |
| 6959 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6960 | for (auto &RefExpr : VarList) { |
| 6961 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 6962 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6963 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6964 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6965 | SrcExprs.push_back(nullptr); |
| 6966 | DstExprs.push_back(nullptr); |
| 6967 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6968 | continue; |
| 6969 | } |
| 6970 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6971 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6972 | // OpenMP [2.1, C/C++] |
| 6973 | // A list item is a variable name. |
| 6974 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6975 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6976 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6977 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6978 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6979 | continue; |
| 6980 | } |
| 6981 | |
| 6982 | Decl *D = DE->getDecl(); |
| 6983 | VarDecl *VD = cast<VarDecl>(D); |
| 6984 | |
| 6985 | QualType Type = VD->getType(); |
| 6986 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6987 | // It will be analyzed later. |
| 6988 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6989 | SrcExprs.push_back(nullptr); |
| 6990 | DstExprs.push_back(nullptr); |
| 6991 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6992 | continue; |
| 6993 | } |
| 6994 | |
| 6995 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 6996 | // A list item that appears in a copyin clause must be threadprivate. |
| 6997 | if (!DSAStack->isThreadPrivate(VD)) { |
| 6998 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6999 | << getOpenMPClauseName(OMPC_copyin) |
| 7000 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7001 | continue; |
| 7002 | } |
| 7003 | |
| 7004 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7005 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7006 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7007 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7008 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7009 | auto *SrcVD = |
| 7010 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 7011 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7012 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7013 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 7014 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7015 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 7016 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7017 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7018 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7019 | // For arrays generate assignment operation for single element and replace |
| 7020 | // it by the original array element in CodeGen. |
| 7021 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7022 | PseudoDstExpr, PseudoSrcExpr); |
| 7023 | if (AssignmentOp.isInvalid()) |
| 7024 | continue; |
| 7025 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7026 | /*DiscardedValue=*/true); |
| 7027 | if (AssignmentOp.isInvalid()) |
| 7028 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7029 | |
| 7030 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 7031 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7032 | SrcExprs.push_back(PseudoSrcExpr); |
| 7033 | DstExprs.push_back(PseudoDstExpr); |
| 7034 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7035 | } |
| 7036 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7037 | if (Vars.empty()) |
| 7038 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7039 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7040 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7041 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7042 | } |
| 7043 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7044 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7045 | SourceLocation StartLoc, |
| 7046 | SourceLocation LParenLoc, |
| 7047 | SourceLocation EndLoc) { |
| 7048 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7049 | SmallVector<Expr *, 8> SrcExprs; |
| 7050 | SmallVector<Expr *, 8> DstExprs; |
| 7051 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7052 | for (auto &RefExpr : VarList) { |
| 7053 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7054 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7055 | // It will be analyzed later. |
| 7056 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7057 | SrcExprs.push_back(nullptr); |
| 7058 | DstExprs.push_back(nullptr); |
| 7059 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7060 | continue; |
| 7061 | } |
| 7062 | |
| 7063 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7064 | // OpenMP [2.1, C/C++] |
| 7065 | // A list item is a variable name. |
| 7066 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7067 | // A list item that appears in a copyin clause must be threadprivate. |
| 7068 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7069 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7070 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7071 | continue; |
| 7072 | } |
| 7073 | |
| 7074 | Decl *D = DE->getDecl(); |
| 7075 | VarDecl *VD = cast<VarDecl>(D); |
| 7076 | |
| 7077 | QualType Type = VD->getType(); |
| 7078 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7079 | // It will be analyzed later. |
| 7080 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7081 | SrcExprs.push_back(nullptr); |
| 7082 | DstExprs.push_back(nullptr); |
| 7083 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7084 | continue; |
| 7085 | } |
| 7086 | |
| 7087 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 7088 | // A list item that appears in a copyprivate clause may not appear in a |
| 7089 | // private or firstprivate clause on the single construct. |
| 7090 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7091 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7092 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 7093 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7094 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7095 | << getOpenMPClauseName(DVar.CKind) |
| 7096 | << getOpenMPClauseName(OMPC_copyprivate); |
| 7097 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7098 | continue; |
| 7099 | } |
| 7100 | |
| 7101 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 7102 | // All list items that appear in a copyprivate clause must be either |
| 7103 | // threadprivate or private in the enclosing context. |
| 7104 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7105 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7106 | if (DVar.CKind == OMPC_shared) { |
| 7107 | Diag(ELoc, diag::err_omp_required_access) |
| 7108 | << getOpenMPClauseName(OMPC_copyprivate) |
| 7109 | << "threadprivate or private in the enclosing context"; |
| 7110 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7111 | continue; |
| 7112 | } |
| 7113 | } |
| 7114 | } |
| 7115 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7116 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7117 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7118 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7119 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 7120 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7121 | bool IsDecl = |
| 7122 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7123 | Diag(VD->getLocation(), |
| 7124 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7125 | << VD; |
| 7126 | continue; |
| 7127 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7128 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7129 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7130 | // A variable of class type (or array thereof) that appears in a |
| 7131 | // copyin clause requires an accessible, unambiguous copy assignment |
| 7132 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7133 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 7134 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7135 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7136 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 7137 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7138 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7139 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7140 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7141 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 7142 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7143 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7144 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7145 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7146 | PseudoDstExpr, PseudoSrcExpr); |
| 7147 | if (AssignmentOp.isInvalid()) |
| 7148 | continue; |
| 7149 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7150 | /*DiscardedValue=*/true); |
| 7151 | if (AssignmentOp.isInvalid()) |
| 7152 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7153 | |
| 7154 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 7155 | // implicitly private. |
| 7156 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7157 | SrcExprs.push_back(PseudoSrcExpr); |
| 7158 | DstExprs.push_back(PseudoDstExpr); |
| 7159 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | if (Vars.empty()) |
| 7163 | return nullptr; |
| 7164 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7165 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 7166 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7167 | } |
| 7168 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7169 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 7170 | SourceLocation StartLoc, |
| 7171 | SourceLocation LParenLoc, |
| 7172 | SourceLocation EndLoc) { |
| 7173 | if (VarList.empty()) |
| 7174 | return nullptr; |
| 7175 | |
| 7176 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 7177 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7178 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7179 | OMPClause * |
| 7180 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 7181 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 7182 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 7183 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7184 | if (DepKind == OMPC_DEPEND_unknown) { |
| 7185 | std::string Values; |
| 7186 | std::string Sep(", "); |
| 7187 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 7188 | Values += "'"; |
| 7189 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 7190 | Values += "'"; |
| 7191 | switch (i) { |
| 7192 | case OMPC_DEPEND_unknown - 2: |
| 7193 | Values += " or "; |
| 7194 | break; |
| 7195 | case OMPC_DEPEND_unknown - 1: |
| 7196 | break; |
| 7197 | default: |
| 7198 | Values += Sep; |
| 7199 | break; |
| 7200 | } |
| 7201 | } |
| 7202 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 7203 | << Values << getOpenMPClauseName(OMPC_depend); |
| 7204 | return nullptr; |
| 7205 | } |
| 7206 | SmallVector<Expr *, 8> Vars; |
| 7207 | for (auto &RefExpr : VarList) { |
| 7208 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7209 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7210 | // It will be analyzed later. |
| 7211 | Vars.push_back(RefExpr); |
| 7212 | continue; |
| 7213 | } |
| 7214 | |
| 7215 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7216 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 7217 | // A variable that is part of another variable (such as a field of a |
| 7218 | // structure) but is not an array element or an array section cannot appear |
| 7219 | // in a depend clause. |
| 7220 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7221 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7222 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7223 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7224 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 7225 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7226 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7227 | !ASE->getBase()->getType()->isArrayType())) { |
| 7228 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7229 | << RefExpr->getSourceRange(); |
| 7230 | continue; |
| 7231 | } |
| 7232 | |
| 7233 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 7234 | } |
| 7235 | |
| 7236 | if (Vars.empty()) |
| 7237 | return nullptr; |
| 7238 | |
| 7239 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 7240 | DepLoc, ColonLoc, Vars); |
| 7241 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7242 | |
| 7243 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 7244 | SourceLocation LParenLoc, |
| 7245 | SourceLocation EndLoc) { |
| 7246 | Expr *ValExpr = Device; |
| 7247 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7248 | !ValExpr->isInstantiationDependent()) { |
| 7249 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7250 | ExprResult Value = PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7251 | if (Value.isInvalid()) |
| 7252 | return nullptr; |
| 7253 | |
| 7254 | // OpenMP [2.9.1, Restrictions] |
| 7255 | // The device expression must evaluate to a non-negative integer value. |
| 7256 | llvm::APSInt Result; |
| 7257 | if (Value.get()->isIntegerConstantExpr(Result, Context) && |
| 7258 | Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7259 | Diag(Loc, diag::err_omp_negative_expression_in_clause) |
| 7260 | << "device" << ValExpr->getSourceRange(); |
| 7261 | return nullptr; |
| 7262 | } |
| 7263 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7264 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7265 | } |