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); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 197 | |
| 198 | /// \brief Returns true if the directive at level \Level matches in the |
| 199 | /// specified \a DPred predicate. |
| 200 | bool hasExplicitDirective( |
| 201 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 202 | unsigned Level); |
| 203 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 204 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 205 | template <class NamedDirectivesPredicate> |
| 206 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 207 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 208 | /// \brief Returns currently analyzed directive. |
| 209 | OpenMPDirectiveKind getCurrentDirective() const { |
| 210 | return Stack.back().Directive; |
| 211 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 212 | /// \brief Returns parent directive. |
| 213 | OpenMPDirectiveKind getParentDirective() const { |
| 214 | if (Stack.size() > 2) |
| 215 | return Stack[Stack.size() - 2].Directive; |
| 216 | return OMPD_unknown; |
| 217 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 218 | |
| 219 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 220 | void setDefaultDSANone(SourceLocation Loc) { |
| 221 | Stack.back().DefaultAttr = DSA_none; |
| 222 | Stack.back().DefaultAttrLoc = Loc; |
| 223 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 224 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 225 | void setDefaultDSAShared(SourceLocation Loc) { |
| 226 | Stack.back().DefaultAttr = DSA_shared; |
| 227 | Stack.back().DefaultAttrLoc = Loc; |
| 228 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 229 | |
| 230 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 231 | return Stack.back().DefaultAttr; |
| 232 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 233 | SourceLocation getDefaultDSALocation() const { |
| 234 | return Stack.back().DefaultAttrLoc; |
| 235 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 236 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 237 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 238 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 239 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 240 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 243 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 244 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 245 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 246 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 247 | } |
| 248 | /// \brief Returns true, if parent region is ordered (has associated |
| 249 | /// 'ordered' clause), false - otherwise. |
| 250 | bool isParentOrderedRegion() const { |
| 251 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 252 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 253 | return false; |
| 254 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 255 | /// \brief Returns optional parameter for the ordered region. |
| 256 | Expr *getParentOrderedRegionParam() const { |
| 257 | if (Stack.size() > 2) |
| 258 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 259 | return nullptr; |
| 260 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 261 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 262 | void setNowaitRegion(bool IsNowait = true) { |
| 263 | Stack.back().NowaitRegion = IsNowait; |
| 264 | } |
| 265 | /// \brief Returns true, if parent region is nowait (has associated |
| 266 | /// 'nowait' clause), false - otherwise. |
| 267 | bool isParentNowaitRegion() const { |
| 268 | if (Stack.size() > 2) |
| 269 | return Stack[Stack.size() - 2].NowaitRegion; |
| 270 | return false; |
| 271 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 272 | /// \brief Marks parent region as cancel region. |
| 273 | void setParentCancelRegion(bool Cancel = true) { |
| 274 | if (Stack.size() > 2) |
| 275 | Stack[Stack.size() - 2].CancelRegion = |
| 276 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 277 | } |
| 278 | /// \brief Return true if current region has inner cancel construct. |
| 279 | bool isCancelRegion() const { |
| 280 | return Stack.back().CancelRegion; |
| 281 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 282 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 283 | /// \brief Set collapse value for the region. |
| 284 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 285 | /// \brief Return collapse value for region. |
| 286 | unsigned getCollapseNumber() const { |
| 287 | return Stack.back().CollapseNumber; |
| 288 | } |
| 289 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 290 | /// \brief Marks current target region as one with closely nested teams |
| 291 | /// region. |
| 292 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 293 | if (Stack.size() > 2) |
| 294 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 295 | } |
| 296 | /// \brief Returns true, if current region has closely nested teams region. |
| 297 | bool hasInnerTeamsRegion() const { |
| 298 | return getInnerTeamsRegionLoc().isValid(); |
| 299 | } |
| 300 | /// \brief Returns location of the nested teams region (if any). |
| 301 | SourceLocation getInnerTeamsRegionLoc() const { |
| 302 | if (Stack.size() > 1) |
| 303 | return Stack.back().InnerTeamsRegionLoc; |
| 304 | return SourceLocation(); |
| 305 | } |
| 306 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 307 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 308 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 309 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 310 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 311 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 312 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 313 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 314 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 315 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 316 | |
| 317 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 318 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 319 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 320 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 321 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 322 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 323 | // in a region but not in construct] |
| 324 | // File-scope or namespace-scope variables referenced in called routines |
| 325 | // in the region are shared unless they appear in a threadprivate |
| 326 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 327 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 328 | DVar.CKind = OMPC_shared; |
| 329 | |
| 330 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 331 | // in a region but not in construct] |
| 332 | // Variables with static storage duration that are declared in called |
| 333 | // routines in the region are shared. |
| 334 | if (D->hasGlobalStorage()) |
| 335 | DVar.CKind = OMPC_shared; |
| 336 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 337 | return DVar; |
| 338 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 339 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 340 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 341 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 342 | // in a Construct, C/C++, predetermined, p.1] |
| 343 | // Variables with automatic storage duration that are declared in a scope |
| 344 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 345 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 346 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 347 | DVar.CKind = OMPC_private; |
| 348 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 351 | // Explicitly specified attributes and local variables with predetermined |
| 352 | // attributes. |
| 353 | if (Iter->SharingMap.count(D)) { |
| 354 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 355 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 356 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 357 | return DVar; |
| 358 | } |
| 359 | |
| 360 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 361 | // in a Construct, C/C++, implicitly determined, p.1] |
| 362 | // In a parallel or task construct, the data-sharing attributes of these |
| 363 | // variables are determined by the default clause, if present. |
| 364 | switch (Iter->DefaultAttr) { |
| 365 | case DSA_shared: |
| 366 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 367 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 368 | return DVar; |
| 369 | case DSA_none: |
| 370 | return DVar; |
| 371 | case DSA_unspecified: |
| 372 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 373 | // in a Construct, implicitly determined, p.2] |
| 374 | // In a parallel construct, if no default clause is present, these |
| 375 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 376 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 377 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 378 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 379 | DVar.CKind = OMPC_shared; |
| 380 | return DVar; |
| 381 | } |
| 382 | |
| 383 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 384 | // in a Construct, implicitly determined, p.4] |
| 385 | // In a task construct, if no default clause is present, a variable that in |
| 386 | // the enclosing context is determined to be shared by all implicit tasks |
| 387 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 388 | if (DVar.DKind == OMPD_task) { |
| 389 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 390 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 391 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 392 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 393 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 394 | // in a Construct, implicitly determined, p.6] |
| 395 | // In a task construct, if no default clause is present, a variable |
| 396 | // whose data-sharing attribute is not determined by the rules above is |
| 397 | // firstprivate. |
| 398 | DVarTemp = getDSA(I, D); |
| 399 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 400 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 401 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 402 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 403 | return DVar; |
| 404 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 405 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 406 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 407 | } |
| 408 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 409 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 410 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 411 | return DVar; |
| 412 | } |
| 413 | } |
| 414 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 415 | // in a Construct, implicitly determined, p.3] |
| 416 | // For constructs other than task, if no default clause is present, these |
| 417 | // variables inherit their data-sharing attributes from the enclosing |
| 418 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 419 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 422 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 423 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 424 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 425 | auto It = Stack.back().AlignedMap.find(D); |
| 426 | if (It == Stack.back().AlignedMap.end()) { |
| 427 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 428 | Stack.back().AlignedMap[D] = NewDE; |
| 429 | return nullptr; |
| 430 | } else { |
| 431 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 432 | return It->second; |
| 433 | } |
| 434 | return nullptr; |
| 435 | } |
| 436 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 437 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 438 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 439 | D = D->getCanonicalDecl(); |
| 440 | Stack.back().LCVSet.insert(D); |
| 441 | } |
| 442 | |
| 443 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 444 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 445 | D = D->getCanonicalDecl(); |
| 446 | return Stack.back().LCVSet.count(D) > 0; |
| 447 | } |
| 448 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 449 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 450 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 451 | if (A == OMPC_threadprivate) { |
| 452 | Stack[0].SharingMap[D].Attributes = A; |
| 453 | Stack[0].SharingMap[D].RefExpr = E; |
| 454 | } else { |
| 455 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 456 | Stack.back().SharingMap[D].Attributes = A; |
| 457 | Stack.back().SharingMap[D].RefExpr = E; |
| 458 | } |
| 459 | } |
| 460 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 461 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 462 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 463 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 464 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 465 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 466 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 467 | ++I; |
| 468 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 469 | if (I == E) |
| 470 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 471 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 472 | Scope *CurScope = getCurScope(); |
| 473 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 474 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 475 | } |
| 476 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 478 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 481 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 482 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 483 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 484 | DeclContext *DC = SemaRef.CurContext; |
| 485 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 486 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 487 | VarDecl *Decl = |
| 488 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 489 | if (Attrs) { |
| 490 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 491 | I != E; ++I) |
| 492 | Decl->addAttr(*I); |
| 493 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 494 | Decl->setImplicit(); |
| 495 | return Decl; |
| 496 | } |
| 497 | |
| 498 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 499 | SourceLocation Loc, |
| 500 | bool RefersToCapture = false) { |
| 501 | D->setReferenced(); |
| 502 | D->markUsed(S.Context); |
| 503 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 504 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 505 | VK_LValue); |
| 506 | } |
| 507 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 508 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 509 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 510 | DSAVarData DVar; |
| 511 | |
| 512 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 513 | // in a Construct, C/C++, predetermined, p.1] |
| 514 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 515 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 516 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 517 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 518 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 519 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 520 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 521 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 522 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 523 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 524 | } |
| 525 | if (Stack[0].SharingMap.count(D)) { |
| 526 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 527 | DVar.CKind = OMPC_threadprivate; |
| 528 | return DVar; |
| 529 | } |
| 530 | |
| 531 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 532 | // in a Construct, C/C++, predetermined, p.1] |
| 533 | // Variables with automatic storage duration that are declared in a scope |
| 534 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 535 | OpenMPDirectiveKind Kind = |
| 536 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 537 | auto StartI = std::next(Stack.rbegin()); |
| 538 | auto EndI = std::prev(Stack.rend()); |
| 539 | if (FromParent && StartI != EndI) { |
| 540 | StartI = std::next(StartI); |
| 541 | } |
| 542 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 543 | if (isOpenMPLocal(D, StartI) && |
| 544 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 545 | D->getStorageClass() == SC_None)) || |
| 546 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 547 | DVar.CKind = OMPC_private; |
| 548 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 549 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 550 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 551 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 552 | // in a Construct, C/C++, predetermined, p.4] |
| 553 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 554 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 555 | // in a Construct, C/C++, predetermined, p.7] |
| 556 | // Variables with static storage duration that are declared in a scope |
| 557 | // inside the construct are shared. |
Kelvin Li | 4eea8c6 | 2015-09-15 18:56:58 +0000 | [diff] [blame] | 558 | if (D->isStaticDataMember()) { |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 559 | DSAVarData DVarTemp = |
| 560 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 561 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 562 | return DVar; |
| 563 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 564 | DVar.CKind = OMPC_shared; |
| 565 | return DVar; |
| 566 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 570 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 571 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 572 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 573 | // in a Construct, C/C++, predetermined, p.6] |
| 574 | // Variables with const qualified type having no mutable member are |
| 575 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 576 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 577 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 578 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 579 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 580 | // Variables with const-qualified type having no mutable member may be |
| 581 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 582 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 583 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 584 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 585 | return DVar; |
| 586 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 587 | DVar.CKind = OMPC_shared; |
| 588 | return DVar; |
| 589 | } |
| 590 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 591 | // Explicitly specified attributes and local variables with predetermined |
| 592 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 593 | auto I = std::prev(StartI); |
| 594 | if (I->SharingMap.count(D)) { |
| 595 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 596 | DVar.CKind = I->SharingMap[D].Attributes; |
| 597 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | return DVar; |
| 601 | } |
| 602 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 603 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 604 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 605 | auto StartI = Stack.rbegin(); |
| 606 | auto EndI = std::prev(Stack.rend()); |
| 607 | if (FromParent && StartI != EndI) { |
| 608 | StartI = std::next(StartI); |
| 609 | } |
| 610 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 611 | } |
| 612 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 613 | template <class ClausesPredicate, class DirectivesPredicate> |
| 614 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 615 | DirectivesPredicate DPred, |
| 616 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 617 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 618 | auto StartI = std::next(Stack.rbegin()); |
| 619 | auto EndI = std::prev(Stack.rend()); |
| 620 | if (FromParent && StartI != EndI) { |
| 621 | StartI = std::next(StartI); |
| 622 | } |
| 623 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 624 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 625 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 626 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 627 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 628 | return DVar; |
| 629 | } |
| 630 | return DSAVarData(); |
| 631 | } |
| 632 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 633 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 634 | DSAStackTy::DSAVarData |
| 635 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 636 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 637 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 638 | auto StartI = std::next(Stack.rbegin()); |
| 639 | auto EndI = std::prev(Stack.rend()); |
| 640 | if (FromParent && StartI != EndI) { |
| 641 | StartI = std::next(StartI); |
| 642 | } |
| 643 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 644 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 645 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 646 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 647 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 648 | return DVar; |
| 649 | return DSAVarData(); |
| 650 | } |
| 651 | return DSAVarData(); |
| 652 | } |
| 653 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 654 | bool DSAStackTy::hasExplicitDSA( |
| 655 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 656 | unsigned Level) { |
| 657 | if (CPred(ClauseKindMode)) |
| 658 | return true; |
| 659 | if (isClauseParsingMode()) |
| 660 | ++Level; |
| 661 | D = D->getCanonicalDecl(); |
| 662 | auto StartI = Stack.rbegin(); |
| 663 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 664 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 665 | return false; |
| 666 | std::advance(StartI, Level); |
| 667 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 668 | CPred(StartI->SharingMap[D].Attributes); |
| 669 | } |
| 670 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 671 | bool DSAStackTy::hasExplicitDirective( |
| 672 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 673 | unsigned Level) { |
| 674 | if (isClauseParsingMode()) |
| 675 | ++Level; |
| 676 | auto StartI = Stack.rbegin(); |
| 677 | auto EndI = std::prev(Stack.rend()); |
| 678 | if (std::distance(StartI, EndI) <= (int)Level) |
| 679 | return false; |
| 680 | std::advance(StartI, Level); |
| 681 | return DPred(StartI->Directive); |
| 682 | } |
| 683 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 684 | template <class NamedDirectivesPredicate> |
| 685 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 686 | auto StartI = std::next(Stack.rbegin()); |
| 687 | auto EndI = std::prev(Stack.rend()); |
| 688 | if (FromParent && StartI != EndI) { |
| 689 | StartI = std::next(StartI); |
| 690 | } |
| 691 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 692 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 693 | return true; |
| 694 | } |
| 695 | return false; |
| 696 | } |
| 697 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 698 | void Sema::InitDataSharingAttributesStack() { |
| 699 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 700 | } |
| 701 | |
| 702 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 703 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 704 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 705 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 706 | VD = VD->getCanonicalDecl(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 707 | |
| 708 | // If we are attempting to capture a global variable in a directive with |
| 709 | // 'target' we return true so that this global is also mapped to the device. |
| 710 | // |
| 711 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 712 | // then it should not be captured. Therefore, an extra check has to be |
| 713 | // inserted here once support for 'declare target' is added. |
| 714 | // |
| 715 | if (!VD->hasLocalStorage()) { |
| 716 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 717 | !DSAStack->isClauseParsingMode()) { |
| 718 | return true; |
| 719 | } |
| 720 | if (DSAStack->getCurScope() && |
| 721 | DSAStack->hasDirective( |
| 722 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 723 | SourceLocation Loc) -> bool { |
| 724 | return isOpenMPTargetDirective(K); |
| 725 | }, |
| 726 | false)) { |
| 727 | return true; |
| 728 | } |
| 729 | } |
| 730 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 731 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 732 | (!DSAStack->isClauseParsingMode() || |
| 733 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 734 | if (DSAStack->isLoopControlVariable(VD) || |
| 735 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 736 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 737 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 738 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 739 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 740 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 741 | return true; |
| 742 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 743 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 744 | return DVarPrivate.CKind != OMPC_unknown; |
| 745 | } |
| 746 | return false; |
| 747 | } |
| 748 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 749 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 750 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 751 | return DSAStack->hasExplicitDSA( |
| 752 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 753 | } |
| 754 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 755 | bool Sema::isOpenMPTargetCapturedVar(VarDecl *VD, unsigned Level) { |
| 756 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 757 | // Return true if the current level is no longer enclosed in a target region. |
| 758 | |
| 759 | return !VD->hasLocalStorage() && |
| 760 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 761 | } |
| 762 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 763 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 764 | |
| 765 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 766 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 767 | Scope *CurScope, SourceLocation Loc) { |
| 768 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 769 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 770 | } |
| 771 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 772 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 773 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 776 | void Sema::EndOpenMPClause() { |
| 777 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 778 | } |
| 779 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 780 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 781 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 782 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 783 | // clause requires an accessible, unambiguous default constructor for the |
| 784 | // class type, unless the list item is also specified in a firstprivate |
| 785 | // clause. |
| 786 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 787 | for (auto *C : D->clauses()) { |
| 788 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 789 | SmallVector<Expr *, 8> PrivateCopies; |
| 790 | for (auto *DE : Clause->varlists()) { |
| 791 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 792 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 793 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 794 | } |
| 795 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 796 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 797 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 798 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 799 | // Generate helper private variable and initialize it with the |
| 800 | // default value. The address of the original variable is replaced |
| 801 | // by the address of the new private variable in CodeGen. This new |
| 802 | // variable is not added to IdResolver, so the code in the OpenMP |
| 803 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 804 | auto *VDPrivate = buildVarDecl( |
| 805 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 806 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 807 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 808 | if (VDPrivate->isInvalidDecl()) |
| 809 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 810 | PrivateCopies.push_back(buildDeclRefExpr( |
| 811 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 812 | } else { |
| 813 | // The variable is also a firstprivate, so initialization sequence |
| 814 | // for private copy is generated already. |
| 815 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 816 | } |
| 817 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 818 | // Set initializers to private copies if no errors were found. |
| 819 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 820 | Clause->setPrivateCopies(PrivateCopies); |
| 821 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 826 | DSAStack->pop(); |
| 827 | DiscardCleanupsInEvaluationContext(); |
| 828 | PopExpressionEvaluationContext(); |
| 829 | } |
| 830 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 831 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 832 | Expr *NumIterations, Sema &SemaRef, |
| 833 | Scope *S); |
| 834 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 835 | namespace { |
| 836 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 837 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 838 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 839 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 840 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 841 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 842 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 843 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 844 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 845 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 846 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 847 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 848 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 849 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 850 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 851 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 852 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 853 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 854 | |
| 855 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 856 | CXXScopeSpec &ScopeSpec, |
| 857 | const DeclarationNameInfo &Id) { |
| 858 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 859 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 860 | |
| 861 | if (Lookup.isAmbiguous()) |
| 862 | return ExprError(); |
| 863 | |
| 864 | VarDecl *VD; |
| 865 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 866 | if (TypoCorrection Corrected = CorrectTypo( |
| 867 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 868 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 869 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 870 | PDiag(Lookup.empty() |
| 871 | ? diag::err_undeclared_var_use_suggest |
| 872 | : diag::err_omp_expected_var_arg_suggest) |
| 873 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 874 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 875 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 876 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 877 | : diag::err_omp_expected_var_arg) |
| 878 | << Id.getName(); |
| 879 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 880 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 881 | } else { |
| 882 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 883 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 884 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 885 | return ExprError(); |
| 886 | } |
| 887 | } |
| 888 | Lookup.suppressDiagnostics(); |
| 889 | |
| 890 | // OpenMP [2.9.2, Syntax, C/C++] |
| 891 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 892 | if (!VD->hasGlobalStorage()) { |
| 893 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 894 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 895 | bool IsDecl = |
| 896 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 897 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 898 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 899 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 900 | return ExprError(); |
| 901 | } |
| 902 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 903 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 904 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 905 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 906 | // A threadprivate directive for file-scope variables must appear outside |
| 907 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 908 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 909 | !getCurLexicalContext()->isTranslationUnit()) { |
| 910 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 911 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 912 | bool IsDecl = |
| 913 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 914 | Diag(VD->getLocation(), |
| 915 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 916 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 917 | return ExprError(); |
| 918 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 919 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 920 | // A threadprivate directive for static class member variables must appear |
| 921 | // in the class definition, in the same scope in which the member |
| 922 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 923 | if (CanonicalVD->isStaticDataMember() && |
| 924 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 925 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 926 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 927 | bool IsDecl = |
| 928 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 929 | Diag(VD->getLocation(), |
| 930 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 931 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 932 | return ExprError(); |
| 933 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 934 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 935 | // A threadprivate directive for namespace-scope variables must appear |
| 936 | // outside any definition or declaration other than the namespace |
| 937 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 938 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 939 | (!getCurLexicalContext()->isFileContext() || |
| 940 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 941 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 942 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 943 | bool IsDecl = |
| 944 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 945 | Diag(VD->getLocation(), |
| 946 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 947 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 948 | return ExprError(); |
| 949 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 950 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 951 | // A threadprivate directive for static block-scope variables must appear |
| 952 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 953 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 954 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 955 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 956 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 957 | bool IsDecl = |
| 958 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 959 | Diag(VD->getLocation(), |
| 960 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 961 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 962 | return ExprError(); |
| 963 | } |
| 964 | |
| 965 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 966 | // A threadprivate directive must lexically precede all references to any |
| 967 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 968 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 969 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 970 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 971 | return ExprError(); |
| 972 | } |
| 973 | |
| 974 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 975 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 976 | return DE; |
| 977 | } |
| 978 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 979 | Sema::DeclGroupPtrTy |
| 980 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 981 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 982 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 983 | CurContext->addDecl(D); |
| 984 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 985 | } |
| 986 | return DeclGroupPtrTy(); |
| 987 | } |
| 988 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 989 | namespace { |
| 990 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 991 | Sema &SemaRef; |
| 992 | |
| 993 | public: |
| 994 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 995 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 996 | if (VD->hasLocalStorage()) { |
| 997 | SemaRef.Diag(E->getLocStart(), |
| 998 | diag::err_omp_local_var_in_threadprivate_init) |
| 999 | << E->getSourceRange(); |
| 1000 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1001 | << VD << VD->getSourceRange(); |
| 1002 | return true; |
| 1003 | } |
| 1004 | } |
| 1005 | return false; |
| 1006 | } |
| 1007 | bool VisitStmt(const Stmt *S) { |
| 1008 | for (auto Child : S->children()) { |
| 1009 | if (Child && Visit(Child)) |
| 1010 | return true; |
| 1011 | } |
| 1012 | return false; |
| 1013 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1014 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1015 | }; |
| 1016 | } // namespace |
| 1017 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1018 | OMPThreadPrivateDecl * |
| 1019 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1020 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1021 | for (auto &RefExpr : VarList) { |
| 1022 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1023 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1024 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1025 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1026 | QualType QType = VD->getType(); |
| 1027 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1028 | // It will be analyzed later. |
| 1029 | Vars.push_back(DE); |
| 1030 | continue; |
| 1031 | } |
| 1032 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1033 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1034 | // A threadprivate variable must not have an incomplete type. |
| 1035 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1036 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1037 | continue; |
| 1038 | } |
| 1039 | |
| 1040 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1041 | // A threadprivate variable must not have a reference type. |
| 1042 | if (VD->getType()->isReferenceType()) { |
| 1043 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1044 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1045 | bool IsDecl = |
| 1046 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1047 | Diag(VD->getLocation(), |
| 1048 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1049 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1050 | continue; |
| 1051 | } |
| 1052 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1053 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1054 | // the corresponding diagnostic. |
| 1055 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1056 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1057 | getLangOpts().OpenMPUseTLS && |
| 1058 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1059 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1060 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1061 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1062 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1063 | bool IsDecl = |
| 1064 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1065 | Diag(VD->getLocation(), |
| 1066 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1067 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1068 | continue; |
| 1069 | } |
| 1070 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1071 | // Check if initial value of threadprivate variable reference variable with |
| 1072 | // local storage (it is not supported by runtime). |
| 1073 | if (auto Init = VD->getAnyInitializer()) { |
| 1074 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1075 | if (Checker.Visit(Init)) |
| 1076 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1079 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1080 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1081 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1082 | Context, SourceRange(Loc, Loc))); |
| 1083 | if (auto *ML = Context.getASTMutationListener()) |
| 1084 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1085 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1086 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1087 | if (!Vars.empty()) { |
| 1088 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1089 | Vars); |
| 1090 | D->setAccess(AS_public); |
| 1091 | } |
| 1092 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1093 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1094 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1095 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1096 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1097 | bool IsLoopIterVar = false) { |
| 1098 | if (DVar.RefExpr) { |
| 1099 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1100 | << getOpenMPClauseName(DVar.CKind); |
| 1101 | return; |
| 1102 | } |
| 1103 | enum { |
| 1104 | PDSA_StaticMemberShared, |
| 1105 | PDSA_StaticLocalVarShared, |
| 1106 | PDSA_LoopIterVarPrivate, |
| 1107 | PDSA_LoopIterVarLinear, |
| 1108 | PDSA_LoopIterVarLastprivate, |
| 1109 | PDSA_ConstVarShared, |
| 1110 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1111 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1112 | PDSA_LocalVarPrivate, |
| 1113 | PDSA_Implicit |
| 1114 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1115 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1116 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1117 | if (IsLoopIterVar) { |
| 1118 | if (DVar.CKind == OMPC_private) |
| 1119 | Reason = PDSA_LoopIterVarPrivate; |
| 1120 | else if (DVar.CKind == OMPC_lastprivate) |
| 1121 | Reason = PDSA_LoopIterVarLastprivate; |
| 1122 | else |
| 1123 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1124 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1125 | Reason = PDSA_TaskVarFirstprivate; |
| 1126 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1127 | } else if (VD->isStaticLocal()) |
| 1128 | Reason = PDSA_StaticLocalVarShared; |
| 1129 | else if (VD->isStaticDataMember()) |
| 1130 | Reason = PDSA_StaticMemberShared; |
| 1131 | else if (VD->isFileVarDecl()) |
| 1132 | Reason = PDSA_GlobalVarShared; |
| 1133 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1134 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1135 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1136 | ReportHint = true; |
| 1137 | Reason = PDSA_LocalVarPrivate; |
| 1138 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1139 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1140 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1141 | << Reason << ReportHint |
| 1142 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1143 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1144 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1145 | << getOpenMPClauseName(DVar.CKind); |
| 1146 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1149 | namespace { |
| 1150 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1151 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1152 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1153 | bool ErrorFound; |
| 1154 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1155 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1156 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1157 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1158 | public: |
| 1159 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1160 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1161 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1162 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1163 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1164 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1165 | auto DVar = Stack->getTopDSA(VD, false); |
| 1166 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1167 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1168 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1169 | auto ELoc = E->getExprLoc(); |
| 1170 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1171 | // The default(none) clause requires that each variable that is referenced |
| 1172 | // in the construct, and does not have a predetermined data-sharing |
| 1173 | // attribute, must have its data-sharing attribute explicitly determined |
| 1174 | // by being listed in a data-sharing attribute clause. |
| 1175 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1176 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1177 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1178 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1179 | return; |
| 1180 | } |
| 1181 | |
| 1182 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1183 | // A list item that appears in a reduction clause of the innermost |
| 1184 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1185 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1186 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1187 | [](OpenMPDirectiveKind K) -> bool { |
| 1188 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1189 | isOpenMPWorksharingDirective(K) || |
| 1190 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1191 | }, |
| 1192 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1193 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1194 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1195 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1196 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1197 | return; |
| 1198 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1199 | |
| 1200 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1201 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1202 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1203 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1204 | } |
| 1205 | } |
| 1206 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1207 | for (auto *C : S->clauses()) { |
| 1208 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1209 | // for task directives. |
| 1210 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1211 | for (auto *CC : C->children()) { |
| 1212 | if (CC) |
| 1213 | Visit(CC); |
| 1214 | } |
| 1215 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1216 | } |
| 1217 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1218 | for (auto *C : S->children()) { |
| 1219 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1220 | Visit(C); |
| 1221 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1222 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1223 | |
| 1224 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1225 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1226 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1227 | return VarsWithInheritedDSA; |
| 1228 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1229 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1230 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1231 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1232 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1233 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1234 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1235 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1236 | switch (DKind) { |
| 1237 | case OMPD_parallel: { |
| 1238 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1239 | QualType KmpInt32PtrTy = |
| 1240 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1241 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1242 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1243 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1244 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1245 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1246 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1247 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1248 | break; |
| 1249 | } |
| 1250 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1251 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1252 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1253 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1254 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1255 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1256 | break; |
| 1257 | } |
| 1258 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1259 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1260 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1261 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1262 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1263 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1264 | break; |
| 1265 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1266 | case OMPD_for_simd: { |
| 1267 | Sema::CapturedParamNameType Params[] = { |
| 1268 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1269 | }; |
| 1270 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1271 | Params); |
| 1272 | break; |
| 1273 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1274 | case OMPD_sections: { |
| 1275 | Sema::CapturedParamNameType Params[] = { |
| 1276 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1277 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1278 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1279 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1280 | break; |
| 1281 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1282 | case OMPD_section: { |
| 1283 | Sema::CapturedParamNameType Params[] = { |
| 1284 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1285 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1286 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1287 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1288 | break; |
| 1289 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1290 | case OMPD_single: { |
| 1291 | Sema::CapturedParamNameType Params[] = { |
| 1292 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1293 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1294 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1295 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1296 | break; |
| 1297 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1298 | case OMPD_master: { |
| 1299 | Sema::CapturedParamNameType Params[] = { |
| 1300 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1301 | }; |
| 1302 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1303 | Params); |
| 1304 | break; |
| 1305 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1306 | case OMPD_critical: { |
| 1307 | Sema::CapturedParamNameType Params[] = { |
| 1308 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1309 | }; |
| 1310 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1311 | Params); |
| 1312 | break; |
| 1313 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1314 | case OMPD_parallel_for: { |
| 1315 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1316 | QualType KmpInt32PtrTy = |
| 1317 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1318 | Sema::CapturedParamNameType Params[] = { |
| 1319 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1320 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1321 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1322 | }; |
| 1323 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1324 | Params); |
| 1325 | break; |
| 1326 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1327 | case OMPD_parallel_for_simd: { |
| 1328 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1329 | QualType KmpInt32PtrTy = |
| 1330 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1331 | Sema::CapturedParamNameType Params[] = { |
| 1332 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1333 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1334 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1335 | }; |
| 1336 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1337 | Params); |
| 1338 | break; |
| 1339 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1340 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1341 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1342 | QualType KmpInt32PtrTy = |
| 1343 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1344 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1345 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1346 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1347 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1348 | }; |
| 1349 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1350 | Params); |
| 1351 | break; |
| 1352 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1353 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1354 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1355 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1356 | FunctionProtoType::ExtProtoInfo EPI; |
| 1357 | EPI.Variadic = true; |
| 1358 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1359 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1360 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1361 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1362 | std::make_pair(".privates.", |
| 1363 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1364 | std::make_pair( |
| 1365 | ".copy_fn.", |
| 1366 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1367 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1368 | }; |
| 1369 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1370 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1371 | // Mark this captured region as inlined, because we don't use outlined |
| 1372 | // function directly. |
| 1373 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1374 | AlwaysInlineAttr::CreateImplicit( |
| 1375 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1376 | break; |
| 1377 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1378 | case OMPD_ordered: { |
| 1379 | Sema::CapturedParamNameType Params[] = { |
| 1380 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1381 | }; |
| 1382 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1383 | Params); |
| 1384 | break; |
| 1385 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1386 | case OMPD_atomic: { |
| 1387 | Sema::CapturedParamNameType Params[] = { |
| 1388 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1389 | }; |
| 1390 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1391 | Params); |
| 1392 | break; |
| 1393 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1394 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1395 | case OMPD_target: { |
| 1396 | Sema::CapturedParamNameType Params[] = { |
| 1397 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1398 | }; |
| 1399 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1400 | Params); |
| 1401 | break; |
| 1402 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1403 | case OMPD_teams: { |
| 1404 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1405 | QualType KmpInt32PtrTy = |
| 1406 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1407 | Sema::CapturedParamNameType Params[] = { |
| 1408 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1409 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1410 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1411 | }; |
| 1412 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1413 | Params); |
| 1414 | break; |
| 1415 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1416 | case OMPD_taskgroup: { |
| 1417 | Sema::CapturedParamNameType Params[] = { |
| 1418 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1419 | }; |
| 1420 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1421 | Params); |
| 1422 | break; |
| 1423 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1424 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1425 | case OMPD_taskyield: |
| 1426 | case OMPD_barrier: |
| 1427 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1428 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1429 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1430 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1431 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1432 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1433 | llvm_unreachable("Unknown OpenMP directive"); |
| 1434 | } |
| 1435 | } |
| 1436 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1437 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1438 | ArrayRef<OMPClause *> Clauses) { |
| 1439 | if (!S.isUsable()) { |
| 1440 | ActOnCapturedRegionError(); |
| 1441 | return StmtError(); |
| 1442 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1443 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1444 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1445 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1446 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1447 | (getLangOpts().OpenMPUseTLS && |
| 1448 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1449 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1450 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1451 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1452 | for (auto *VarRef : Clause->children()) { |
| 1453 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1454 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1455 | } |
| 1456 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1457 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1458 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1459 | Clause->getClauseKind() == OMPC_schedule) { |
| 1460 | // Mark all variables in private list clauses as used in inner region. |
| 1461 | // Required for proper codegen of combined directives. |
| 1462 | // TODO: add processing for other clauses. |
| 1463 | if (auto *E = cast_or_null<Expr>( |
| 1464 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1465 | MarkDeclarationsReferencedInExpr(E); |
| 1466 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1467 | } |
| 1468 | } |
| 1469 | return ActOnCapturedRegionEnd(S.get()); |
| 1470 | } |
| 1471 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1472 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1473 | OpenMPDirectiveKind CurrentRegion, |
| 1474 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1475 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1476 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1477 | // Allowed nesting of constructs |
| 1478 | // +------------------+-----------------+------------------------------------+ |
| 1479 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1480 | // +------------------+-----------------+------------------------------------+ |
| 1481 | // | parallel | parallel | * | |
| 1482 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1483 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1484 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1485 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1486 | // | parallel | simd | * | |
| 1487 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1488 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1489 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1490 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1491 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1492 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1493 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1494 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1495 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1496 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1497 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1498 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1499 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1500 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1501 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1502 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1503 | // | parallel | cancellation | | |
| 1504 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1505 | // | parallel | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1506 | // +------------------+-----------------+------------------------------------+ |
| 1507 | // | for | parallel | * | |
| 1508 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1509 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1510 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1511 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1512 | // | for | simd | * | |
| 1513 | // | for | sections | + | |
| 1514 | // | for | section | + | |
| 1515 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1516 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1517 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1518 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1519 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1520 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1521 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1522 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1523 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1524 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1525 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1526 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1527 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1528 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1529 | // | for | cancellation | | |
| 1530 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1531 | // | for | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1532 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1533 | // | master | parallel | * | |
| 1534 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1535 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1536 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1537 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1538 | // | master | simd | * | |
| 1539 | // | master | sections | + | |
| 1540 | // | master | section | + | |
| 1541 | // | master | single | + | |
| 1542 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1543 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1544 | // | master |parallel sections| * | |
| 1545 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1546 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1547 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1548 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1549 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1550 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1551 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1552 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1553 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1554 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1555 | // | master | cancellation | | |
| 1556 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1557 | // | master | cancel | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1558 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1559 | // | critical | parallel | * | |
| 1560 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1561 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1562 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1563 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1564 | // | critical | simd | * | |
| 1565 | // | critical | sections | + | |
| 1566 | // | critical | section | + | |
| 1567 | // | critical | single | + | |
| 1568 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1569 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1570 | // | critical |parallel sections| * | |
| 1571 | // | critical | task | * | |
| 1572 | // | critical | taskyield | * | |
| 1573 | // | critical | barrier | + | |
| 1574 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1575 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1576 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1577 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1578 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1579 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1580 | // | critical | cancellation | | |
| 1581 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1582 | // | critical | cancel | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1583 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1584 | // | simd | parallel | | |
| 1585 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1586 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1587 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1588 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1589 | // | simd | simd | | |
| 1590 | // | simd | sections | | |
| 1591 | // | simd | section | | |
| 1592 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1593 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1594 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1595 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1596 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1597 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1598 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1599 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1600 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1601 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1602 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1603 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1604 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1605 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1606 | // | simd | cancellation | | |
| 1607 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1608 | // | simd | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1609 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1610 | // | for simd | parallel | | |
| 1611 | // | for simd | for | | |
| 1612 | // | for simd | for simd | | |
| 1613 | // | for simd | master | | |
| 1614 | // | for simd | critical | | |
| 1615 | // | for simd | simd | | |
| 1616 | // | for simd | sections | | |
| 1617 | // | for simd | section | | |
| 1618 | // | for simd | single | | |
| 1619 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1620 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1621 | // | for simd |parallel sections| | |
| 1622 | // | for simd | task | | |
| 1623 | // | for simd | taskyield | | |
| 1624 | // | for simd | barrier | | |
| 1625 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1626 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1627 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1628 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1629 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1630 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1631 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1632 | // | for simd | cancellation | | |
| 1633 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1634 | // | for simd | cancel | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1635 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1636 | // | parallel for simd| parallel | | |
| 1637 | // | parallel for simd| for | | |
| 1638 | // | parallel for simd| for simd | | |
| 1639 | // | parallel for simd| master | | |
| 1640 | // | parallel for simd| critical | | |
| 1641 | // | parallel for simd| simd | | |
| 1642 | // | parallel for simd| sections | | |
| 1643 | // | parallel for simd| section | | |
| 1644 | // | parallel for simd| single | | |
| 1645 | // | parallel for simd| parallel for | | |
| 1646 | // | parallel for simd|parallel for simd| | |
| 1647 | // | parallel for simd|parallel sections| | |
| 1648 | // | parallel for simd| task | | |
| 1649 | // | parallel for simd| taskyield | | |
| 1650 | // | parallel for simd| barrier | | |
| 1651 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1652 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1653 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1654 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1655 | // | parallel for simd| atomic | | |
| 1656 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1657 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1658 | // | parallel for simd| cancellation | | |
| 1659 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1660 | // | parallel for simd| cancel | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1661 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1662 | // | sections | parallel | * | |
| 1663 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1664 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1665 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1666 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1667 | // | sections | simd | * | |
| 1668 | // | sections | sections | + | |
| 1669 | // | sections | section | * | |
| 1670 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1671 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1672 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1673 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1674 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1675 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1676 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1677 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1678 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1679 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1680 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1681 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1682 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1683 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1684 | // | sections | cancellation | | |
| 1685 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1686 | // | sections | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1687 | // +------------------+-----------------+------------------------------------+ |
| 1688 | // | section | parallel | * | |
| 1689 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1690 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1691 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1692 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1693 | // | section | simd | * | |
| 1694 | // | section | sections | + | |
| 1695 | // | section | section | + | |
| 1696 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1697 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1698 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1699 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1700 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1701 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1702 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1703 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1704 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1705 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1706 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1707 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1708 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1709 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1710 | // | section | cancellation | | |
| 1711 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1712 | // | section | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1713 | // +------------------+-----------------+------------------------------------+ |
| 1714 | // | single | parallel | * | |
| 1715 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1716 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1717 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1718 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1719 | // | single | simd | * | |
| 1720 | // | single | sections | + | |
| 1721 | // | single | section | + | |
| 1722 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1723 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1724 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1725 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1726 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1727 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1728 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1729 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1730 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1731 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1732 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1733 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1734 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1735 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1736 | // | single | cancellation | | |
| 1737 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1738 | // | single | cancel | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1739 | // +------------------+-----------------+------------------------------------+ |
| 1740 | // | parallel for | parallel | * | |
| 1741 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1742 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1743 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1744 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1745 | // | parallel for | simd | * | |
| 1746 | // | parallel for | sections | + | |
| 1747 | // | parallel for | section | + | |
| 1748 | // | parallel for | single | + | |
| 1749 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1750 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1751 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1752 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1753 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1754 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1755 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1756 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1757 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1758 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1759 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1760 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1761 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1762 | // | parallel for | cancellation | | |
| 1763 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1764 | // | parallel for | cancel | ! | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1765 | // +------------------+-----------------+------------------------------------+ |
| 1766 | // | parallel sections| parallel | * | |
| 1767 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1768 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1769 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1770 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1771 | // | parallel sections| simd | * | |
| 1772 | // | parallel sections| sections | + | |
| 1773 | // | parallel sections| section | * | |
| 1774 | // | parallel sections| single | + | |
| 1775 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1776 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1777 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1778 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1779 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1780 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1781 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1782 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1783 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1784 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1785 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1786 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1787 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1788 | // | parallel sections| cancellation | | |
| 1789 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1790 | // | parallel sections| cancel | ! | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1791 | // +------------------+-----------------+------------------------------------+ |
| 1792 | // | task | parallel | * | |
| 1793 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1794 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1795 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1796 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1797 | // | task | simd | * | |
| 1798 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1799 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1800 | // | task | single | + | |
| 1801 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1802 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1803 | // | task |parallel sections| * | |
| 1804 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1805 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1806 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1807 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1808 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1809 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1810 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1811 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1812 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1813 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1814 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1815 | // | | point | ! | |
| 1816 | // | task | cancel | ! | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1817 | // +------------------+-----------------+------------------------------------+ |
| 1818 | // | ordered | parallel | * | |
| 1819 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1820 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1821 | // | ordered | master | * | |
| 1822 | // | ordered | critical | * | |
| 1823 | // | ordered | simd | * | |
| 1824 | // | ordered | sections | + | |
| 1825 | // | ordered | section | + | |
| 1826 | // | ordered | single | + | |
| 1827 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1828 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1829 | // | ordered |parallel sections| * | |
| 1830 | // | ordered | task | * | |
| 1831 | // | ordered | taskyield | * | |
| 1832 | // | ordered | barrier | + | |
| 1833 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1834 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1835 | // | ordered | flush | * | |
| 1836 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1837 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1838 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1839 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1840 | // | ordered | cancellation | | |
| 1841 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1842 | // | ordered | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1843 | // +------------------+-----------------+------------------------------------+ |
| 1844 | // | atomic | parallel | | |
| 1845 | // | atomic | for | | |
| 1846 | // | atomic | for simd | | |
| 1847 | // | atomic | master | | |
| 1848 | // | atomic | critical | | |
| 1849 | // | atomic | simd | | |
| 1850 | // | atomic | sections | | |
| 1851 | // | atomic | section | | |
| 1852 | // | atomic | single | | |
| 1853 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1854 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1855 | // | atomic |parallel sections| | |
| 1856 | // | atomic | task | | |
| 1857 | // | atomic | taskyield | | |
| 1858 | // | atomic | barrier | | |
| 1859 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1860 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1861 | // | atomic | flush | | |
| 1862 | // | atomic | ordered | | |
| 1863 | // | atomic | atomic | | |
| 1864 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1865 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1866 | // | atomic | cancellation | | |
| 1867 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1868 | // | atomic | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1869 | // +------------------+-----------------+------------------------------------+ |
| 1870 | // | target | parallel | * | |
| 1871 | // | target | for | * | |
| 1872 | // | target | for simd | * | |
| 1873 | // | target | master | * | |
| 1874 | // | target | critical | * | |
| 1875 | // | target | simd | * | |
| 1876 | // | target | sections | * | |
| 1877 | // | target | section | * | |
| 1878 | // | target | single | * | |
| 1879 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1880 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1881 | // | target |parallel sections| * | |
| 1882 | // | target | task | * | |
| 1883 | // | target | taskyield | * | |
| 1884 | // | target | barrier | * | |
| 1885 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1886 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1887 | // | target | flush | * | |
| 1888 | // | target | ordered | * | |
| 1889 | // | target | atomic | * | |
| 1890 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1891 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1892 | // | target | cancellation | | |
| 1893 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1894 | // | target | cancel | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1895 | // +------------------+-----------------+------------------------------------+ |
| 1896 | // | teams | parallel | * | |
| 1897 | // | teams | for | + | |
| 1898 | // | teams | for simd | + | |
| 1899 | // | teams | master | + | |
| 1900 | // | teams | critical | + | |
| 1901 | // | teams | simd | + | |
| 1902 | // | teams | sections | + | |
| 1903 | // | teams | section | + | |
| 1904 | // | teams | single | + | |
| 1905 | // | teams | parallel for | * | |
| 1906 | // | teams |parallel for simd| * | |
| 1907 | // | teams |parallel sections| * | |
| 1908 | // | teams | task | + | |
| 1909 | // | teams | taskyield | + | |
| 1910 | // | teams | barrier | + | |
| 1911 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1912 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1913 | // | teams | flush | + | |
| 1914 | // | teams | ordered | + | |
| 1915 | // | teams | atomic | + | |
| 1916 | // | teams | target | + | |
| 1917 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1918 | // | teams | cancellation | | |
| 1919 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1920 | // | teams | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1921 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1922 | if (Stack->getCurScope()) { |
| 1923 | auto ParentRegion = Stack->getParentDirective(); |
| 1924 | bool NestingProhibited = false; |
| 1925 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1926 | enum { |
| 1927 | NoRecommend, |
| 1928 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1929 | ShouldBeInOrderedRegion, |
| 1930 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1931 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1932 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1933 | // OpenMP [2.16, Nesting of Regions] |
| 1934 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1935 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 1936 | // An ordered construct with the simd clause is the only OpenMP construct |
| 1937 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1938 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1939 | return true; |
| 1940 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1941 | if (ParentRegion == OMPD_atomic) { |
| 1942 | // OpenMP [2.16, Nesting of Regions] |
| 1943 | // OpenMP constructs may not be nested inside an atomic region. |
| 1944 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1945 | return true; |
| 1946 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1947 | if (CurrentRegion == OMPD_section) { |
| 1948 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1949 | // Orphaned section directives are prohibited. That is, the section |
| 1950 | // directives must appear within the sections construct and must not be |
| 1951 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1952 | if (ParentRegion != OMPD_sections && |
| 1953 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1954 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1955 | << (ParentRegion != OMPD_unknown) |
| 1956 | << getOpenMPDirectiveName(ParentRegion); |
| 1957 | return true; |
| 1958 | } |
| 1959 | return false; |
| 1960 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1961 | // Allow some constructs to be orphaned (they could be used in functions, |
| 1962 | // called from OpenMP regions with the required preconditions). |
| 1963 | if (ParentRegion == OMPD_unknown) |
| 1964 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1965 | if (CurrentRegion == OMPD_cancellation_point || |
| 1966 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1967 | // OpenMP [2.16, Nesting of Regions] |
| 1968 | // A cancellation point construct for which construct-type-clause is |
| 1969 | // taskgroup must be nested inside a task construct. A cancellation |
| 1970 | // point construct for which construct-type-clause is not taskgroup must |
| 1971 | // be closely nested inside an OpenMP construct that matches the type |
| 1972 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1973 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 1974 | // nested inside a task construct. A cancel construct for which |
| 1975 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 1976 | // OpenMP construct that matches the type specified in |
| 1977 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1978 | NestingProhibited = |
| 1979 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 1980 | (CancelRegion == OMPD_for && |
| 1981 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1982 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 1983 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 1984 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 1985 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1986 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1987 | // OpenMP [2.16, Nesting of Regions] |
| 1988 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1989 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1990 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 1991 | ParentRegion == OMPD_task; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1992 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 1993 | // OpenMP [2.16, Nesting of Regions] |
| 1994 | // A critical region may not be nested (closely or otherwise) inside a |
| 1995 | // critical region with the same name. Note that this restriction is not |
| 1996 | // sufficient to prevent deadlock. |
| 1997 | SourceLocation PreviousCriticalLoc; |
| 1998 | bool DeadLock = |
| 1999 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2000 | OpenMPDirectiveKind K, |
| 2001 | const DeclarationNameInfo &DNI, |
| 2002 | SourceLocation Loc) |
| 2003 | ->bool { |
| 2004 | if (K == OMPD_critical && |
| 2005 | DNI.getName() == CurrentName.getName()) { |
| 2006 | PreviousCriticalLoc = Loc; |
| 2007 | return true; |
| 2008 | } else |
| 2009 | return false; |
| 2010 | }, |
| 2011 | false /* skip top directive */); |
| 2012 | if (DeadLock) { |
| 2013 | SemaRef.Diag(StartLoc, |
| 2014 | diag::err_omp_prohibited_region_critical_same_name) |
| 2015 | << CurrentName.getName(); |
| 2016 | if (PreviousCriticalLoc.isValid()) |
| 2017 | SemaRef.Diag(PreviousCriticalLoc, |
| 2018 | diag::note_omp_previous_critical_region); |
| 2019 | return true; |
| 2020 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2021 | } else if (CurrentRegion == OMPD_barrier) { |
| 2022 | // OpenMP [2.16, Nesting of Regions] |
| 2023 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2024 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2025 | NestingProhibited = |
| 2026 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2027 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 2028 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2029 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2030 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2031 | // OpenMP [2.16, Nesting of Regions] |
| 2032 | // A worksharing region may not be closely nested inside a worksharing, |
| 2033 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2034 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2035 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2036 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 2037 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
| 2038 | Recommend = ShouldBeInParallelRegion; |
| 2039 | } else if (CurrentRegion == OMPD_ordered) { |
| 2040 | // OpenMP [2.16, Nesting of Regions] |
| 2041 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2042 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2043 | // An ordered region must be closely nested inside a loop region (or |
| 2044 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2045 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2046 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2047 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2048 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2049 | ParentRegion == OMPD_task || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2050 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2051 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2052 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2053 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2054 | // OpenMP [2.16, Nesting of Regions] |
| 2055 | // If specified, a teams construct must be contained within a target |
| 2056 | // construct. |
| 2057 | NestingProhibited = ParentRegion != OMPD_target; |
| 2058 | Recommend = ShouldBeInTargetRegion; |
| 2059 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2060 | } |
| 2061 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2062 | // OpenMP [2.16, Nesting of Regions] |
| 2063 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2064 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2065 | // constructs that can be closely nested in the teams region. |
| 2066 | // TODO: add distribute directive. |
| 2067 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 2068 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2069 | } |
| 2070 | if (NestingProhibited) { |
| 2071 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2072 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2073 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2074 | return true; |
| 2075 | } |
| 2076 | } |
| 2077 | return false; |
| 2078 | } |
| 2079 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2080 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2081 | ArrayRef<OMPClause *> Clauses, |
| 2082 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2083 | bool ErrorFound = false; |
| 2084 | unsigned NamedModifiersNumber = 0; |
| 2085 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2086 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2087 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2088 | for (const auto *C : Clauses) { |
| 2089 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2090 | // At most one if clause without a directive-name-modifier can appear on |
| 2091 | // the directive. |
| 2092 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2093 | if (FoundNameModifiers[CurNM]) { |
| 2094 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2095 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2096 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2097 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2098 | } else if (CurNM != OMPD_unknown) { |
| 2099 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2100 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2101 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2102 | FoundNameModifiers[CurNM] = IC; |
| 2103 | if (CurNM == OMPD_unknown) |
| 2104 | continue; |
| 2105 | // Check if the specified name modifier is allowed for the current |
| 2106 | // directive. |
| 2107 | // At most one if clause with the particular directive-name-modifier can |
| 2108 | // appear on the directive. |
| 2109 | bool MatchFound = false; |
| 2110 | for (auto NM : AllowedNameModifiers) { |
| 2111 | if (CurNM == NM) { |
| 2112 | MatchFound = true; |
| 2113 | break; |
| 2114 | } |
| 2115 | } |
| 2116 | if (!MatchFound) { |
| 2117 | S.Diag(IC->getNameModifierLoc(), |
| 2118 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2119 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2120 | ErrorFound = true; |
| 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | // If any if clause on the directive includes a directive-name-modifier then |
| 2125 | // all if clauses on the directive must include a directive-name-modifier. |
| 2126 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2127 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2128 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2129 | diag::err_omp_no_more_if_clause); |
| 2130 | } else { |
| 2131 | std::string Values; |
| 2132 | std::string Sep(", "); |
| 2133 | unsigned AllowedCnt = 0; |
| 2134 | unsigned TotalAllowedNum = |
| 2135 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2136 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2137 | ++Cnt) { |
| 2138 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2139 | if (!FoundNameModifiers[NM]) { |
| 2140 | Values += "'"; |
| 2141 | Values += getOpenMPDirectiveName(NM); |
| 2142 | Values += "'"; |
| 2143 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2144 | Values += " or "; |
| 2145 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2146 | Values += Sep; |
| 2147 | ++AllowedCnt; |
| 2148 | } |
| 2149 | } |
| 2150 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2151 | diag::err_omp_unnamed_if_clause) |
| 2152 | << (TotalAllowedNum > 1) << Values; |
| 2153 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2154 | for (auto Loc : NameModifierLoc) { |
| 2155 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2156 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2157 | ErrorFound = true; |
| 2158 | } |
| 2159 | return ErrorFound; |
| 2160 | } |
| 2161 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2162 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2163 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2164 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2165 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2166 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2167 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2168 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2169 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2170 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2171 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2172 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2173 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2174 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2175 | if (AStmt) { |
| 2176 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2177 | |
| 2178 | // Check default data sharing attributes for referenced variables. |
| 2179 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2180 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2181 | if (DSAChecker.isErrorFound()) |
| 2182 | return StmtError(); |
| 2183 | // Generate list of implicitly defined firstprivate variables. |
| 2184 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2185 | |
| 2186 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2187 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2188 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2189 | SourceLocation(), SourceLocation())) { |
| 2190 | ClausesWithImplicit.push_back(Implicit); |
| 2191 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2192 | DSAChecker.getImplicitFirstprivate().size(); |
| 2193 | } else |
| 2194 | ErrorFound = true; |
| 2195 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2196 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2197 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2198 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2199 | switch (Kind) { |
| 2200 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2201 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2202 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2203 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2204 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2205 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2206 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2207 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2208 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2209 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2210 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2211 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2212 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2213 | case OMPD_for_simd: |
| 2214 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2215 | EndLoc, VarsWithInheritedDSA); |
| 2216 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2217 | case OMPD_sections: |
| 2218 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2219 | EndLoc); |
| 2220 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2221 | case OMPD_section: |
| 2222 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2223 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2224 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2225 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2226 | case OMPD_single: |
| 2227 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2228 | EndLoc); |
| 2229 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2230 | case OMPD_master: |
| 2231 | assert(ClausesWithImplicit.empty() && |
| 2232 | "No clauses are allowed for 'omp master' directive"); |
| 2233 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2234 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2235 | case OMPD_critical: |
| 2236 | assert(ClausesWithImplicit.empty() && |
| 2237 | "No clauses are allowed for 'omp critical' directive"); |
| 2238 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2239 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2240 | case OMPD_parallel_for: |
| 2241 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2242 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2243 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2244 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2245 | case OMPD_parallel_for_simd: |
| 2246 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2247 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2248 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2249 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2250 | case OMPD_parallel_sections: |
| 2251 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2252 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2253 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2254 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2255 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2256 | Res = |
| 2257 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2258 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2259 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2260 | case OMPD_taskyield: |
| 2261 | assert(ClausesWithImplicit.empty() && |
| 2262 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2263 | assert(AStmt == nullptr && |
| 2264 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2265 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2266 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2267 | case OMPD_barrier: |
| 2268 | assert(ClausesWithImplicit.empty() && |
| 2269 | "No clauses are allowed for 'omp barrier' directive"); |
| 2270 | assert(AStmt == nullptr && |
| 2271 | "No associated statement allowed for 'omp barrier' directive"); |
| 2272 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2273 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2274 | case OMPD_taskwait: |
| 2275 | assert(ClausesWithImplicit.empty() && |
| 2276 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2277 | assert(AStmt == nullptr && |
| 2278 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2279 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2280 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2281 | case OMPD_taskgroup: |
| 2282 | assert(ClausesWithImplicit.empty() && |
| 2283 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2284 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2285 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2286 | case OMPD_flush: |
| 2287 | assert(AStmt == nullptr && |
| 2288 | "No associated statement allowed for 'omp flush' directive"); |
| 2289 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2290 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2291 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2292 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2293 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2294 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2295 | case OMPD_atomic: |
| 2296 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2297 | EndLoc); |
| 2298 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2299 | case OMPD_teams: |
| 2300 | Res = |
| 2301 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2302 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2303 | case OMPD_target: |
| 2304 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2305 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2306 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2307 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2308 | case OMPD_cancellation_point: |
| 2309 | assert(ClausesWithImplicit.empty() && |
| 2310 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2311 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2312 | "cancellation point' directive"); |
| 2313 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2314 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2315 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2316 | assert(AStmt == nullptr && |
| 2317 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2318 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2319 | CancelRegion); |
| 2320 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2321 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2322 | case OMPD_target_data: |
| 2323 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2324 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2325 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2326 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2327 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2328 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2329 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2330 | llvm_unreachable("Unknown OpenMP directive"); |
| 2331 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2332 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2333 | for (auto P : VarsWithInheritedDSA) { |
| 2334 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2335 | << P.first << P.second->getSourceRange(); |
| 2336 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2337 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2338 | |
| 2339 | if (!AllowedNameModifiers.empty()) |
| 2340 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2341 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2342 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2343 | if (ErrorFound) |
| 2344 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2345 | return Res; |
| 2346 | } |
| 2347 | |
| 2348 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2349 | Stmt *AStmt, |
| 2350 | SourceLocation StartLoc, |
| 2351 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2352 | if (!AStmt) |
| 2353 | return StmtError(); |
| 2354 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2355 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2356 | // 1.2.2 OpenMP Language Terminology |
| 2357 | // Structured block - An executable statement with a single entry at the |
| 2358 | // top and a single exit at the bottom. |
| 2359 | // The point of exit cannot be a branch out of the structured block. |
| 2360 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2361 | CS->getCapturedDecl()->setNothrow(); |
| 2362 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2363 | getCurFunction()->setHasBranchProtectedScope(); |
| 2364 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2365 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2366 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2367 | } |
| 2368 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2369 | namespace { |
| 2370 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2371 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2372 | /// for IR generation. |
| 2373 | class OpenMPIterationSpaceChecker { |
| 2374 | /// \brief Reference to Sema. |
| 2375 | Sema &SemaRef; |
| 2376 | /// \brief A location for diagnostics (when there is no some better location). |
| 2377 | SourceLocation DefaultLoc; |
| 2378 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2379 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2380 | /// \brief A source location for referring to loop init later. |
| 2381 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2382 | /// \brief A source location for referring to condition later. |
| 2383 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2384 | /// \brief A source location for referring to increment later. |
| 2385 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2386 | /// \brief Loop variable. |
| 2387 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2388 | /// \brief Reference to loop variable. |
| 2389 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2390 | /// \brief Lower bound (initializer for the var). |
| 2391 | Expr *LB; |
| 2392 | /// \brief Upper bound. |
| 2393 | Expr *UB; |
| 2394 | /// \brief Loop step (increment). |
| 2395 | Expr *Step; |
| 2396 | /// \brief This flag is true when condition is one of: |
| 2397 | /// Var < UB |
| 2398 | /// Var <= UB |
| 2399 | /// UB > Var |
| 2400 | /// UB >= Var |
| 2401 | bool TestIsLessOp; |
| 2402 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2403 | bool TestIsStrictOp; |
| 2404 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2405 | bool SubtractStep; |
| 2406 | |
| 2407 | public: |
| 2408 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2409 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2410 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2411 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2412 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2413 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2414 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2415 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2416 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2417 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2418 | /// for less/greater and for strict/non-strict comparison. |
| 2419 | bool CheckCond(Expr *S); |
| 2420 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2421 | /// does not conform, otherwise save loop step (#Step). |
| 2422 | bool CheckInc(Expr *S); |
| 2423 | /// \brief Return the loop counter variable. |
| 2424 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2425 | /// \brief Return the reference expression to loop counter variable. |
| 2426 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2427 | /// \brief Source range of the loop init. |
| 2428 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2429 | /// \brief Source range of the loop condition. |
| 2430 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2431 | /// \brief Source range of the loop increment. |
| 2432 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2433 | /// \brief True if the step should be subtracted. |
| 2434 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2435 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2436 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2437 | /// \brief Build the precondition expression for the loops. |
| 2438 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2439 | /// \brief Build reference expression to the counter be used for codegen. |
| 2440 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2441 | /// \brief Build reference expression to the private counter be used for |
| 2442 | /// codegen. |
| 2443 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2444 | /// \brief Build initization of the counter be used for codegen. |
| 2445 | Expr *BuildCounterInit() const; |
| 2446 | /// \brief Build step of the counter be used for codegen. |
| 2447 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2448 | /// \brief Return true if any expression is dependent. |
| 2449 | bool Dependent() const; |
| 2450 | |
| 2451 | private: |
| 2452 | /// \brief Check the right-hand side of an assignment in the increment |
| 2453 | /// expression. |
| 2454 | bool CheckIncRHS(Expr *RHS); |
| 2455 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2456 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2457 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame^] | 2458 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2459 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2460 | /// \brief Helper to set loop increment. |
| 2461 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2462 | }; |
| 2463 | |
| 2464 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2465 | if (!Var) { |
| 2466 | assert(!LB && !UB && !Step); |
| 2467 | return false; |
| 2468 | } |
| 2469 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2470 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2471 | } |
| 2472 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2473 | template <typename T> |
| 2474 | static T *getExprAsWritten(T *E) { |
| 2475 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2476 | E = ExprTemp->getSubExpr(); |
| 2477 | |
| 2478 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2479 | E = MTE->GetTemporaryExpr(); |
| 2480 | |
| 2481 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2482 | E = Binder->getSubExpr(); |
| 2483 | |
| 2484 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2485 | E = ICE->getSubExprAsWritten(); |
| 2486 | return E->IgnoreParens(); |
| 2487 | } |
| 2488 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2489 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2490 | DeclRefExpr *NewVarRefExpr, |
| 2491 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2492 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2493 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2494 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2495 | if (!NewVar || !NewLB) |
| 2496 | return true; |
| 2497 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2498 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2499 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2500 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2501 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2502 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2503 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2504 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2505 | LB = NewLB; |
| 2506 | return false; |
| 2507 | } |
| 2508 | |
| 2509 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame^] | 2510 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2511 | // State consistency checking to ensure correct usage. |
| 2512 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2513 | !TestIsLessOp && !TestIsStrictOp); |
| 2514 | if (!NewUB) |
| 2515 | return true; |
| 2516 | UB = NewUB; |
| 2517 | TestIsLessOp = LessOp; |
| 2518 | TestIsStrictOp = StrictOp; |
| 2519 | ConditionSrcRange = SR; |
| 2520 | ConditionLoc = SL; |
| 2521 | return false; |
| 2522 | } |
| 2523 | |
| 2524 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2525 | // State consistency checking to ensure correct usage. |
| 2526 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2527 | if (!NewStep) |
| 2528 | return true; |
| 2529 | if (!NewStep->isValueDependent()) { |
| 2530 | // Check that the step is integer expression. |
| 2531 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2532 | ExprResult Val = |
| 2533 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2534 | if (Val.isInvalid()) |
| 2535 | return true; |
| 2536 | NewStep = Val.get(); |
| 2537 | |
| 2538 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2539 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2540 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2541 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2542 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2543 | // the loop. |
| 2544 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2545 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2546 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2547 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2548 | // the loop. |
| 2549 | llvm::APSInt Result; |
| 2550 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2551 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2552 | bool IsConstNeg = |
| 2553 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2554 | bool IsConstPos = |
| 2555 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2556 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2557 | if (UB && (IsConstZero || |
| 2558 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2559 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2560 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2561 | diag::err_omp_loop_incr_not_compatible) |
| 2562 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2563 | SemaRef.Diag(ConditionLoc, |
| 2564 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2565 | << TestIsLessOp << ConditionSrcRange; |
| 2566 | return true; |
| 2567 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2568 | if (TestIsLessOp == Subtract) { |
| 2569 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2570 | NewStep).get(); |
| 2571 | Subtract = !Subtract; |
| 2572 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | Step = NewStep; |
| 2576 | SubtractStep = Subtract; |
| 2577 | return false; |
| 2578 | } |
| 2579 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2580 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2581 | // Check init-expr for canonical loop form and save loop counter |
| 2582 | // variable - #Var and its initialization value - #LB. |
| 2583 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2584 | // var = lb |
| 2585 | // integer-type var = lb |
| 2586 | // random-access-iterator-type var = lb |
| 2587 | // pointer-type var = lb |
| 2588 | // |
| 2589 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2590 | if (EmitDiags) { |
| 2591 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2592 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2593 | return true; |
| 2594 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2595 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2596 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2597 | S = E->IgnoreParens(); |
| 2598 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2599 | if (BO->getOpcode() == BO_Assign) |
| 2600 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2601 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2602 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2603 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2604 | if (DS->isSingleDecl()) { |
| 2605 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2606 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2607 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2608 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2609 | SemaRef.Diag(S->getLocStart(), |
| 2610 | diag::ext_omp_loop_not_canonical_init) |
| 2611 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2612 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2613 | } |
| 2614 | } |
| 2615 | } |
| 2616 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2617 | if (CE->getOperator() == OO_Equal) |
| 2618 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2619 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2620 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2621 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2622 | if (EmitDiags) { |
| 2623 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2624 | << S->getSourceRange(); |
| 2625 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2626 | return true; |
| 2627 | } |
| 2628 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2629 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2630 | /// variable (which may be the loop variable) if possible. |
| 2631 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2632 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2633 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2634 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2635 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2636 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2637 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2638 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2639 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2640 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2641 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2642 | if (!DRE) |
| 2643 | return nullptr; |
| 2644 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2645 | } |
| 2646 | |
| 2647 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2648 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2649 | // less/greater and for strict/non-strict comparison. |
| 2650 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2651 | // var relational-op b |
| 2652 | // b relational-op var |
| 2653 | // |
| 2654 | if (!S) { |
| 2655 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2656 | return true; |
| 2657 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2658 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2659 | SourceLocation CondLoc = S->getLocStart(); |
| 2660 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2661 | if (BO->isRelationalOp()) { |
| 2662 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2663 | return SetUB(BO->getRHS(), |
| 2664 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2665 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2666 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2667 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2668 | return SetUB(BO->getLHS(), |
| 2669 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2670 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2671 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2672 | } |
| 2673 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2674 | if (CE->getNumArgs() == 2) { |
| 2675 | auto Op = CE->getOperator(); |
| 2676 | switch (Op) { |
| 2677 | case OO_Greater: |
| 2678 | case OO_GreaterEqual: |
| 2679 | case OO_Less: |
| 2680 | case OO_LessEqual: |
| 2681 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2682 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2683 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2684 | CE->getOperatorLoc()); |
| 2685 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2686 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2687 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2688 | CE->getOperatorLoc()); |
| 2689 | break; |
| 2690 | default: |
| 2691 | break; |
| 2692 | } |
| 2693 | } |
| 2694 | } |
| 2695 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2696 | << S->getSourceRange() << Var; |
| 2697 | return true; |
| 2698 | } |
| 2699 | |
| 2700 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2701 | // RHS of canonical loop form increment can be: |
| 2702 | // var + incr |
| 2703 | // incr + var |
| 2704 | // var - incr |
| 2705 | // |
| 2706 | RHS = RHS->IgnoreParenImpCasts(); |
| 2707 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2708 | if (BO->isAdditiveOp()) { |
| 2709 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2710 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2711 | return SetStep(BO->getRHS(), !IsAdd); |
| 2712 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2713 | return SetStep(BO->getLHS(), false); |
| 2714 | } |
| 2715 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2716 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2717 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2718 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2719 | return SetStep(CE->getArg(1), !IsAdd); |
| 2720 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2721 | return SetStep(CE->getArg(0), false); |
| 2722 | } |
| 2723 | } |
| 2724 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2725 | << RHS->getSourceRange() << Var; |
| 2726 | return true; |
| 2727 | } |
| 2728 | |
| 2729 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2730 | // Check incr-expr for canonical loop form and return true if it |
| 2731 | // does not conform. |
| 2732 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2733 | // ++var |
| 2734 | // var++ |
| 2735 | // --var |
| 2736 | // var-- |
| 2737 | // var += incr |
| 2738 | // var -= incr |
| 2739 | // var = var + incr |
| 2740 | // var = incr + var |
| 2741 | // var = var - incr |
| 2742 | // |
| 2743 | if (!S) { |
| 2744 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2745 | return true; |
| 2746 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2747 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2748 | S = S->IgnoreParens(); |
| 2749 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2750 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2751 | return SetStep( |
| 2752 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2753 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2754 | false); |
| 2755 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2756 | switch (BO->getOpcode()) { |
| 2757 | case BO_AddAssign: |
| 2758 | case BO_SubAssign: |
| 2759 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2760 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2761 | break; |
| 2762 | case BO_Assign: |
| 2763 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2764 | return CheckIncRHS(BO->getRHS()); |
| 2765 | break; |
| 2766 | default: |
| 2767 | break; |
| 2768 | } |
| 2769 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2770 | switch (CE->getOperator()) { |
| 2771 | case OO_PlusPlus: |
| 2772 | case OO_MinusMinus: |
| 2773 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2774 | return SetStep( |
| 2775 | SemaRef.ActOnIntegerConstant( |
| 2776 | CE->getLocStart(), |
| 2777 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2778 | false); |
| 2779 | break; |
| 2780 | case OO_PlusEqual: |
| 2781 | case OO_MinusEqual: |
| 2782 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2783 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2784 | break; |
| 2785 | case OO_Equal: |
| 2786 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2787 | return CheckIncRHS(CE->getArg(1)); |
| 2788 | break; |
| 2789 | default: |
| 2790 | break; |
| 2791 | } |
| 2792 | } |
| 2793 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2794 | << S->getSourceRange() << Var; |
| 2795 | return true; |
| 2796 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2797 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2798 | namespace { |
| 2799 | // Transform variables declared in GNU statement expressions to new ones to |
| 2800 | // avoid crash on codegen. |
| 2801 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 2802 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 2803 | |
| 2804 | public: |
| 2805 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 2806 | |
| 2807 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 2808 | if (auto *VD = cast<VarDecl>(D)) |
| 2809 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 2810 | !isa<ImplicitParamDecl>(D)) { |
| 2811 | auto *NewVD = VarDecl::Create( |
| 2812 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 2813 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 2814 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 2815 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 2816 | NewVD->setInit(VD->getInit()); |
| 2817 | NewVD->setInitStyle(VD->getInitStyle()); |
| 2818 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 2819 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 2820 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 2821 | NewVD->setConstexpr(VD->isConstexpr()); |
| 2822 | NewVD->setInitCapture(VD->isInitCapture()); |
| 2823 | NewVD->setPreviousDeclInSameBlockScope( |
| 2824 | VD->isPreviousDeclInSameBlockScope()); |
| 2825 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 2826 | if (VD->hasAttrs()) |
| 2827 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2828 | transformedLocalDecl(VD, NewVD); |
| 2829 | return NewVD; |
| 2830 | } |
| 2831 | return BaseTransform::TransformDefinition(Loc, D); |
| 2832 | } |
| 2833 | |
| 2834 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 2835 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 2836 | if (E->getDecl() != NewD) { |
| 2837 | NewD->setReferenced(); |
| 2838 | NewD->markUsed(SemaRef.Context); |
| 2839 | return DeclRefExpr::Create( |
| 2840 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 2841 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 2842 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 2843 | } |
| 2844 | return BaseTransform::TransformDeclRefExpr(E); |
| 2845 | } |
| 2846 | }; |
| 2847 | } |
| 2848 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2849 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2850 | Expr * |
| 2851 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2852 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2853 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2854 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2855 | auto VarType = Var->getType().getNonReferenceType(); |
| 2856 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2857 | SemaRef.getLangOpts().CPlusPlus) { |
| 2858 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2859 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 2860 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 2861 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 2862 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 2863 | if (!Upper || !Lower) |
| 2864 | return nullptr; |
| 2865 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 2866 | Sema::AA_Converting, |
| 2867 | /*AllowExplicit=*/true) |
| 2868 | .get(); |
| 2869 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 2870 | Sema::AA_Converting, |
| 2871 | /*AllowExplicit=*/true) |
| 2872 | .get(); |
| 2873 | if (!Upper || !Lower) |
| 2874 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2875 | |
| 2876 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2877 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2878 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2879 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2880 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2881 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2882 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2883 | return nullptr; |
| 2884 | } |
| 2885 | } |
| 2886 | |
| 2887 | if (!Diff.isUsable()) |
| 2888 | return nullptr; |
| 2889 | |
| 2890 | // Upper - Lower [- 1] |
| 2891 | if (TestIsStrictOp) |
| 2892 | Diff = SemaRef.BuildBinOp( |
| 2893 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2894 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2895 | if (!Diff.isUsable()) |
| 2896 | return nullptr; |
| 2897 | |
| 2898 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2899 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2900 | if (NewStep.isInvalid()) |
| 2901 | return nullptr; |
| 2902 | NewStep = SemaRef.PerformImplicitConversion( |
| 2903 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2904 | /*AllowExplicit=*/true); |
| 2905 | if (NewStep.isInvalid()) |
| 2906 | return nullptr; |
| 2907 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2908 | if (!Diff.isUsable()) |
| 2909 | return nullptr; |
| 2910 | |
| 2911 | // Parentheses (for dumping/debugging purposes only). |
| 2912 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 2913 | if (!Diff.isUsable()) |
| 2914 | return nullptr; |
| 2915 | |
| 2916 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2917 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2918 | if (NewStep.isInvalid()) |
| 2919 | return nullptr; |
| 2920 | NewStep = SemaRef.PerformImplicitConversion( |
| 2921 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2922 | /*AllowExplicit=*/true); |
| 2923 | if (NewStep.isInvalid()) |
| 2924 | return nullptr; |
| 2925 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2926 | if (!Diff.isUsable()) |
| 2927 | return nullptr; |
| 2928 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2929 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2930 | QualType Type = Diff.get()->getType(); |
| 2931 | auto &C = SemaRef.Context; |
| 2932 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 2933 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 2934 | if (!Type->isIntegerType() || UseVarType) { |
| 2935 | unsigned NewSize = |
| 2936 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 2937 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 2938 | : Type->hasSignedIntegerRepresentation(); |
| 2939 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 2940 | Diff = SemaRef.PerformImplicitConversion( |
| 2941 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 2942 | if (!Diff.isUsable()) |
| 2943 | return nullptr; |
| 2944 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2945 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2946 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 2947 | if (NewSize != C.getTypeSize(Type)) { |
| 2948 | if (NewSize < C.getTypeSize(Type)) { |
| 2949 | assert(NewSize == 64 && "incorrect loop var size"); |
| 2950 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 2951 | << InitSrcRange << ConditionSrcRange; |
| 2952 | } |
| 2953 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2954 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 2955 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2956 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 2957 | Sema::AA_Converting, true); |
| 2958 | if (!Diff.isUsable()) |
| 2959 | return nullptr; |
| 2960 | } |
| 2961 | } |
| 2962 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2963 | return Diff.get(); |
| 2964 | } |
| 2965 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2966 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 2967 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 2968 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 2969 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2970 | TransformToNewDefs Transform(SemaRef); |
| 2971 | |
| 2972 | auto NewLB = Transform.TransformExpr(LB); |
| 2973 | auto NewUB = Transform.TransformExpr(UB); |
| 2974 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 2975 | return Cond; |
| 2976 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 2977 | Sema::AA_Converting, |
| 2978 | /*AllowExplicit=*/true); |
| 2979 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 2980 | Sema::AA_Converting, |
| 2981 | /*AllowExplicit=*/true); |
| 2982 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 2983 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2984 | auto CondExpr = SemaRef.BuildBinOp( |
| 2985 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 2986 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2987 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2988 | if (CondExpr.isUsable()) { |
| 2989 | CondExpr = SemaRef.PerformImplicitConversion( |
| 2990 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 2991 | /*AllowExplicit=*/true); |
| 2992 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2993 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 2994 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 2995 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 2996 | } |
| 2997 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2998 | /// \brief Build reference expression to the counter be used for codegen. |
| 2999 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3000 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3001 | DefaultLoc); |
| 3002 | } |
| 3003 | |
| 3004 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3005 | if (Var && !Var->isInvalidDecl()) { |
| 3006 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3007 | auto *PrivateVar = |
| 3008 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3009 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3010 | if (PrivateVar->isInvalidDecl()) |
| 3011 | return nullptr; |
| 3012 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3013 | } |
| 3014 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | /// \brief Build initization of the counter be used for codegen. |
| 3018 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3019 | |
| 3020 | /// \brief Build step of the counter be used for codegen. |
| 3021 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3022 | |
| 3023 | /// \brief Iteration space of a single for loop. |
| 3024 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3025 | /// \brief Condition of the loop. |
| 3026 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3027 | /// \brief This expression calculates the number of iterations in the loop. |
| 3028 | /// It is always possible to calculate it before starting the loop. |
| 3029 | Expr *NumIterations; |
| 3030 | /// \brief The loop counter variable. |
| 3031 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3032 | /// \brief Private loop counter variable. |
| 3033 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3034 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3035 | Expr *CounterInit; |
| 3036 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3037 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3038 | Expr *CounterStep; |
| 3039 | /// \brief Should step be subtracted? |
| 3040 | bool Subtract; |
| 3041 | /// \brief Source range of the loop init. |
| 3042 | SourceRange InitSrcRange; |
| 3043 | /// \brief Source range of the loop condition. |
| 3044 | SourceRange CondSrcRange; |
| 3045 | /// \brief Source range of the loop increment. |
| 3046 | SourceRange IncSrcRange; |
| 3047 | }; |
| 3048 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3049 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3050 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3051 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3052 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3053 | assert(Init && "Expected loop in canonical form."); |
| 3054 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 3055 | if (CollapseIteration > 0 && |
| 3056 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3057 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 3058 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3059 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 3060 | } |
| 3061 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 3062 | } |
| 3063 | } |
| 3064 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3065 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3066 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3067 | static bool CheckOpenMPIterationSpace( |
| 3068 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3069 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3070 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3071 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3072 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3073 | // OpenMP [2.6, Canonical Loop Form] |
| 3074 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3075 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3076 | if (!For) { |
| 3077 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3078 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3079 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3080 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3081 | if (NestedLoopCount > 1) { |
| 3082 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3083 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3084 | diag::note_omp_collapse_ordered_expr) |
| 3085 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3086 | << OrderedLoopCountExpr->getSourceRange(); |
| 3087 | else if (CollapseLoopCountExpr) |
| 3088 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3089 | diag::note_omp_collapse_ordered_expr) |
| 3090 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3091 | else |
| 3092 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3093 | diag::note_omp_collapse_ordered_expr) |
| 3094 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3095 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3096 | return true; |
| 3097 | } |
| 3098 | assert(For->getBody()); |
| 3099 | |
| 3100 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3101 | |
| 3102 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3103 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3104 | if (ISC.CheckInit(Init)) { |
| 3105 | return true; |
| 3106 | } |
| 3107 | |
| 3108 | bool HasErrors = false; |
| 3109 | |
| 3110 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3111 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3112 | |
| 3113 | // OpenMP [2.6, Canonical Loop Form] |
| 3114 | // Var is one of the following: |
| 3115 | // A variable of signed or unsigned integer type. |
| 3116 | // For C++, a variable of a random access iterator type. |
| 3117 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3118 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3119 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3120 | !VarType->isPointerType() && |
| 3121 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3122 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3123 | << SemaRef.getLangOpts().CPlusPlus; |
| 3124 | HasErrors = true; |
| 3125 | } |
| 3126 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3127 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3128 | // Construct |
| 3129 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3130 | // parallel for construct is (are) private. |
| 3131 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3132 | // with just one associated for-loop is linear with a constant-linear-step |
| 3133 | // that is the increment of the associated for-loop. |
| 3134 | // Exclude loop var from the list of variables with implicitly defined data |
| 3135 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3136 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3137 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3138 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3139 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3140 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3141 | // with just one associated for-loop may be listed in a linear clause with a |
| 3142 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3143 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3144 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3145 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3146 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3147 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3148 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3149 | auto PredeterminedCKind = |
| 3150 | isOpenMPSimdDirective(DKind) |
| 3151 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3152 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3153 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3154 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3155 | (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && |
| 3156 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3157 | DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) && |
| 3158 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 3159 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3160 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3161 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3162 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3163 | if (DVar.RefExpr == nullptr) |
| 3164 | DVar.CKind = PredeterminedCKind; |
| 3165 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3166 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3167 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3168 | // Make the loop iteration variable private (for worksharing constructs), |
| 3169 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3170 | // lastprivate (for simd directives with several collapsed or ordered |
| 3171 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3172 | if (DVar.CKind == OMPC_unknown) |
| 3173 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3174 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3175 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3176 | } |
| 3177 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3178 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3179 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3180 | // Check test-expr. |
| 3181 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3182 | |
| 3183 | // Check incr-expr. |
| 3184 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3185 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3186 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3187 | return HasErrors; |
| 3188 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3189 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3190 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3191 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
| 3192 | DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3193 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3194 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3195 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3196 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3197 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3198 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3199 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3200 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3201 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3202 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3203 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3204 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3205 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3206 | ResultIterSpace.CounterInit == nullptr || |
| 3207 | ResultIterSpace.CounterStep == nullptr); |
| 3208 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3209 | return HasErrors; |
| 3210 | } |
| 3211 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3212 | /// \brief Build 'VarRef = Start. |
| 3213 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3214 | ExprResult VarRef, ExprResult Start) { |
| 3215 | TransformToNewDefs Transform(SemaRef); |
| 3216 | // Build 'VarRef = Start. |
| 3217 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3218 | if (NewStart.isInvalid()) |
| 3219 | return ExprError(); |
| 3220 | NewStart = SemaRef.PerformImplicitConversion( |
| 3221 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3222 | Sema::AA_Converting, |
| 3223 | /*AllowExplicit=*/true); |
| 3224 | if (NewStart.isInvalid()) |
| 3225 | return ExprError(); |
| 3226 | NewStart = SemaRef.PerformImplicitConversion( |
| 3227 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3228 | /*AllowExplicit=*/true); |
| 3229 | if (!NewStart.isUsable()) |
| 3230 | return ExprError(); |
| 3231 | |
| 3232 | auto Init = |
| 3233 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3234 | return Init; |
| 3235 | } |
| 3236 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3237 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3238 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3239 | SourceLocation Loc, ExprResult VarRef, |
| 3240 | ExprResult Start, ExprResult Iter, |
| 3241 | ExprResult Step, bool Subtract) { |
| 3242 | // Add parentheses (for debugging purposes only). |
| 3243 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3244 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3245 | !Step.isUsable()) |
| 3246 | return ExprError(); |
| 3247 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3248 | TransformToNewDefs Transform(SemaRef); |
| 3249 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3250 | if (NewStep.isInvalid()) |
| 3251 | return ExprError(); |
| 3252 | NewStep = SemaRef.PerformImplicitConversion( |
| 3253 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3254 | Sema::AA_Converting, |
| 3255 | /*AllowExplicit=*/true); |
| 3256 | if (NewStep.isInvalid()) |
| 3257 | return ExprError(); |
| 3258 | ExprResult Update = |
| 3259 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3260 | if (!Update.isUsable()) |
| 3261 | return ExprError(); |
| 3262 | |
| 3263 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3264 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3265 | if (NewStart.isInvalid()) |
| 3266 | return ExprError(); |
| 3267 | NewStart = SemaRef.PerformImplicitConversion( |
| 3268 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3269 | Sema::AA_Converting, |
| 3270 | /*AllowExplicit=*/true); |
| 3271 | if (NewStart.isInvalid()) |
| 3272 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3273 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3274 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3275 | if (!Update.isUsable()) |
| 3276 | return ExprError(); |
| 3277 | |
| 3278 | Update = SemaRef.PerformImplicitConversion( |
| 3279 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3280 | if (!Update.isUsable()) |
| 3281 | return ExprError(); |
| 3282 | |
| 3283 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3284 | return Update; |
| 3285 | } |
| 3286 | |
| 3287 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3288 | /// bits. |
| 3289 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3290 | Sema &SemaRef) { |
| 3291 | if (E == nullptr) |
| 3292 | return ExprError(); |
| 3293 | auto &C = SemaRef.Context; |
| 3294 | QualType OldType = E->getType(); |
| 3295 | unsigned HasBits = C.getTypeSize(OldType); |
| 3296 | if (HasBits >= Bits) |
| 3297 | return ExprResult(E); |
| 3298 | // OK to convert to signed, because new type has more bits than old. |
| 3299 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3300 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3301 | true); |
| 3302 | } |
| 3303 | |
| 3304 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3305 | /// into \a Bits bits. |
| 3306 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3307 | if (E == nullptr) |
| 3308 | return false; |
| 3309 | llvm::APSInt Result; |
| 3310 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3311 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3312 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | /// \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] | 3316 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3317 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3318 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3319 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3320 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3321 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3322 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3323 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3324 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3325 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3326 | // Found 'collapse' clause - calculate collapse number. |
| 3327 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3328 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 3329 | NestedLoopCount += Result.getLimitedValue() - 1; |
| 3330 | } |
| 3331 | if (OrderedLoopCountExpr) { |
| 3332 | // Found 'ordered' clause - calculate collapse number. |
| 3333 | llvm::APSInt Result; |
| 3334 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 3335 | NestedLoopCount += Result.getLimitedValue() - 1; |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3336 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3337 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3338 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3339 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3340 | IterSpaces.resize(NestedLoopCount); |
| 3341 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3342 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3343 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3344 | NestedLoopCount, CollapseLoopCountExpr, |
| 3345 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3346 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3347 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3348 | // 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] | 3349 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3350 | // All loops associated with the construct must be perfectly nested; that |
| 3351 | // is, there must be no intervening code nor any OpenMP directive between |
| 3352 | // any two loops. |
| 3353 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3354 | } |
| 3355 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3356 | Built.clear(/* size */ NestedLoopCount); |
| 3357 | |
| 3358 | if (SemaRef.CurContext->isDependentContext()) |
| 3359 | return NestedLoopCount; |
| 3360 | |
| 3361 | // An example of what is generated for the following code: |
| 3362 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3363 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3364 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3365 | // for (k = 0; k < NK; ++k) |
| 3366 | // for (j = J0; j < NJ; j+=2) { |
| 3367 | // <loop body> |
| 3368 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3369 | // |
| 3370 | // We generate the code below. |
| 3371 | // Note: the loop body may be outlined in CodeGen. |
| 3372 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3373 | // iterations and operator+= to calculate counter value. |
| 3374 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3375 | // or i64 is currently supported). |
| 3376 | // |
| 3377 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3378 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3379 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3380 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3381 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3382 | // <loop body (using local i and j)> |
| 3383 | // } |
| 3384 | // i = NI; // assign final values of counters |
| 3385 | // j = NJ; |
| 3386 | // |
| 3387 | |
| 3388 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3389 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3390 | // Precondition tests if there is at least one iteration (all conditions are |
| 3391 | // true). |
| 3392 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3393 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3394 | ExprResult LastIteration32 = WidenIterationCount( |
| 3395 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3396 | N0->IgnoreImpCasts(), N0->getType(), |
| 3397 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3398 | .get(), |
| 3399 | SemaRef); |
| 3400 | ExprResult LastIteration64 = WidenIterationCount( |
| 3401 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3402 | N0->IgnoreImpCasts(), N0->getType(), |
| 3403 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3404 | .get(), |
| 3405 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3406 | |
| 3407 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3408 | return NestedLoopCount; |
| 3409 | |
| 3410 | auto &C = SemaRef.Context; |
| 3411 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3412 | |
| 3413 | Scope *CurScope = DSA.getCurScope(); |
| 3414 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3415 | if (PreCond.isUsable()) { |
| 3416 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3417 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3418 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3419 | auto N = IterSpaces[Cnt].NumIterations; |
| 3420 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3421 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3422 | LastIteration32 = SemaRef.BuildBinOp( |
| 3423 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3424 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3425 | Sema::AA_Converting, |
| 3426 | /*AllowExplicit=*/true) |
| 3427 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3428 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3429 | LastIteration64 = SemaRef.BuildBinOp( |
| 3430 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3431 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3432 | Sema::AA_Converting, |
| 3433 | /*AllowExplicit=*/true) |
| 3434 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | // Choose either the 32-bit or 64-bit version. |
| 3438 | ExprResult LastIteration = LastIteration64; |
| 3439 | if (LastIteration32.isUsable() && |
| 3440 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3441 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3442 | FitsInto( |
| 3443 | 32 /* Bits */, |
| 3444 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3445 | LastIteration64.get(), SemaRef))) |
| 3446 | LastIteration = LastIteration32; |
| 3447 | |
| 3448 | if (!LastIteration.isUsable()) |
| 3449 | return 0; |
| 3450 | |
| 3451 | // Save the number of iterations. |
| 3452 | ExprResult NumIterations = LastIteration; |
| 3453 | { |
| 3454 | LastIteration = SemaRef.BuildBinOp( |
| 3455 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3456 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3457 | if (!LastIteration.isUsable()) |
| 3458 | return 0; |
| 3459 | } |
| 3460 | |
| 3461 | // Calculate the last iteration number beforehand instead of doing this on |
| 3462 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3463 | llvm::APSInt Result; |
| 3464 | bool IsConstant = |
| 3465 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3466 | ExprResult CalcLastIteration; |
| 3467 | if (!IsConstant) { |
| 3468 | SourceLocation SaveLoc; |
| 3469 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3470 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3471 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3472 | ExprResult SaveRef = buildDeclRefExpr( |
| 3473 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3474 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3475 | SaveRef.get(), LastIteration.get()); |
| 3476 | LastIteration = SaveRef; |
| 3477 | |
| 3478 | // Prepare SaveRef + 1. |
| 3479 | NumIterations = SemaRef.BuildBinOp( |
| 3480 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3481 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3482 | if (!NumIterations.isUsable()) |
| 3483 | return 0; |
| 3484 | } |
| 3485 | |
| 3486 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3487 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3488 | QualType VType = LastIteration.get()->getType(); |
| 3489 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3490 | ExprResult LB, UB, IL, ST, EUB; |
| 3491 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3492 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3493 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3494 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3495 | SemaRef.AddInitializerToDecl( |
| 3496 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3497 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3498 | |
| 3499 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3500 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3501 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3502 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3503 | /*DirectInit*/ false, |
| 3504 | /*TypeMayContainAuto*/ false); |
| 3505 | |
| 3506 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3507 | // This will be used to implement clause 'lastprivate'. |
| 3508 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3509 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3510 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3511 | SemaRef.AddInitializerToDecl( |
| 3512 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3513 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3514 | |
| 3515 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3516 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3517 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3518 | SemaRef.AddInitializerToDecl( |
| 3519 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3520 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3521 | |
| 3522 | // Build expression: UB = min(UB, LastIteration) |
| 3523 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3524 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3525 | UB.get(), LastIteration.get()); |
| 3526 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3527 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3528 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3529 | CondOp.get()); |
| 3530 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3531 | } |
| 3532 | |
| 3533 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3534 | ExprResult IV; |
| 3535 | ExprResult Init; |
| 3536 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3537 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3538 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3539 | Expr *RHS = isOpenMPWorksharingDirective(DKind) |
| 3540 | ? LB.get() |
| 3541 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3542 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3543 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3544 | } |
| 3545 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3546 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3547 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3548 | ExprResult Cond = |
| 3549 | isOpenMPWorksharingDirective(DKind) |
| 3550 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3551 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3552 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3553 | |
| 3554 | // Loop increment (IV = IV + 1) |
| 3555 | SourceLocation IncLoc; |
| 3556 | ExprResult Inc = |
| 3557 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3558 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3559 | if (!Inc.isUsable()) |
| 3560 | return 0; |
| 3561 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3562 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3563 | if (!Inc.isUsable()) |
| 3564 | return 0; |
| 3565 | |
| 3566 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3567 | // Used for directives with static scheduling. |
| 3568 | ExprResult NextLB, NextUB; |
| 3569 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3570 | // LB + ST |
| 3571 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3572 | if (!NextLB.isUsable()) |
| 3573 | return 0; |
| 3574 | // LB = LB + ST |
| 3575 | NextLB = |
| 3576 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3577 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3578 | if (!NextLB.isUsable()) |
| 3579 | return 0; |
| 3580 | // UB + ST |
| 3581 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3582 | if (!NextUB.isUsable()) |
| 3583 | return 0; |
| 3584 | // UB = UB + ST |
| 3585 | NextUB = |
| 3586 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3587 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3588 | if (!NextUB.isUsable()) |
| 3589 | return 0; |
| 3590 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3591 | |
| 3592 | // Build updates and final values of the loop counters. |
| 3593 | bool HasErrors = false; |
| 3594 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3595 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3596 | Built.Updates.resize(NestedLoopCount); |
| 3597 | Built.Finals.resize(NestedLoopCount); |
| 3598 | { |
| 3599 | ExprResult Div; |
| 3600 | // Go from inner nested loop to outer. |
| 3601 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3602 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3603 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3604 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3605 | // where Div is product of previous iterations' IS.NumIters. |
| 3606 | ExprResult Iter; |
| 3607 | if (Div.isUsable()) { |
| 3608 | Iter = |
| 3609 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3610 | } else { |
| 3611 | Iter = IV; |
| 3612 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3613 | "unusable div expected on first iteration only"); |
| 3614 | } |
| 3615 | |
| 3616 | if (Cnt != 0 && Iter.isUsable()) |
| 3617 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3618 | IS.NumIterations); |
| 3619 | if (!Iter.isUsable()) { |
| 3620 | HasErrors = true; |
| 3621 | break; |
| 3622 | } |
| 3623 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3624 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3625 | auto *CounterVar = buildDeclRefExpr( |
| 3626 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3627 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3628 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3629 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3630 | IS.CounterInit); |
| 3631 | if (!Init.isUsable()) { |
| 3632 | HasErrors = true; |
| 3633 | break; |
| 3634 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3635 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3636 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3637 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3638 | if (!Update.isUsable()) { |
| 3639 | HasErrors = true; |
| 3640 | break; |
| 3641 | } |
| 3642 | |
| 3643 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3644 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3645 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3646 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3647 | if (!Final.isUsable()) { |
| 3648 | HasErrors = true; |
| 3649 | break; |
| 3650 | } |
| 3651 | |
| 3652 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3653 | if (Cnt != 0) { |
| 3654 | if (Div.isUnset()) |
| 3655 | Div = IS.NumIterations; |
| 3656 | else |
| 3657 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3658 | IS.NumIterations); |
| 3659 | |
| 3660 | // Add parentheses (for debugging purposes only). |
| 3661 | if (Div.isUsable()) |
| 3662 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3663 | if (!Div.isUsable()) { |
| 3664 | HasErrors = true; |
| 3665 | break; |
| 3666 | } |
| 3667 | } |
| 3668 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3669 | HasErrors = true; |
| 3670 | break; |
| 3671 | } |
| 3672 | // Save results |
| 3673 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3674 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3675 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3676 | Built.Updates[Cnt] = Update.get(); |
| 3677 | Built.Finals[Cnt] = Final.get(); |
| 3678 | } |
| 3679 | } |
| 3680 | |
| 3681 | if (HasErrors) |
| 3682 | return 0; |
| 3683 | |
| 3684 | // Save results |
| 3685 | Built.IterationVarRef = IV.get(); |
| 3686 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3687 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3688 | Built.CalcLastIteration = |
| 3689 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3690 | Built.PreCond = PreCond.get(); |
| 3691 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3692 | Built.Init = Init.get(); |
| 3693 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3694 | Built.LB = LB.get(); |
| 3695 | Built.UB = UB.get(); |
| 3696 | Built.IL = IL.get(); |
| 3697 | Built.ST = ST.get(); |
| 3698 | Built.EUB = EUB.get(); |
| 3699 | Built.NLB = NextLB.get(); |
| 3700 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3701 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3702 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3703 | } |
| 3704 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3705 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3706 | auto CollapseClauses = |
| 3707 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 3708 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 3709 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3710 | return nullptr; |
| 3711 | } |
| 3712 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3713 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3714 | auto OrderedClauses = |
| 3715 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 3716 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 3717 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3718 | return nullptr; |
| 3719 | } |
| 3720 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3721 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 3722 | const Expr *Safelen) { |
| 3723 | llvm::APSInt SimdlenRes, SafelenRes; |
| 3724 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 3725 | Simdlen->isInstantiationDependent() || |
| 3726 | Simdlen->containsUnexpandedParameterPack()) |
| 3727 | return false; |
| 3728 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 3729 | Safelen->isInstantiationDependent() || |
| 3730 | Safelen->containsUnexpandedParameterPack()) |
| 3731 | return false; |
| 3732 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 3733 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 3734 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3735 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3736 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3737 | if (SimdlenRes > SafelenRes) { |
| 3738 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 3739 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 3740 | return true; |
| 3741 | } |
| 3742 | return false; |
| 3743 | } |
| 3744 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3745 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3746 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3747 | SourceLocation EndLoc, |
| 3748 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3749 | if (!AStmt) |
| 3750 | return StmtError(); |
| 3751 | |
| 3752 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3753 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3754 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3755 | // define the nested loops number. |
| 3756 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3757 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3758 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3759 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3760 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3761 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3762 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3763 | "omp simd loop exprs were not built"); |
| 3764 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3765 | if (!CurContext->isDependentContext()) { |
| 3766 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3767 | for (auto C : Clauses) { |
| 3768 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3769 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3770 | B.NumIterations, *this, CurScope)) |
| 3771 | return StmtError(); |
| 3772 | } |
| 3773 | } |
| 3774 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3775 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3776 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3777 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3778 | OMPSafelenClause *Safelen = nullptr; |
| 3779 | OMPSimdlenClause *Simdlen = nullptr; |
| 3780 | for (auto *Clause : Clauses) { |
| 3781 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3782 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3783 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3784 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3785 | if (Safelen && Simdlen) |
| 3786 | break; |
| 3787 | } |
| 3788 | if (Simdlen && Safelen && |
| 3789 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3790 | Safelen->getSafelen())) |
| 3791 | return StmtError(); |
| 3792 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3793 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3794 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3795 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3796 | } |
| 3797 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3798 | StmtResult Sema::ActOnOpenMPForDirective( |
| 3799 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3800 | SourceLocation EndLoc, |
| 3801 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3802 | if (!AStmt) |
| 3803 | return StmtError(); |
| 3804 | |
| 3805 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3806 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3807 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3808 | // define the nested loops number. |
| 3809 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3810 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3811 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3812 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3813 | return StmtError(); |
| 3814 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3815 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3816 | "omp for loop exprs were not built"); |
| 3817 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 3818 | if (!CurContext->isDependentContext()) { |
| 3819 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3820 | for (auto C : Clauses) { |
| 3821 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3822 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3823 | B.NumIterations, *this, CurScope)) |
| 3824 | return StmtError(); |
| 3825 | } |
| 3826 | } |
| 3827 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3828 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3829 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3830 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3831 | } |
| 3832 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3833 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 3834 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3835 | SourceLocation EndLoc, |
| 3836 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3837 | if (!AStmt) |
| 3838 | return StmtError(); |
| 3839 | |
| 3840 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3841 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3842 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3843 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3844 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3845 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 3846 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3847 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3848 | if (NestedLoopCount == 0) |
| 3849 | return StmtError(); |
| 3850 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3851 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3852 | "omp for simd loop exprs were not built"); |
| 3853 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 3854 | if (!CurContext->isDependentContext()) { |
| 3855 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3856 | for (auto C : Clauses) { |
| 3857 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3858 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3859 | B.NumIterations, *this, CurScope)) |
| 3860 | return StmtError(); |
| 3861 | } |
| 3862 | } |
| 3863 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3864 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3865 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3866 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3867 | OMPSafelenClause *Safelen = nullptr; |
| 3868 | OMPSimdlenClause *Simdlen = nullptr; |
| 3869 | for (auto *Clause : Clauses) { |
| 3870 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3871 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3872 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3873 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3874 | if (Safelen && Simdlen) |
| 3875 | break; |
| 3876 | } |
| 3877 | if (Simdlen && Safelen && |
| 3878 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3879 | Safelen->getSafelen())) |
| 3880 | return StmtError(); |
| 3881 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3882 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3883 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3884 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3885 | } |
| 3886 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3887 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3888 | Stmt *AStmt, |
| 3889 | SourceLocation StartLoc, |
| 3890 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3891 | if (!AStmt) |
| 3892 | return StmtError(); |
| 3893 | |
| 3894 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3895 | auto BaseStmt = AStmt; |
| 3896 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3897 | BaseStmt = CS->getCapturedStmt(); |
| 3898 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3899 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3900 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3901 | return StmtError(); |
| 3902 | // All associated statements must be '#pragma omp section' except for |
| 3903 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3904 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3905 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3906 | if (SectionStmt) |
| 3907 | Diag(SectionStmt->getLocStart(), |
| 3908 | diag::err_omp_sections_substmt_not_section); |
| 3909 | return StmtError(); |
| 3910 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3911 | cast<OMPSectionDirective>(SectionStmt) |
| 3912 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3913 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3914 | } else { |
| 3915 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 3916 | return StmtError(); |
| 3917 | } |
| 3918 | |
| 3919 | getCurFunction()->setHasBranchProtectedScope(); |
| 3920 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3921 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3922 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3923 | } |
| 3924 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3925 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 3926 | SourceLocation StartLoc, |
| 3927 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3928 | if (!AStmt) |
| 3929 | return StmtError(); |
| 3930 | |
| 3931 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3932 | |
| 3933 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3934 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3935 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3936 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 3937 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3938 | } |
| 3939 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3940 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 3941 | Stmt *AStmt, |
| 3942 | SourceLocation StartLoc, |
| 3943 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3944 | if (!AStmt) |
| 3945 | return StmtError(); |
| 3946 | |
| 3947 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3948 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3949 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3950 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 3951 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 3952 | // The copyprivate clause must not be used with the nowait clause. |
| 3953 | OMPClause *Nowait = nullptr; |
| 3954 | OMPClause *Copyprivate = nullptr; |
| 3955 | for (auto *Clause : Clauses) { |
| 3956 | if (Clause->getClauseKind() == OMPC_nowait) |
| 3957 | Nowait = Clause; |
| 3958 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 3959 | Copyprivate = Clause; |
| 3960 | if (Copyprivate && Nowait) { |
| 3961 | Diag(Copyprivate->getLocStart(), |
| 3962 | diag::err_omp_single_copyprivate_with_nowait); |
| 3963 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 3964 | return StmtError(); |
| 3965 | } |
| 3966 | } |
| 3967 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3968 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3969 | } |
| 3970 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3971 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 3972 | SourceLocation StartLoc, |
| 3973 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3974 | if (!AStmt) |
| 3975 | return StmtError(); |
| 3976 | |
| 3977 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3978 | |
| 3979 | getCurFunction()->setHasBranchProtectedScope(); |
| 3980 | |
| 3981 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3982 | } |
| 3983 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3984 | StmtResult |
| 3985 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 3986 | Stmt *AStmt, SourceLocation StartLoc, |
| 3987 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3988 | if (!AStmt) |
| 3989 | return StmtError(); |
| 3990 | |
| 3991 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3992 | |
| 3993 | getCurFunction()->setHasBranchProtectedScope(); |
| 3994 | |
| 3995 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 3996 | AStmt); |
| 3997 | } |
| 3998 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3999 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4000 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4001 | SourceLocation EndLoc, |
| 4002 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4003 | if (!AStmt) |
| 4004 | return StmtError(); |
| 4005 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4006 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4007 | // 1.2.2 OpenMP Language Terminology |
| 4008 | // Structured block - An executable statement with a single entry at the |
| 4009 | // top and a single exit at the bottom. |
| 4010 | // The point of exit cannot be a branch out of the structured block. |
| 4011 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4012 | CS->getCapturedDecl()->setNothrow(); |
| 4013 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4014 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4015 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4016 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4017 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4018 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4019 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4020 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4021 | if (NestedLoopCount == 0) |
| 4022 | return StmtError(); |
| 4023 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4024 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4025 | "omp parallel for loop exprs were not built"); |
| 4026 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4027 | if (!CurContext->isDependentContext()) { |
| 4028 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4029 | for (auto C : Clauses) { |
| 4030 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4031 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4032 | B.NumIterations, *this, CurScope)) |
| 4033 | return StmtError(); |
| 4034 | } |
| 4035 | } |
| 4036 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4037 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4038 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4039 | NestedLoopCount, Clauses, AStmt, B, |
| 4040 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4041 | } |
| 4042 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4043 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4044 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4045 | SourceLocation EndLoc, |
| 4046 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4047 | if (!AStmt) |
| 4048 | return StmtError(); |
| 4049 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4050 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4051 | // 1.2.2 OpenMP Language Terminology |
| 4052 | // Structured block - An executable statement with a single entry at the |
| 4053 | // top and a single exit at the bottom. |
| 4054 | // The point of exit cannot be a branch out of the structured block. |
| 4055 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4056 | CS->getCapturedDecl()->setNothrow(); |
| 4057 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4058 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4059 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4060 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4061 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4062 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4063 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4064 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4065 | if (NestedLoopCount == 0) |
| 4066 | return StmtError(); |
| 4067 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4068 | if (!CurContext->isDependentContext()) { |
| 4069 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4070 | for (auto C : Clauses) { |
| 4071 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4072 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4073 | B.NumIterations, *this, CurScope)) |
| 4074 | return StmtError(); |
| 4075 | } |
| 4076 | } |
| 4077 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4078 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4079 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4080 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4081 | OMPSafelenClause *Safelen = nullptr; |
| 4082 | OMPSimdlenClause *Simdlen = nullptr; |
| 4083 | for (auto *Clause : Clauses) { |
| 4084 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4085 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4086 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4087 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4088 | if (Safelen && Simdlen) |
| 4089 | break; |
| 4090 | } |
| 4091 | if (Simdlen && Safelen && |
| 4092 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4093 | Safelen->getSafelen())) |
| 4094 | return StmtError(); |
| 4095 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4096 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4097 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4098 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4099 | } |
| 4100 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4101 | StmtResult |
| 4102 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4103 | Stmt *AStmt, SourceLocation StartLoc, |
| 4104 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4105 | if (!AStmt) |
| 4106 | return StmtError(); |
| 4107 | |
| 4108 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4109 | auto BaseStmt = AStmt; |
| 4110 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4111 | BaseStmt = CS->getCapturedStmt(); |
| 4112 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4113 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4114 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4115 | return StmtError(); |
| 4116 | // All associated statements must be '#pragma omp section' except for |
| 4117 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4118 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4119 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4120 | if (SectionStmt) |
| 4121 | Diag(SectionStmt->getLocStart(), |
| 4122 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4123 | return StmtError(); |
| 4124 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4125 | cast<OMPSectionDirective>(SectionStmt) |
| 4126 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4127 | } |
| 4128 | } else { |
| 4129 | Diag(AStmt->getLocStart(), |
| 4130 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4131 | return StmtError(); |
| 4132 | } |
| 4133 | |
| 4134 | getCurFunction()->setHasBranchProtectedScope(); |
| 4135 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4136 | return OMPParallelSectionsDirective::Create( |
| 4137 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4138 | } |
| 4139 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4140 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4141 | Stmt *AStmt, SourceLocation StartLoc, |
| 4142 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4143 | if (!AStmt) |
| 4144 | return StmtError(); |
| 4145 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4146 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4147 | // 1.2.2 OpenMP Language Terminology |
| 4148 | // Structured block - An executable statement with a single entry at the |
| 4149 | // top and a single exit at the bottom. |
| 4150 | // The point of exit cannot be a branch out of the structured block. |
| 4151 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4152 | CS->getCapturedDecl()->setNothrow(); |
| 4153 | |
| 4154 | getCurFunction()->setHasBranchProtectedScope(); |
| 4155 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4156 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4157 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4158 | } |
| 4159 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4160 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4161 | SourceLocation EndLoc) { |
| 4162 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4163 | } |
| 4164 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4165 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4166 | SourceLocation EndLoc) { |
| 4167 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4168 | } |
| 4169 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4170 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4171 | SourceLocation EndLoc) { |
| 4172 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4173 | } |
| 4174 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4175 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4176 | SourceLocation StartLoc, |
| 4177 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4178 | if (!AStmt) |
| 4179 | return StmtError(); |
| 4180 | |
| 4181 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4182 | |
| 4183 | getCurFunction()->setHasBranchProtectedScope(); |
| 4184 | |
| 4185 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4186 | } |
| 4187 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4188 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4189 | SourceLocation StartLoc, |
| 4190 | SourceLocation EndLoc) { |
| 4191 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4192 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4193 | } |
| 4194 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4195 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4196 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4197 | SourceLocation StartLoc, |
| 4198 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4199 | if (!AStmt) |
| 4200 | return StmtError(); |
| 4201 | |
| 4202 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4203 | |
| 4204 | getCurFunction()->setHasBranchProtectedScope(); |
| 4205 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4206 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4207 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4208 | for (auto *C: Clauses) { |
| 4209 | if (C->getClauseKind() == OMPC_threads) |
| 4210 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4211 | else if (C->getClauseKind() == OMPC_simd) |
| 4212 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | // TODO: this must happen only if 'threads' clause specified or if no clauses |
| 4216 | // is specified. |
| 4217 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4218 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4219 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) << (TC != nullptr); |
| 4220 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4221 | return StmtError(); |
| 4222 | } |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4223 | if (!SC && isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
| 4224 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4225 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4226 | // that can appear in the simd region. |
| 4227 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 4228 | return StmtError(); |
| 4229 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4230 | |
| 4231 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4232 | } |
| 4233 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4234 | namespace { |
| 4235 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4236 | /// construct. |
| 4237 | class OpenMPAtomicUpdateChecker { |
| 4238 | /// \brief Error results for atomic update expressions. |
| 4239 | enum ExprAnalysisErrorCode { |
| 4240 | /// \brief A statement is not an expression statement. |
| 4241 | NotAnExpression, |
| 4242 | /// \brief Expression is not builtin binary or unary operation. |
| 4243 | NotABinaryOrUnaryExpression, |
| 4244 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4245 | NotAnUnaryIncDecExpression, |
| 4246 | /// \brief An expression is not of scalar type. |
| 4247 | NotAScalarType, |
| 4248 | /// \brief A binary operation is not an assignment operation. |
| 4249 | NotAnAssignmentOp, |
| 4250 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4251 | NotABinaryExpression, |
| 4252 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4253 | /// expression. |
| 4254 | NotABinaryOperator, |
| 4255 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4256 | /// part. |
| 4257 | NotAnUpdateExpression, |
| 4258 | /// \brief No errors is found. |
| 4259 | NoError |
| 4260 | }; |
| 4261 | /// \brief Reference to Sema. |
| 4262 | Sema &SemaRef; |
| 4263 | /// \brief A location for note diagnostics (when error is found). |
| 4264 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4265 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4266 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4267 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4268 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4269 | /// \brief Helper expression of the form |
| 4270 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4271 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4272 | Expr *UpdateExpr; |
| 4273 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4274 | /// important for non-associative operations. |
| 4275 | bool IsXLHSInRHSPart; |
| 4276 | BinaryOperatorKind Op; |
| 4277 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4278 | /// \brief true if the source expression is a postfix unary operation, false |
| 4279 | /// if it is a prefix unary operation. |
| 4280 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4281 | |
| 4282 | public: |
| 4283 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4284 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4285 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4286 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4287 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4288 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4289 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4290 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4291 | /// \param NoteId Diagnostic note for the main error message. |
| 4292 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4293 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4294 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4295 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4296 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4297 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4298 | /// \brief Return the update expression used in calculation of the updated |
| 4299 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4300 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4301 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4302 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4303 | /// false otherwise. |
| 4304 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4305 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4306 | /// \brief true if the source expression is a postfix unary operation, false |
| 4307 | /// if it is a prefix unary operation. |
| 4308 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4309 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4310 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4311 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4312 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4313 | }; |
| 4314 | } // namespace |
| 4315 | |
| 4316 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4317 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4318 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4319 | SourceLocation ErrorLoc, NoteLoc; |
| 4320 | SourceRange ErrorRange, NoteRange; |
| 4321 | // Allowed constructs are: |
| 4322 | // x = x binop expr; |
| 4323 | // x = expr binop x; |
| 4324 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4325 | X = AtomicBinOp->getLHS(); |
| 4326 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4327 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4328 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4329 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4330 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4331 | Op = AtomicInnerBinOp->getOpcode(); |
| 4332 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4333 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4334 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4335 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4336 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4337 | /*Canonical=*/true); |
| 4338 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4339 | /*Canonical=*/true); |
| 4340 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4341 | /*Canonical=*/true); |
| 4342 | if (XId == LHSId) { |
| 4343 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4344 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4345 | } else if (XId == RHSId) { |
| 4346 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4347 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4348 | } else { |
| 4349 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4350 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4351 | NoteLoc = X->getExprLoc(); |
| 4352 | NoteRange = X->getSourceRange(); |
| 4353 | ErrorFound = NotAnUpdateExpression; |
| 4354 | } |
| 4355 | } else { |
| 4356 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4357 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4358 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4359 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4360 | ErrorFound = NotABinaryOperator; |
| 4361 | } |
| 4362 | } else { |
| 4363 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4364 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4365 | ErrorFound = NotABinaryExpression; |
| 4366 | } |
| 4367 | } else { |
| 4368 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4369 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4370 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4371 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4372 | ErrorFound = NotAnAssignmentOp; |
| 4373 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4374 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4375 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4376 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4377 | return true; |
| 4378 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4379 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4380 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4384 | unsigned NoteId) { |
| 4385 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4386 | SourceLocation ErrorLoc, NoteLoc; |
| 4387 | SourceRange ErrorRange, NoteRange; |
| 4388 | // Allowed constructs are: |
| 4389 | // x++; |
| 4390 | // x--; |
| 4391 | // ++x; |
| 4392 | // --x; |
| 4393 | // x binop= expr; |
| 4394 | // x = x binop expr; |
| 4395 | // x = expr binop x; |
| 4396 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4397 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4398 | if (AtomicBody->getType()->isScalarType() || |
| 4399 | AtomicBody->isInstantiationDependent()) { |
| 4400 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4401 | AtomicBody->IgnoreParenImpCasts())) { |
| 4402 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4403 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4404 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4405 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4406 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4407 | X = AtomicCompAssignOp->getLHS(); |
| 4408 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4409 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4410 | AtomicBody->IgnoreParenImpCasts())) { |
| 4411 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4412 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4413 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4414 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4415 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4416 | // Check for Unary Operation |
| 4417 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4418 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4419 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4420 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4421 | X = AtomicUnaryOp->getSubExpr(); |
| 4422 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4423 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4424 | } else { |
| 4425 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4426 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4427 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4428 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4429 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4430 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4431 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4432 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4433 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4434 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4435 | } |
| 4436 | } else { |
| 4437 | ErrorFound = NotAScalarType; |
| 4438 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4439 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4440 | } |
| 4441 | } else { |
| 4442 | ErrorFound = NotAnExpression; |
| 4443 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4444 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4445 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4446 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4447 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4448 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4449 | return true; |
| 4450 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4451 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4452 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4453 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4454 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4455 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4456 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4457 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4458 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4459 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4460 | auto Update = |
| 4461 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4462 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4463 | if (Update.isInvalid()) |
| 4464 | return true; |
| 4465 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4466 | Sema::AA_Casting); |
| 4467 | if (Update.isInvalid()) |
| 4468 | return true; |
| 4469 | UpdateExpr = Update.get(); |
| 4470 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4471 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4472 | } |
| 4473 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4474 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4475 | Stmt *AStmt, |
| 4476 | SourceLocation StartLoc, |
| 4477 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4478 | if (!AStmt) |
| 4479 | return StmtError(); |
| 4480 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4481 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4482 | // 1.2.2 OpenMP Language Terminology |
| 4483 | // Structured block - An executable statement with a single entry at the |
| 4484 | // top and a single exit at the bottom. |
| 4485 | // The point of exit cannot be a branch out of the structured block. |
| 4486 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4487 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4488 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4489 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4490 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4491 | C->getClauseKind() == OMPC_update || |
| 4492 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4493 | if (AtomicKind != OMPC_unknown) { |
| 4494 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4495 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4496 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4497 | << getOpenMPClauseName(AtomicKind); |
| 4498 | } else { |
| 4499 | AtomicKind = C->getClauseKind(); |
| 4500 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4501 | } |
| 4502 | } |
| 4503 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4504 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4505 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4506 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4507 | Body = EWC->getSubExpr(); |
| 4508 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4509 | Expr *X = nullptr; |
| 4510 | Expr *V = nullptr; |
| 4511 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4512 | Expr *UE = nullptr; |
| 4513 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4514 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4515 | // OpenMP [2.12.6, atomic Construct] |
| 4516 | // In the next expressions: |
| 4517 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4518 | // * During the execution of an atomic region, multiple syntactic |
| 4519 | // occurrences of x must designate the same storage location. |
| 4520 | // * Neither of v and expr (as applicable) may access the storage location |
| 4521 | // designated by x. |
| 4522 | // * Neither of x and expr (as applicable) may access the storage location |
| 4523 | // designated by v. |
| 4524 | // * expr is an expression with scalar type. |
| 4525 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4526 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4527 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4528 | // (expr). This requirement is satisfied if the operators in expr have |
| 4529 | // precedence greater than binop, or by using parentheses around expr or |
| 4530 | // subexpressions of expr. |
| 4531 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4532 | // binop x. This requirement is satisfied if the operators in expr have |
| 4533 | // precedence equal to or greater than binop, or by using parentheses around |
| 4534 | // expr or subexpressions of expr. |
| 4535 | // * For forms that allow multiple occurrences of x, the number of times |
| 4536 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4537 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4538 | enum { |
| 4539 | NotAnExpression, |
| 4540 | NotAnAssignmentOp, |
| 4541 | NotAScalarType, |
| 4542 | NotAnLValue, |
| 4543 | NoError |
| 4544 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4545 | SourceLocation ErrorLoc, NoteLoc; |
| 4546 | SourceRange ErrorRange, NoteRange; |
| 4547 | // If clause is read: |
| 4548 | // v = x; |
| 4549 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4550 | auto AtomicBinOp = |
| 4551 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4552 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4553 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4554 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4555 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4556 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4557 | if (!X->isLValue() || !V->isLValue()) { |
| 4558 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4559 | ErrorFound = NotAnLValue; |
| 4560 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4561 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4562 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4563 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4564 | } |
| 4565 | } else if (!X->isInstantiationDependent() || |
| 4566 | !V->isInstantiationDependent()) { |
| 4567 | auto NotScalarExpr = |
| 4568 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4569 | ? V |
| 4570 | : X; |
| 4571 | ErrorFound = NotAScalarType; |
| 4572 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4573 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4574 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4575 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4576 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4577 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4578 | ErrorFound = NotAnAssignmentOp; |
| 4579 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4580 | ErrorRange = AtomicBody->getSourceRange(); |
| 4581 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4582 | : AtomicBody->getExprLoc(); |
| 4583 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4584 | : AtomicBody->getSourceRange(); |
| 4585 | } |
| 4586 | } else { |
| 4587 | ErrorFound = NotAnExpression; |
| 4588 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4589 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4590 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4591 | if (ErrorFound != NoError) { |
| 4592 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4593 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4594 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4595 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4596 | return StmtError(); |
| 4597 | } else if (CurContext->isDependentContext()) |
| 4598 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4599 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4600 | enum { |
| 4601 | NotAnExpression, |
| 4602 | NotAnAssignmentOp, |
| 4603 | NotAScalarType, |
| 4604 | NotAnLValue, |
| 4605 | NoError |
| 4606 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4607 | SourceLocation ErrorLoc, NoteLoc; |
| 4608 | SourceRange ErrorRange, NoteRange; |
| 4609 | // If clause is write: |
| 4610 | // x = expr; |
| 4611 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4612 | auto AtomicBinOp = |
| 4613 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4614 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4615 | X = AtomicBinOp->getLHS(); |
| 4616 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4617 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4618 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4619 | if (!X->isLValue()) { |
| 4620 | ErrorFound = NotAnLValue; |
| 4621 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4622 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4623 | NoteLoc = X->getExprLoc(); |
| 4624 | NoteRange = X->getSourceRange(); |
| 4625 | } |
| 4626 | } else if (!X->isInstantiationDependent() || |
| 4627 | !E->isInstantiationDependent()) { |
| 4628 | auto NotScalarExpr = |
| 4629 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4630 | ? E |
| 4631 | : X; |
| 4632 | ErrorFound = NotAScalarType; |
| 4633 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4634 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4635 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4636 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4637 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4638 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4639 | ErrorFound = NotAnAssignmentOp; |
| 4640 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4641 | ErrorRange = AtomicBody->getSourceRange(); |
| 4642 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4643 | : AtomicBody->getExprLoc(); |
| 4644 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4645 | : AtomicBody->getSourceRange(); |
| 4646 | } |
| 4647 | } else { |
| 4648 | ErrorFound = NotAnExpression; |
| 4649 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4650 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4651 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4652 | if (ErrorFound != NoError) { |
| 4653 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4654 | << ErrorRange; |
| 4655 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4656 | << NoteRange; |
| 4657 | return StmtError(); |
| 4658 | } else if (CurContext->isDependentContext()) |
| 4659 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4660 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4661 | // If clause is update: |
| 4662 | // x++; |
| 4663 | // x--; |
| 4664 | // ++x; |
| 4665 | // --x; |
| 4666 | // x binop= expr; |
| 4667 | // x = x binop expr; |
| 4668 | // x = expr binop x; |
| 4669 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4670 | if (Checker.checkStatement( |
| 4671 | Body, (AtomicKind == OMPC_update) |
| 4672 | ? diag::err_omp_atomic_update_not_expression_statement |
| 4673 | : diag::err_omp_atomic_not_expression_statement, |
| 4674 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4675 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4676 | if (!CurContext->isDependentContext()) { |
| 4677 | E = Checker.getExpr(); |
| 4678 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4679 | UE = Checker.getUpdateExpr(); |
| 4680 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4681 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4682 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4683 | enum { |
| 4684 | NotAnAssignmentOp, |
| 4685 | NotACompoundStatement, |
| 4686 | NotTwoSubstatements, |
| 4687 | NotASpecificExpression, |
| 4688 | NoError |
| 4689 | } ErrorFound = NoError; |
| 4690 | SourceLocation ErrorLoc, NoteLoc; |
| 4691 | SourceRange ErrorRange, NoteRange; |
| 4692 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 4693 | // If clause is a capture: |
| 4694 | // v = x++; |
| 4695 | // v = x--; |
| 4696 | // v = ++x; |
| 4697 | // v = --x; |
| 4698 | // v = x binop= expr; |
| 4699 | // v = x = x binop expr; |
| 4700 | // v = x = expr binop x; |
| 4701 | auto *AtomicBinOp = |
| 4702 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4703 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4704 | V = AtomicBinOp->getLHS(); |
| 4705 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4706 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4707 | if (Checker.checkStatement( |
| 4708 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 4709 | diag::note_omp_atomic_update)) |
| 4710 | return StmtError(); |
| 4711 | E = Checker.getExpr(); |
| 4712 | X = Checker.getX(); |
| 4713 | UE = Checker.getUpdateExpr(); |
| 4714 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 4715 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4716 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4717 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4718 | ErrorRange = AtomicBody->getSourceRange(); |
| 4719 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4720 | : AtomicBody->getExprLoc(); |
| 4721 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4722 | : AtomicBody->getSourceRange(); |
| 4723 | ErrorFound = NotAnAssignmentOp; |
| 4724 | } |
| 4725 | if (ErrorFound != NoError) { |
| 4726 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 4727 | << ErrorRange; |
| 4728 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4729 | return StmtError(); |
| 4730 | } else if (CurContext->isDependentContext()) { |
| 4731 | UE = V = E = X = nullptr; |
| 4732 | } |
| 4733 | } else { |
| 4734 | // If clause is a capture: |
| 4735 | // { v = x; x = expr; } |
| 4736 | // { v = x; x++; } |
| 4737 | // { v = x; x--; } |
| 4738 | // { v = x; ++x; } |
| 4739 | // { v = x; --x; } |
| 4740 | // { v = x; x binop= expr; } |
| 4741 | // { v = x; x = x binop expr; } |
| 4742 | // { v = x; x = expr binop x; } |
| 4743 | // { x++; v = x; } |
| 4744 | // { x--; v = x; } |
| 4745 | // { ++x; v = x; } |
| 4746 | // { --x; v = x; } |
| 4747 | // { x binop= expr; v = x; } |
| 4748 | // { x = x binop expr; v = x; } |
| 4749 | // { x = expr binop x; v = x; } |
| 4750 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 4751 | // Check that this is { expr1; expr2; } |
| 4752 | if (CS->size() == 2) { |
| 4753 | auto *First = CS->body_front(); |
| 4754 | auto *Second = CS->body_back(); |
| 4755 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 4756 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4757 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 4758 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4759 | // Need to find what subexpression is 'v' and what is 'x'. |
| 4760 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4761 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 4762 | BinaryOperator *BinOp = nullptr; |
| 4763 | if (IsUpdateExprFound) { |
| 4764 | BinOp = dyn_cast<BinaryOperator>(First); |
| 4765 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4766 | } |
| 4767 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4768 | // { v = x; x++; } |
| 4769 | // { v = x; x--; } |
| 4770 | // { v = x; ++x; } |
| 4771 | // { v = x; --x; } |
| 4772 | // { v = x; x binop= expr; } |
| 4773 | // { v = x; x = x binop expr; } |
| 4774 | // { v = x; x = expr binop x; } |
| 4775 | // Check that the first expression has form v = x. |
| 4776 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4777 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4778 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4779 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4780 | IsUpdateExprFound = XId == PossibleXId; |
| 4781 | if (IsUpdateExprFound) { |
| 4782 | V = BinOp->getLHS(); |
| 4783 | X = Checker.getX(); |
| 4784 | E = Checker.getExpr(); |
| 4785 | UE = Checker.getUpdateExpr(); |
| 4786 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4787 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4788 | } |
| 4789 | } |
| 4790 | if (!IsUpdateExprFound) { |
| 4791 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 4792 | BinOp = nullptr; |
| 4793 | if (IsUpdateExprFound) { |
| 4794 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 4795 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4796 | } |
| 4797 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4798 | // { x++; v = x; } |
| 4799 | // { x--; v = x; } |
| 4800 | // { ++x; v = x; } |
| 4801 | // { --x; v = x; } |
| 4802 | // { x binop= expr; v = x; } |
| 4803 | // { x = x binop expr; v = x; } |
| 4804 | // { x = expr binop x; v = x; } |
| 4805 | // Check that the second expression has form v = x. |
| 4806 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4807 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4808 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4809 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4810 | IsUpdateExprFound = XId == PossibleXId; |
| 4811 | if (IsUpdateExprFound) { |
| 4812 | V = BinOp->getLHS(); |
| 4813 | X = Checker.getX(); |
| 4814 | E = Checker.getExpr(); |
| 4815 | UE = Checker.getUpdateExpr(); |
| 4816 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4817 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4818 | } |
| 4819 | } |
| 4820 | } |
| 4821 | if (!IsUpdateExprFound) { |
| 4822 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4823 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 4824 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 4825 | if (!FirstExpr || !SecondExpr || |
| 4826 | !(FirstExpr->isInstantiationDependent() || |
| 4827 | SecondExpr->isInstantiationDependent())) { |
| 4828 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 4829 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4830 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4831 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 4832 | : First->getLocStart(); |
| 4833 | NoteRange = ErrorRange = FirstBinOp |
| 4834 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4835 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4836 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4837 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 4838 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 4839 | ErrorFound = NotAnAssignmentOp; |
| 4840 | NoteLoc = ErrorLoc = SecondBinOp |
| 4841 | ? SecondBinOp->getOperatorLoc() |
| 4842 | : Second->getLocStart(); |
| 4843 | NoteRange = ErrorRange = |
| 4844 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 4845 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4846 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4847 | auto *PossibleXRHSInFirst = |
| 4848 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4849 | auto *PossibleXLHSInSecond = |
| 4850 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4851 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 4852 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 4853 | /*Canonical=*/true); |
| 4854 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 4855 | /*Canonical=*/true); |
| 4856 | IsUpdateExprFound = X1Id == X2Id; |
| 4857 | if (IsUpdateExprFound) { |
| 4858 | V = FirstBinOp->getLHS(); |
| 4859 | X = SecondBinOp->getLHS(); |
| 4860 | E = SecondBinOp->getRHS(); |
| 4861 | UE = nullptr; |
| 4862 | IsXLHSInRHSPart = false; |
| 4863 | IsPostfixUpdate = true; |
| 4864 | } else { |
| 4865 | ErrorFound = NotASpecificExpression; |
| 4866 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 4867 | ErrorRange = FirstBinOp->getSourceRange(); |
| 4868 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 4869 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 4870 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4871 | } |
| 4872 | } |
| 4873 | } |
| 4874 | } |
| 4875 | } else { |
| 4876 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4877 | NoteRange = ErrorRange = |
| 4878 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4879 | ErrorFound = NotTwoSubstatements; |
| 4880 | } |
| 4881 | } else { |
| 4882 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4883 | NoteRange = ErrorRange = |
| 4884 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4885 | ErrorFound = NotACompoundStatement; |
| 4886 | } |
| 4887 | if (ErrorFound != NoError) { |
| 4888 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 4889 | << ErrorRange; |
| 4890 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4891 | return StmtError(); |
| 4892 | } else if (CurContext->isDependentContext()) { |
| 4893 | UE = V = E = X = nullptr; |
| 4894 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4895 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4896 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4897 | |
| 4898 | getCurFunction()->setHasBranchProtectedScope(); |
| 4899 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4900 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4901 | X, V, E, UE, IsXLHSInRHSPart, |
| 4902 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4905 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 4906 | Stmt *AStmt, |
| 4907 | SourceLocation StartLoc, |
| 4908 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4909 | if (!AStmt) |
| 4910 | return StmtError(); |
| 4911 | |
| 4912 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4913 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4914 | // OpenMP [2.16, Nesting of Regions] |
| 4915 | // If specified, a teams construct must be contained within a target |
| 4916 | // construct. That target construct must contain no statements or directives |
| 4917 | // outside of the teams construct. |
| 4918 | if (DSAStack->hasInnerTeamsRegion()) { |
| 4919 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 4920 | bool OMPTeamsFound = true; |
| 4921 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 4922 | auto I = CS->body_begin(); |
| 4923 | while (I != CS->body_end()) { |
| 4924 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 4925 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 4926 | OMPTeamsFound = false; |
| 4927 | break; |
| 4928 | } |
| 4929 | ++I; |
| 4930 | } |
| 4931 | assert(I != CS->body_end() && "Not found statement"); |
| 4932 | S = *I; |
| 4933 | } |
| 4934 | if (!OMPTeamsFound) { |
| 4935 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 4936 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 4937 | diag::note_omp_nested_teams_construct_here); |
| 4938 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 4939 | << isa<OMPExecutableDirective>(S); |
| 4940 | return StmtError(); |
| 4941 | } |
| 4942 | } |
| 4943 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4944 | getCurFunction()->setHasBranchProtectedScope(); |
| 4945 | |
| 4946 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4947 | } |
| 4948 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4949 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 4950 | Stmt *AStmt, |
| 4951 | SourceLocation StartLoc, |
| 4952 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4953 | if (!AStmt) |
| 4954 | return StmtError(); |
| 4955 | |
| 4956 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4957 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4958 | getCurFunction()->setHasBranchProtectedScope(); |
| 4959 | |
| 4960 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 4961 | AStmt); |
| 4962 | } |
| 4963 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4964 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 4965 | Stmt *AStmt, SourceLocation StartLoc, |
| 4966 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4967 | if (!AStmt) |
| 4968 | return StmtError(); |
| 4969 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4970 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4971 | // 1.2.2 OpenMP Language Terminology |
| 4972 | // Structured block - An executable statement with a single entry at the |
| 4973 | // top and a single exit at the bottom. |
| 4974 | // The point of exit cannot be a branch out of the structured block. |
| 4975 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4976 | CS->getCapturedDecl()->setNothrow(); |
| 4977 | |
| 4978 | getCurFunction()->setHasBranchProtectedScope(); |
| 4979 | |
| 4980 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4981 | } |
| 4982 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4983 | StmtResult |
| 4984 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 4985 | SourceLocation EndLoc, |
| 4986 | OpenMPDirectiveKind CancelRegion) { |
| 4987 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4988 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4989 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4990 | << getOpenMPDirectiveName(CancelRegion); |
| 4991 | return StmtError(); |
| 4992 | } |
| 4993 | if (DSAStack->isParentNowaitRegion()) { |
| 4994 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 4995 | return StmtError(); |
| 4996 | } |
| 4997 | if (DSAStack->isParentOrderedRegion()) { |
| 4998 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 4999 | return StmtError(); |
| 5000 | } |
| 5001 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5002 | CancelRegion); |
| 5003 | } |
| 5004 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5005 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5006 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5007 | SourceLocation EndLoc, |
| 5008 | OpenMPDirectiveKind CancelRegion) { |
| 5009 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5010 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5011 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5012 | << getOpenMPDirectiveName(CancelRegion); |
| 5013 | return StmtError(); |
| 5014 | } |
| 5015 | if (DSAStack->isParentNowaitRegion()) { |
| 5016 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5017 | return StmtError(); |
| 5018 | } |
| 5019 | if (DSAStack->isParentOrderedRegion()) { |
| 5020 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5021 | return StmtError(); |
| 5022 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5023 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5024 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5025 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5028 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5029 | SourceLocation StartLoc, |
| 5030 | SourceLocation LParenLoc, |
| 5031 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5032 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5033 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5034 | case OMPC_final: |
| 5035 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5036 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5037 | case OMPC_num_threads: |
| 5038 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5039 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5040 | case OMPC_safelen: |
| 5041 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5042 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5043 | case OMPC_simdlen: |
| 5044 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5045 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5046 | case OMPC_collapse: |
| 5047 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5048 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5049 | case OMPC_ordered: |
| 5050 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5051 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5052 | case OMPC_device: |
| 5053 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5054 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5055 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5056 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5057 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5058 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5059 | case OMPC_private: |
| 5060 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5061 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5062 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5063 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5064 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5065 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5066 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5067 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5068 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5069 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5070 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5071 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5072 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5073 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5074 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5075 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5076 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5077 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5078 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5079 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5080 | case OMPC_simd: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5081 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5082 | llvm_unreachable("Clause is not allowed."); |
| 5083 | } |
| 5084 | return Res; |
| 5085 | } |
| 5086 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5087 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5088 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5089 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5090 | SourceLocation NameModifierLoc, |
| 5091 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5092 | SourceLocation EndLoc) { |
| 5093 | Expr *ValExpr = Condition; |
| 5094 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5095 | !Condition->isInstantiationDependent() && |
| 5096 | !Condition->containsUnexpandedParameterPack()) { |
| 5097 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5098 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5099 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5100 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5101 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5102 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5103 | } |
| 5104 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5105 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5106 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5107 | } |
| 5108 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5109 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5110 | SourceLocation StartLoc, |
| 5111 | SourceLocation LParenLoc, |
| 5112 | SourceLocation EndLoc) { |
| 5113 | Expr *ValExpr = Condition; |
| 5114 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5115 | !Condition->isInstantiationDependent() && |
| 5116 | !Condition->containsUnexpandedParameterPack()) { |
| 5117 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5118 | Condition->getExprLoc(), Condition); |
| 5119 | if (Val.isInvalid()) |
| 5120 | return nullptr; |
| 5121 | |
| 5122 | ValExpr = Val.get(); |
| 5123 | } |
| 5124 | |
| 5125 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5126 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5127 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5128 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5129 | if (!Op) |
| 5130 | return ExprError(); |
| 5131 | |
| 5132 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5133 | public: |
| 5134 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5135 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5136 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5137 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5138 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5139 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5140 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5141 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5142 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5143 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5144 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5145 | QualType T, |
| 5146 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5147 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5148 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5149 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5150 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5151 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5152 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5153 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5154 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5155 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5156 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5157 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5158 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5159 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5160 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5161 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5162 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5163 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5164 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5165 | llvm_unreachable("conversion functions are permitted"); |
| 5166 | } |
| 5167 | } ConvertDiagnoser; |
| 5168 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5169 | } |
| 5170 | |
| 5171 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5172 | SourceLocation StartLoc, |
| 5173 | SourceLocation LParenLoc, |
| 5174 | SourceLocation EndLoc) { |
| 5175 | Expr *ValExpr = NumThreads; |
| 5176 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5177 | !NumThreads->containsUnexpandedParameterPack()) { |
| 5178 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 5179 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5180 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5181 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5182 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5183 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5184 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5185 | |
| 5186 | // OpenMP [2.5, Restrictions] |
| 5187 | // The num_threads expression must evaluate to a positive integer value. |
| 5188 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5189 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 5190 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5191 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 5192 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5193 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5194 | } |
| 5195 | } |
| 5196 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5197 | return new (Context) |
| 5198 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5199 | } |
| 5200 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5201 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 5202 | OpenMPClauseKind CKind) { |
| 5203 | if (!E) |
| 5204 | return ExprError(); |
| 5205 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5206 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5207 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5208 | llvm::APSInt Result; |
| 5209 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5210 | if (ICE.isInvalid()) |
| 5211 | return ExprError(); |
| 5212 | if (!Result.isStrictlyPositive()) { |
| 5213 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 5214 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 5215 | return ExprError(); |
| 5216 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5217 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5218 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5219 | << E->getSourceRange(); |
| 5220 | return ExprError(); |
| 5221 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5222 | if (CKind == OMPC_collapse) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5223 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 5224 | Result.getExtValue()); |
| 5225 | } else if (CKind == OMPC_ordered) { |
| 5226 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 5227 | Result.getExtValue()); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5228 | } |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5229 | return ICE; |
| 5230 | } |
| 5231 | |
| 5232 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5233 | SourceLocation LParenLoc, |
| 5234 | SourceLocation EndLoc) { |
| 5235 | // OpenMP [2.8.1, simd construct, Description] |
| 5236 | // The parameter of the safelen clause must be a constant |
| 5237 | // positive integer expression. |
| 5238 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5239 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5240 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5241 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5242 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5243 | } |
| 5244 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5245 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5246 | SourceLocation LParenLoc, |
| 5247 | SourceLocation EndLoc) { |
| 5248 | // OpenMP [2.8.1, simd construct, Description] |
| 5249 | // The parameter of the simdlen clause must be a constant |
| 5250 | // positive integer expression. |
| 5251 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5252 | if (Simdlen.isInvalid()) |
| 5253 | return nullptr; |
| 5254 | return new (Context) |
| 5255 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5256 | } |
| 5257 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5258 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5259 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5260 | SourceLocation LParenLoc, |
| 5261 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5262 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5263 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5264 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5265 | // The parameter of the collapse clause must be a constant |
| 5266 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5267 | ExprResult NumForLoopsResult = |
| 5268 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5269 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5270 | return nullptr; |
| 5271 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5272 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5273 | } |
| 5274 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5275 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5276 | SourceLocation EndLoc, |
| 5277 | SourceLocation LParenLoc, |
| 5278 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5279 | // OpenMP [2.7.1, loop construct, Description] |
| 5280 | // OpenMP [2.8.1, simd construct, Description] |
| 5281 | // OpenMP [2.9.6, distribute construct, Description] |
| 5282 | // The parameter of the ordered clause must be a constant |
| 5283 | // positive integer expression if any. |
| 5284 | if (NumForLoops && LParenLoc.isValid()) { |
| 5285 | ExprResult NumForLoopsResult = |
| 5286 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5287 | if (NumForLoopsResult.isInvalid()) |
| 5288 | return nullptr; |
| 5289 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5290 | } else |
| 5291 | NumForLoops = nullptr; |
| 5292 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5293 | return new (Context) |
| 5294 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5295 | } |
| 5296 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5297 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5298 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5299 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5300 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5301 | switch (Kind) { |
| 5302 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5303 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5304 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5305 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5306 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5307 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5308 | Res = ActOnOpenMPProcBindClause( |
| 5309 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5310 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5311 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5312 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5313 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5314 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5315 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5316 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5317 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5318 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5319 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5320 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5321 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5322 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5323 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5324 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5325 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5326 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5327 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5328 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5329 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5330 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5331 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5332 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5333 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5334 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5335 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5336 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5337 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5338 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5339 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5340 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5341 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5342 | case OMPC_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5343 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5344 | llvm_unreachable("Clause is not allowed."); |
| 5345 | } |
| 5346 | return Res; |
| 5347 | } |
| 5348 | |
| 5349 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 5350 | SourceLocation KindKwLoc, |
| 5351 | SourceLocation StartLoc, |
| 5352 | SourceLocation LParenLoc, |
| 5353 | SourceLocation EndLoc) { |
| 5354 | if (Kind == OMPC_DEFAULT_unknown) { |
| 5355 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5356 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 5357 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 5358 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5359 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5360 | Values += "'"; |
| 5361 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 5362 | Values += "'"; |
| 5363 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5364 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5365 | Values += " or "; |
| 5366 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5367 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5368 | break; |
| 5369 | default: |
| 5370 | Values += Sep; |
| 5371 | break; |
| 5372 | } |
| 5373 | } |
| 5374 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5375 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5376 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5377 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5378 | switch (Kind) { |
| 5379 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5380 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5381 | break; |
| 5382 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5383 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5384 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5385 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5386 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5387 | break; |
| 5388 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5389 | return new (Context) |
| 5390 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5393 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5394 | SourceLocation KindKwLoc, |
| 5395 | SourceLocation StartLoc, |
| 5396 | SourceLocation LParenLoc, |
| 5397 | SourceLocation EndLoc) { |
| 5398 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5399 | std::string Values; |
| 5400 | std::string Sep(", "); |
| 5401 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 5402 | Values += "'"; |
| 5403 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 5404 | Values += "'"; |
| 5405 | switch (i) { |
| 5406 | case OMPC_PROC_BIND_unknown - 2: |
| 5407 | Values += " or "; |
| 5408 | break; |
| 5409 | case OMPC_PROC_BIND_unknown - 1: |
| 5410 | break; |
| 5411 | default: |
| 5412 | Values += Sep; |
| 5413 | break; |
| 5414 | } |
| 5415 | } |
| 5416 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5417 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5418 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5419 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5420 | return new (Context) |
| 5421 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5422 | } |
| 5423 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5424 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 5425 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 5426 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5427 | SourceLocation ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5428 | SourceLocation EndLoc) { |
| 5429 | OMPClause *Res = nullptr; |
| 5430 | switch (Kind) { |
| 5431 | case OMPC_schedule: |
| 5432 | Res = ActOnOpenMPScheduleClause( |
| 5433 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5434 | LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5435 | break; |
| 5436 | case OMPC_if: |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5437 | Res = |
| 5438 | ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr, |
| 5439 | StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
| 5440 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5441 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5442 | case OMPC_num_threads: |
| 5443 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5444 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5445 | case OMPC_collapse: |
| 5446 | case OMPC_default: |
| 5447 | case OMPC_proc_bind: |
| 5448 | case OMPC_private: |
| 5449 | case OMPC_firstprivate: |
| 5450 | case OMPC_lastprivate: |
| 5451 | case OMPC_shared: |
| 5452 | case OMPC_reduction: |
| 5453 | case OMPC_linear: |
| 5454 | case OMPC_aligned: |
| 5455 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5456 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5457 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5458 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5459 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5460 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5461 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5462 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5463 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5464 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5465 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5466 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5467 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5468 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5469 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5470 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5471 | case OMPC_simd: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5472 | case OMPC_unknown: |
| 5473 | llvm_unreachable("Clause is not allowed."); |
| 5474 | } |
| 5475 | return Res; |
| 5476 | } |
| 5477 | |
| 5478 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 5479 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 5480 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 5481 | SourceLocation EndLoc) { |
| 5482 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 5483 | std::string Values; |
| 5484 | std::string Sep(", "); |
| 5485 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 5486 | Values += "'"; |
| 5487 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 5488 | Values += "'"; |
| 5489 | switch (i) { |
| 5490 | case OMPC_SCHEDULE_unknown - 2: |
| 5491 | Values += " or "; |
| 5492 | break; |
| 5493 | case OMPC_SCHEDULE_unknown - 1: |
| 5494 | break; |
| 5495 | default: |
| 5496 | Values += Sep; |
| 5497 | break; |
| 5498 | } |
| 5499 | } |
| 5500 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 5501 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 5502 | return nullptr; |
| 5503 | } |
| 5504 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5505 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5506 | if (ChunkSize) { |
| 5507 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 5508 | !ChunkSize->isInstantiationDependent() && |
| 5509 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 5510 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 5511 | ExprResult Val = |
| 5512 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 5513 | if (Val.isInvalid()) |
| 5514 | return nullptr; |
| 5515 | |
| 5516 | ValExpr = Val.get(); |
| 5517 | |
| 5518 | // OpenMP [2.7.1, Restrictions] |
| 5519 | // chunk_size must be a loop invariant integer expression with a positive |
| 5520 | // value. |
| 5521 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5522 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 5523 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 5524 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 5525 | << "schedule" << ChunkSize->getSourceRange(); |
| 5526 | return nullptr; |
| 5527 | } |
| 5528 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 5529 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 5530 | ChunkSize->getType(), ".chunk."); |
| 5531 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 5532 | ChunkSize->getExprLoc(), |
| 5533 | /*RefersToCapture=*/true); |
| 5534 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5535 | } |
| 5536 | } |
| 5537 | } |
| 5538 | |
| 5539 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5540 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5541 | } |
| 5542 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5543 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 5544 | SourceLocation StartLoc, |
| 5545 | SourceLocation EndLoc) { |
| 5546 | OMPClause *Res = nullptr; |
| 5547 | switch (Kind) { |
| 5548 | case OMPC_ordered: |
| 5549 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 5550 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5551 | case OMPC_nowait: |
| 5552 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 5553 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5554 | case OMPC_untied: |
| 5555 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 5556 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5557 | case OMPC_mergeable: |
| 5558 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 5559 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5560 | case OMPC_read: |
| 5561 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 5562 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5563 | case OMPC_write: |
| 5564 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 5565 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5566 | case OMPC_update: |
| 5567 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 5568 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5569 | case OMPC_capture: |
| 5570 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 5571 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5572 | case OMPC_seq_cst: |
| 5573 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 5574 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5575 | case OMPC_threads: |
| 5576 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 5577 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5578 | case OMPC_simd: |
| 5579 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 5580 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5581 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5582 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5583 | case OMPC_num_threads: |
| 5584 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5585 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5586 | case OMPC_collapse: |
| 5587 | case OMPC_schedule: |
| 5588 | case OMPC_private: |
| 5589 | case OMPC_firstprivate: |
| 5590 | case OMPC_lastprivate: |
| 5591 | case OMPC_shared: |
| 5592 | case OMPC_reduction: |
| 5593 | case OMPC_linear: |
| 5594 | case OMPC_aligned: |
| 5595 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5596 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5597 | case OMPC_default: |
| 5598 | case OMPC_proc_bind: |
| 5599 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5600 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5601 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5602 | case OMPC_device: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5603 | case OMPC_unknown: |
| 5604 | llvm_unreachable("Clause is not allowed."); |
| 5605 | } |
| 5606 | return Res; |
| 5607 | } |
| 5608 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5609 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 5610 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5611 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5612 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 5613 | } |
| 5614 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5615 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 5616 | SourceLocation EndLoc) { |
| 5617 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 5618 | } |
| 5619 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5620 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 5621 | SourceLocation EndLoc) { |
| 5622 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 5623 | } |
| 5624 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5625 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 5626 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5627 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 5628 | } |
| 5629 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5630 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 5631 | SourceLocation EndLoc) { |
| 5632 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 5633 | } |
| 5634 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5635 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 5636 | SourceLocation EndLoc) { |
| 5637 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 5638 | } |
| 5639 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5640 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 5641 | SourceLocation EndLoc) { |
| 5642 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 5643 | } |
| 5644 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5645 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 5646 | SourceLocation EndLoc) { |
| 5647 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 5648 | } |
| 5649 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5650 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 5651 | SourceLocation EndLoc) { |
| 5652 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 5653 | } |
| 5654 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5655 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 5656 | SourceLocation EndLoc) { |
| 5657 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 5658 | } |
| 5659 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5660 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 5661 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 5662 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 5663 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5664 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5665 | OpenMPLinearClauseKind LinKind, SourceLocation DepLinLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5666 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5667 | switch (Kind) { |
| 5668 | case OMPC_private: |
| 5669 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5670 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5671 | case OMPC_firstprivate: |
| 5672 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5673 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5674 | case OMPC_lastprivate: |
| 5675 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5676 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5677 | case OMPC_shared: |
| 5678 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5679 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5680 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5681 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 5682 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5683 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5684 | case OMPC_linear: |
| 5685 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5686 | LinKind, DepLinLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5687 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5688 | case OMPC_aligned: |
| 5689 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 5690 | ColonLoc, EndLoc); |
| 5691 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5692 | case OMPC_copyin: |
| 5693 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5694 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5695 | case OMPC_copyprivate: |
| 5696 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5697 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5698 | case OMPC_flush: |
| 5699 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5700 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5701 | case OMPC_depend: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5702 | Res = ActOnOpenMPDependClause(DepKind, DepLinLoc, ColonLoc, VarList, StartLoc, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5703 | LParenLoc, EndLoc); |
| 5704 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5705 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5706 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5707 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5708 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5709 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5710 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5711 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5712 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5713 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5714 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5715 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5716 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5717 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5718 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5719 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5720 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5721 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5722 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5723 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5724 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5725 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5726 | case OMPC_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5727 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5728 | llvm_unreachable("Clause is not allowed."); |
| 5729 | } |
| 5730 | return Res; |
| 5731 | } |
| 5732 | |
| 5733 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 5734 | SourceLocation StartLoc, |
| 5735 | SourceLocation LParenLoc, |
| 5736 | SourceLocation EndLoc) { |
| 5737 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5738 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5739 | for (auto &RefExpr : VarList) { |
| 5740 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 5741 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5742 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5743 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5744 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5745 | continue; |
| 5746 | } |
| 5747 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5748 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5749 | // OpenMP [2.1, C/C++] |
| 5750 | // A list item is a variable name. |
| 5751 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5752 | // A variable that is part of another variable (as an array or |
| 5753 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5754 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5755 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5756 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5757 | continue; |
| 5758 | } |
| 5759 | Decl *D = DE->getDecl(); |
| 5760 | VarDecl *VD = cast<VarDecl>(D); |
| 5761 | |
| 5762 | QualType Type = VD->getType(); |
| 5763 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5764 | // It will be analyzed later. |
| 5765 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5766 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5767 | continue; |
| 5768 | } |
| 5769 | |
| 5770 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5771 | // A variable that appears in a private clause must not have an incomplete |
| 5772 | // type or a reference type. |
| 5773 | if (RequireCompleteType(ELoc, Type, |
| 5774 | diag::err_omp_private_incomplete_type)) { |
| 5775 | continue; |
| 5776 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5777 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5778 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5779 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5780 | // in a Construct] |
| 5781 | // Variables with the predetermined data-sharing attributes may not be |
| 5782 | // listed in data-sharing attributes clauses, except for the cases |
| 5783 | // listed below. For these exceptions only, listing a predetermined |
| 5784 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5785 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5786 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5787 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5788 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5789 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5790 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5791 | continue; |
| 5792 | } |
| 5793 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5794 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5795 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5796 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5797 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5798 | << getOpenMPClauseName(OMPC_private) << Type |
| 5799 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5800 | bool IsDecl = |
| 5801 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5802 | Diag(VD->getLocation(), |
| 5803 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5804 | << VD; |
| 5805 | continue; |
| 5806 | } |
| 5807 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5808 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 5809 | // A variable of class type (or array thereof) that appears in a private |
| 5810 | // clause requires an accessible, unambiguous default constructor for the |
| 5811 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5812 | // Generate helper private variable and initialize it with the default |
| 5813 | // value. The address of the original variable is replaced by the address of |
| 5814 | // the new private variable in CodeGen. This new variable is not added to |
| 5815 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 5816 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5817 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 5818 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 5819 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5820 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5821 | if (VDPrivate->isInvalidDecl()) |
| 5822 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5823 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5824 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5825 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5826 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5827 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5828 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5829 | } |
| 5830 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5831 | if (Vars.empty()) |
| 5832 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5833 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5834 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 5835 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5836 | } |
| 5837 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5838 | namespace { |
| 5839 | class DiagsUninitializedSeveretyRAII { |
| 5840 | private: |
| 5841 | DiagnosticsEngine &Diags; |
| 5842 | SourceLocation SavedLoc; |
| 5843 | bool IsIgnored; |
| 5844 | |
| 5845 | public: |
| 5846 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 5847 | bool IsIgnored) |
| 5848 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 5849 | if (!IsIgnored) { |
| 5850 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 5851 | /*Map*/ diag::Severity::Ignored, Loc); |
| 5852 | } |
| 5853 | } |
| 5854 | ~DiagsUninitializedSeveretyRAII() { |
| 5855 | if (!IsIgnored) |
| 5856 | Diags.popMappings(SavedLoc); |
| 5857 | } |
| 5858 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 5859 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5860 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5861 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 5862 | SourceLocation StartLoc, |
| 5863 | SourceLocation LParenLoc, |
| 5864 | SourceLocation EndLoc) { |
| 5865 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5866 | SmallVector<Expr *, 8> PrivateCopies; |
| 5867 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5868 | bool IsImplicitClause = |
| 5869 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 5870 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 5871 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5872 | for (auto &RefExpr : VarList) { |
| 5873 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 5874 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5875 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5876 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5877 | PrivateCopies.push_back(nullptr); |
| 5878 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5879 | continue; |
| 5880 | } |
| 5881 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5882 | SourceLocation ELoc = |
| 5883 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5884 | // OpenMP [2.1, C/C++] |
| 5885 | // A list item is a variable name. |
| 5886 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5887 | // A variable that is part of another variable (as an array or |
| 5888 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5889 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5890 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5891 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5892 | continue; |
| 5893 | } |
| 5894 | Decl *D = DE->getDecl(); |
| 5895 | VarDecl *VD = cast<VarDecl>(D); |
| 5896 | |
| 5897 | QualType Type = VD->getType(); |
| 5898 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5899 | // It will be analyzed later. |
| 5900 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5901 | PrivateCopies.push_back(nullptr); |
| 5902 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5903 | continue; |
| 5904 | } |
| 5905 | |
| 5906 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5907 | // A variable that appears in a private clause must not have an incomplete |
| 5908 | // type or a reference type. |
| 5909 | if (RequireCompleteType(ELoc, Type, |
| 5910 | diag::err_omp_firstprivate_incomplete_type)) { |
| 5911 | continue; |
| 5912 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5913 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5914 | |
| 5915 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 5916 | // 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] | 5917 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5918 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5919 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5920 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5921 | // If an implicit firstprivate variable found it was checked already. |
| 5922 | if (!IsImplicitClause) { |
| 5923 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5924 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5925 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 5926 | // A list item that specifies a given variable may not appear in more |
| 5927 | // than one clause on the same directive, except that a variable may be |
| 5928 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5929 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5930 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5931 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5932 | << getOpenMPClauseName(DVar.CKind) |
| 5933 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5934 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5935 | continue; |
| 5936 | } |
| 5937 | |
| 5938 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5939 | // in a Construct] |
| 5940 | // Variables with the predetermined data-sharing attributes may not be |
| 5941 | // listed in data-sharing attributes clauses, except for the cases |
| 5942 | // listed below. For these exceptions only, listing a predetermined |
| 5943 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5944 | // the variable's predetermined data-sharing attributes. |
| 5945 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5946 | // in a Construct, C/C++, p.2] |
| 5947 | // Variables with const-qualified type having no mutable member may be |
| 5948 | // listed in a firstprivate clause, even if they are static data members. |
| 5949 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 5950 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 5951 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5952 | << getOpenMPClauseName(DVar.CKind) |
| 5953 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5954 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5955 | continue; |
| 5956 | } |
| 5957 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5958 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5959 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 5960 | // A list item that is private within a parallel region must not appear |
| 5961 | // in a firstprivate clause on a worksharing construct if any of the |
| 5962 | // worksharing regions arising from the worksharing construct ever bind |
| 5963 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5964 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5965 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5966 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 5967 | if (DVar.CKind != OMPC_shared && |
| 5968 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5969 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5970 | Diag(ELoc, diag::err_omp_required_access) |
| 5971 | << getOpenMPClauseName(OMPC_firstprivate) |
| 5972 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5973 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5974 | continue; |
| 5975 | } |
| 5976 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5977 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 5978 | // A list item that appears in a reduction clause of a parallel construct |
| 5979 | // must not appear in a firstprivate clause on a worksharing or task |
| 5980 | // construct if any of the worksharing or task regions arising from the |
| 5981 | // worksharing or task construct ever bind to any of the parallel regions |
| 5982 | // arising from the parallel construct. |
| 5983 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 5984 | // A list item that appears in a reduction clause in worksharing |
| 5985 | // construct must not appear in a firstprivate clause in a task construct |
| 5986 | // encountered during execution of any of the worksharing regions arising |
| 5987 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5988 | if (CurrDir == OMPD_task) { |
| 5989 | DVar = |
| 5990 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 5991 | [](OpenMPDirectiveKind K) -> bool { |
| 5992 | return isOpenMPParallelDirective(K) || |
| 5993 | isOpenMPWorksharingDirective(K); |
| 5994 | }, |
| 5995 | false); |
| 5996 | if (DVar.CKind == OMPC_reduction && |
| 5997 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5998 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 5999 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6000 | << getOpenMPDirectiveName(DVar.DKind); |
| 6001 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6002 | continue; |
| 6003 | } |
| 6004 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6005 | } |
| 6006 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6007 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6008 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6009 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6010 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6011 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6012 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6013 | bool IsDecl = |
| 6014 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6015 | Diag(VD->getLocation(), |
| 6016 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6017 | << VD; |
| 6018 | continue; |
| 6019 | } |
| 6020 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6021 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6022 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6023 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6024 | // Generate helper private variable and initialize it with the value of the |
| 6025 | // original variable. The address of the original variable is replaced by |
| 6026 | // the address of the new private variable in the CodeGen. This new variable |
| 6027 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 6028 | // original variable for proper diagnostics and variable capturing. |
| 6029 | Expr *VDInitRefExpr = nullptr; |
| 6030 | // For arrays generate initializer for single element and replace it by the |
| 6031 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6032 | if (Type->isArrayType()) { |
| 6033 | auto VDInit = |
| 6034 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 6035 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6036 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6037 | ElemType = ElemType.getUnqualifiedType(); |
| 6038 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 6039 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6040 | InitializedEntity Entity = |
| 6041 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6042 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 6043 | |
| 6044 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 6045 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 6046 | if (Result.isInvalid()) |
| 6047 | VDPrivate->setInvalidDecl(); |
| 6048 | else |
| 6049 | VDPrivate->setInit(Result.getAs<Expr>()); |
| 6050 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6051 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6052 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6053 | VDInitRefExpr = |
| 6054 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6055 | AddInitializerToDecl(VDPrivate, |
| 6056 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 6057 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6058 | } |
| 6059 | if (VDPrivate->isInvalidDecl()) { |
| 6060 | if (IsImplicitClause) { |
| 6061 | Diag(DE->getExprLoc(), |
| 6062 | diag::note_omp_task_predetermined_firstprivate_here); |
| 6063 | } |
| 6064 | continue; |
| 6065 | } |
| 6066 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6067 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6068 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6069 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 6070 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6071 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 6072 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6073 | } |
| 6074 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6075 | if (Vars.empty()) |
| 6076 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6077 | |
| 6078 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6079 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6080 | } |
| 6081 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6082 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6083 | SourceLocation StartLoc, |
| 6084 | SourceLocation LParenLoc, |
| 6085 | SourceLocation EndLoc) { |
| 6086 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6087 | SmallVector<Expr *, 8> SrcExprs; |
| 6088 | SmallVector<Expr *, 8> DstExprs; |
| 6089 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6090 | for (auto &RefExpr : VarList) { |
| 6091 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 6092 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6093 | // It will be analyzed later. |
| 6094 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6095 | SrcExprs.push_back(nullptr); |
| 6096 | DstExprs.push_back(nullptr); |
| 6097 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6098 | continue; |
| 6099 | } |
| 6100 | |
| 6101 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6102 | // OpenMP [2.1, C/C++] |
| 6103 | // A list item is a variable name. |
| 6104 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 6105 | // A variable that is part of another variable (as an array or structure |
| 6106 | // element) cannot appear in a lastprivate clause. |
| 6107 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 6108 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6109 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6110 | continue; |
| 6111 | } |
| 6112 | Decl *D = DE->getDecl(); |
| 6113 | VarDecl *VD = cast<VarDecl>(D); |
| 6114 | |
| 6115 | QualType Type = VD->getType(); |
| 6116 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6117 | // It will be analyzed later. |
| 6118 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6119 | SrcExprs.push_back(nullptr); |
| 6120 | DstExprs.push_back(nullptr); |
| 6121 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6122 | continue; |
| 6123 | } |
| 6124 | |
| 6125 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6126 | // A variable that appears in a lastprivate clause must not have an |
| 6127 | // incomplete type or a reference type. |
| 6128 | if (RequireCompleteType(ELoc, Type, |
| 6129 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6130 | continue; |
| 6131 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6132 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6133 | |
| 6134 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6135 | // in a Construct] |
| 6136 | // Variables with the predetermined data-sharing attributes may not be |
| 6137 | // listed in data-sharing attributes clauses, except for the cases |
| 6138 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6139 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6140 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6141 | DVar.CKind != OMPC_firstprivate && |
| 6142 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6143 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6144 | << getOpenMPClauseName(DVar.CKind) |
| 6145 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6146 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6147 | continue; |
| 6148 | } |
| 6149 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6150 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6151 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6152 | // A list item that is private within a parallel region, or that appears in |
| 6153 | // the reduction clause of a parallel construct, must not appear in a |
| 6154 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6155 | // worksharing regions ever binds to any of the corresponding parallel |
| 6156 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6157 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6158 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6159 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6160 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6161 | if (DVar.CKind != OMPC_shared) { |
| 6162 | Diag(ELoc, diag::err_omp_required_access) |
| 6163 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6164 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6165 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6166 | continue; |
| 6167 | } |
| 6168 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6169 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6170 | // A variable of class type (or array thereof) that appears in a |
| 6171 | // lastprivate clause requires an accessible, unambiguous default |
| 6172 | // constructor for the class type, unless the list item is also specified |
| 6173 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6174 | // A variable of class type (or array thereof) that appears in a |
| 6175 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6176 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6177 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6178 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6179 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6180 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6181 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6182 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6183 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6184 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6185 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6186 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6187 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6188 | // For arrays generate assignment operation for single element and replace |
| 6189 | // it by the original array element in CodeGen. |
| 6190 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6191 | PseudoDstExpr, PseudoSrcExpr); |
| 6192 | if (AssignmentOp.isInvalid()) |
| 6193 | continue; |
| 6194 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6195 | /*DiscardedValue=*/true); |
| 6196 | if (AssignmentOp.isInvalid()) |
| 6197 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6198 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6199 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6200 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6201 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6202 | SrcExprs.push_back(PseudoSrcExpr); |
| 6203 | DstExprs.push_back(PseudoDstExpr); |
| 6204 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | if (Vars.empty()) |
| 6208 | return nullptr; |
| 6209 | |
| 6210 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6211 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6212 | } |
| 6213 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6214 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 6215 | SourceLocation StartLoc, |
| 6216 | SourceLocation LParenLoc, |
| 6217 | SourceLocation EndLoc) { |
| 6218 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6219 | for (auto &RefExpr : VarList) { |
| 6220 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6221 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6222 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6223 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6224 | continue; |
| 6225 | } |
| 6226 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6227 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6228 | // OpenMP [2.1, C/C++] |
| 6229 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 6230 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 6231 | // A variable that is part of another variable (as an array or structure |
| 6232 | // element) cannot appear in a shared unless it is a static data member |
| 6233 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6234 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6235 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6236 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6237 | continue; |
| 6238 | } |
| 6239 | Decl *D = DE->getDecl(); |
| 6240 | VarDecl *VD = cast<VarDecl>(D); |
| 6241 | |
| 6242 | QualType Type = VD->getType(); |
| 6243 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6244 | // It will be analyzed later. |
| 6245 | Vars.push_back(DE); |
| 6246 | continue; |
| 6247 | } |
| 6248 | |
| 6249 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6250 | // in a Construct] |
| 6251 | // Variables with the predetermined data-sharing attributes may not be |
| 6252 | // listed in data-sharing attributes clauses, except for the cases |
| 6253 | // listed below. For these exceptions only, listing a predetermined |
| 6254 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6255 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6256 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6257 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 6258 | DVar.RefExpr) { |
| 6259 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6260 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6261 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6262 | continue; |
| 6263 | } |
| 6264 | |
| 6265 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 6266 | Vars.push_back(DE); |
| 6267 | } |
| 6268 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6269 | if (Vars.empty()) |
| 6270 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6271 | |
| 6272 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 6273 | } |
| 6274 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6275 | namespace { |
| 6276 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 6277 | DSAStackTy *Stack; |
| 6278 | |
| 6279 | public: |
| 6280 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 6281 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6282 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6283 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 6284 | return false; |
| 6285 | if (DVar.CKind != OMPC_unknown) |
| 6286 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6287 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6288 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6289 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6290 | return true; |
| 6291 | return false; |
| 6292 | } |
| 6293 | return false; |
| 6294 | } |
| 6295 | bool VisitStmt(Stmt *S) { |
| 6296 | for (auto Child : S->children()) { |
| 6297 | if (Child && Visit(Child)) |
| 6298 | return true; |
| 6299 | } |
| 6300 | return false; |
| 6301 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6302 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6303 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6304 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6305 | |
| 6306 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 6307 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 6308 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 6309 | CXXScopeSpec &ReductionIdScopeSpec, |
| 6310 | const DeclarationNameInfo &ReductionId) { |
| 6311 | // TODO: Allow scope specification search when 'declare reduction' is |
| 6312 | // supported. |
| 6313 | assert(ReductionIdScopeSpec.isEmpty() && |
| 6314 | "No support for scoped reduction identifiers yet."); |
| 6315 | |
| 6316 | auto DN = ReductionId.getName(); |
| 6317 | auto OOK = DN.getCXXOverloadedOperator(); |
| 6318 | BinaryOperatorKind BOK = BO_Comma; |
| 6319 | |
| 6320 | // OpenMP [2.14.3.6, reduction clause] |
| 6321 | // C |
| 6322 | // reduction-identifier is either an identifier or one of the following |
| 6323 | // operators: +, -, *, &, |, ^, && and || |
| 6324 | // C++ |
| 6325 | // reduction-identifier is either an id-expression or one of the following |
| 6326 | // operators: +, -, *, &, |, ^, && and || |
| 6327 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 6328 | switch (OOK) { |
| 6329 | case OO_Plus: |
| 6330 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6331 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6332 | break; |
| 6333 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6334 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6335 | break; |
| 6336 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6337 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6338 | break; |
| 6339 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6340 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6341 | break; |
| 6342 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6343 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6344 | break; |
| 6345 | case OO_AmpAmp: |
| 6346 | BOK = BO_LAnd; |
| 6347 | break; |
| 6348 | case OO_PipePipe: |
| 6349 | BOK = BO_LOr; |
| 6350 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6351 | case OO_New: |
| 6352 | case OO_Delete: |
| 6353 | case OO_Array_New: |
| 6354 | case OO_Array_Delete: |
| 6355 | case OO_Slash: |
| 6356 | case OO_Percent: |
| 6357 | case OO_Tilde: |
| 6358 | case OO_Exclaim: |
| 6359 | case OO_Equal: |
| 6360 | case OO_Less: |
| 6361 | case OO_Greater: |
| 6362 | case OO_LessEqual: |
| 6363 | case OO_GreaterEqual: |
| 6364 | case OO_PlusEqual: |
| 6365 | case OO_MinusEqual: |
| 6366 | case OO_StarEqual: |
| 6367 | case OO_SlashEqual: |
| 6368 | case OO_PercentEqual: |
| 6369 | case OO_CaretEqual: |
| 6370 | case OO_AmpEqual: |
| 6371 | case OO_PipeEqual: |
| 6372 | case OO_LessLess: |
| 6373 | case OO_GreaterGreater: |
| 6374 | case OO_LessLessEqual: |
| 6375 | case OO_GreaterGreaterEqual: |
| 6376 | case OO_EqualEqual: |
| 6377 | case OO_ExclaimEqual: |
| 6378 | case OO_PlusPlus: |
| 6379 | case OO_MinusMinus: |
| 6380 | case OO_Comma: |
| 6381 | case OO_ArrowStar: |
| 6382 | case OO_Arrow: |
| 6383 | case OO_Call: |
| 6384 | case OO_Subscript: |
| 6385 | case OO_Conditional: |
| 6386 | case NUM_OVERLOADED_OPERATORS: |
| 6387 | llvm_unreachable("Unexpected reduction identifier"); |
| 6388 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6389 | if (auto II = DN.getAsIdentifierInfo()) { |
| 6390 | if (II->isStr("max")) |
| 6391 | BOK = BO_GT; |
| 6392 | else if (II->isStr("min")) |
| 6393 | BOK = BO_LT; |
| 6394 | } |
| 6395 | break; |
| 6396 | } |
| 6397 | SourceRange ReductionIdRange; |
| 6398 | if (ReductionIdScopeSpec.isValid()) { |
| 6399 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 6400 | } |
| 6401 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 6402 | if (BOK == BO_Comma) { |
| 6403 | // Not allowed reduction identifier is found. |
| 6404 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 6405 | << ReductionIdRange; |
| 6406 | return nullptr; |
| 6407 | } |
| 6408 | |
| 6409 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6410 | SmallVector<Expr *, 8> LHSs; |
| 6411 | SmallVector<Expr *, 8> RHSs; |
| 6412 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6413 | for (auto RefExpr : VarList) { |
| 6414 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 6415 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6416 | // It will be analyzed later. |
| 6417 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6418 | LHSs.push_back(nullptr); |
| 6419 | RHSs.push_back(nullptr); |
| 6420 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6421 | continue; |
| 6422 | } |
| 6423 | |
| 6424 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6425 | RefExpr->isInstantiationDependent() || |
| 6426 | RefExpr->containsUnexpandedParameterPack()) { |
| 6427 | // It will be analyzed later. |
| 6428 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6429 | LHSs.push_back(nullptr); |
| 6430 | RHSs.push_back(nullptr); |
| 6431 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6432 | continue; |
| 6433 | } |
| 6434 | |
| 6435 | auto ELoc = RefExpr->getExprLoc(); |
| 6436 | auto ERange = RefExpr->getSourceRange(); |
| 6437 | // OpenMP [2.1, C/C++] |
| 6438 | // A list item is a variable or array section, subject to the restrictions |
| 6439 | // specified in Section 2.4 on page 42 and in each of the sections |
| 6440 | // describing clauses and directives for which a list appears. |
| 6441 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6442 | // A variable that is part of another variable (as an array or |
| 6443 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6444 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6445 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 6446 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 6447 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
| 6448 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6449 | continue; |
| 6450 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6451 | QualType Type; |
| 6452 | VarDecl *VD = nullptr; |
| 6453 | if (DE) { |
| 6454 | auto D = DE->getDecl(); |
| 6455 | VD = cast<VarDecl>(D); |
| 6456 | Type = VD->getType(); |
| 6457 | } else if (ASE) |
| 6458 | Type = ASE->getType(); |
| 6459 | else if (OASE) { |
| 6460 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 6461 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 6462 | Type = ATy->getElementType(); |
| 6463 | else |
| 6464 | Type = BaseType->getPointeeType(); |
| 6465 | } |
| 6466 | // OpenMP [2.15.3.6, reduction Clause] |
| 6467 | // If a list item is an array section, its lower-bound must be zero. |
| 6468 | llvm::APSInt Result; |
| 6469 | if (OASE && OASE->getLowerBound() && |
| 6470 | OASE->getLowerBound()->EvaluateAsInt(Result, Context) && Result != 0) { |
| 6471 | Diag(OASE->getLowerBound()->getExprLoc(), |
| 6472 | diag::err_omp_expected_array_sect_reduction_lb_not_zero) |
| 6473 | << OASE->getLowerBound()->getSourceRange(); |
| 6474 | continue; |
| 6475 | } |
| 6476 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6477 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6478 | // A variable that appears in a private clause must not have an incomplete |
| 6479 | // type or a reference type. |
| 6480 | if (RequireCompleteType(ELoc, Type, |
| 6481 | diag::err_omp_reduction_incomplete_type)) |
| 6482 | continue; |
| 6483 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6484 | // Arrays may not appear in a reduction clause. |
| 6485 | if (Type.getNonReferenceType()->isArrayType()) { |
| 6486 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6487 | if (VD) { |
| 6488 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6489 | VarDecl::DeclarationOnly; |
| 6490 | Diag(VD->getLocation(), |
| 6491 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6492 | << VD; |
| 6493 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6494 | continue; |
| 6495 | } |
| 6496 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6497 | // A list item that appears in a reduction clause must not be |
| 6498 | // const-qualified. |
| 6499 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6500 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6501 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6502 | if (VD) { |
| 6503 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6504 | VarDecl::DeclarationOnly; |
| 6505 | Diag(VD->getLocation(), |
| 6506 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6507 | << VD; |
| 6508 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6509 | continue; |
| 6510 | } |
| 6511 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 6512 | // If a list-item is a reference type then it must bind to the same object |
| 6513 | // for all threads of the team. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6514 | if (VD) { |
| 6515 | VarDecl *VDDef = VD->getDefinition(); |
| 6516 | if (Type->isReferenceType() && VDDef) { |
| 6517 | DSARefChecker Check(DSAStack); |
| 6518 | if (Check.Visit(VDDef->getInit())) { |
| 6519 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 6520 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 6521 | continue; |
| 6522 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6523 | } |
| 6524 | } |
| 6525 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6526 | // The type of a list item that appears in a reduction clause must be valid |
| 6527 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 6528 | // of the list item must be an allowed arithmetic data type: char, int, |
| 6529 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 6530 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 6531 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 6532 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 6533 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 6534 | !(Type->isScalarType() || |
| 6535 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 6536 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 6537 | << getLangOpts().CPlusPlus; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6538 | if (VD) { |
| 6539 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6540 | VarDecl::DeclarationOnly; |
| 6541 | Diag(VD->getLocation(), |
| 6542 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6543 | << VD; |
| 6544 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6545 | continue; |
| 6546 | } |
| 6547 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 6548 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 6549 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6550 | if (VD) { |
| 6551 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6552 | VarDecl::DeclarationOnly; |
| 6553 | Diag(VD->getLocation(), |
| 6554 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6555 | << VD; |
| 6556 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6557 | continue; |
| 6558 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6559 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6560 | // in a Construct] |
| 6561 | // Variables with the predetermined data-sharing attributes may not be |
| 6562 | // listed in data-sharing attributes clauses, except for the cases |
| 6563 | // listed below. For these exceptions only, listing a predetermined |
| 6564 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6565 | // the variable's predetermined data-sharing attributes. |
| 6566 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 6567 | // Any number of reduction clauses can be specified on the directive, |
| 6568 | // but a list item can appear only once in the reduction clauses for that |
| 6569 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6570 | DSAStackTy::DSAVarData DVar; |
| 6571 | if (VD) { |
| 6572 | DVar = DSAStack->getTopDSA(VD, false); |
| 6573 | if (DVar.CKind == OMPC_reduction) { |
| 6574 | Diag(ELoc, diag::err_omp_once_referenced) |
| 6575 | << getOpenMPClauseName(OMPC_reduction); |
| 6576 | if (DVar.RefExpr) { |
| 6577 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 6578 | } |
| 6579 | } else if (DVar.CKind != OMPC_unknown) { |
| 6580 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6581 | << getOpenMPClauseName(DVar.CKind) |
| 6582 | << getOpenMPClauseName(OMPC_reduction); |
| 6583 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6584 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6585 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 6589 | // A list item that appears in a reduction clause of a worksharing |
| 6590 | // construct must be shared in the parallel regions to which any of the |
| 6591 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6592 | if (VD) { |
| 6593 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6594 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6595 | !isOpenMPParallelDirective(CurrDir)) { |
| 6596 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6597 | if (DVar.CKind != OMPC_shared) { |
| 6598 | Diag(ELoc, diag::err_omp_required_access) |
| 6599 | << getOpenMPClauseName(OMPC_reduction) |
| 6600 | << getOpenMPClauseName(OMPC_shared); |
| 6601 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6602 | continue; |
| 6603 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6604 | } |
| 6605 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6606 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6607 | auto *LHSVD = |
| 6608 | buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 6609 | VD && VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 6610 | auto *RHSVD = |
| 6611 | buildVarDecl(*this, ELoc, Type, VD ? VD->getName() : ".item.", |
| 6612 | VD && VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6613 | // Add initializer for private variable. |
| 6614 | Expr *Init = nullptr; |
| 6615 | switch (BOK) { |
| 6616 | case BO_Add: |
| 6617 | case BO_Xor: |
| 6618 | case BO_Or: |
| 6619 | case BO_LOr: |
| 6620 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 6621 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6622 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6623 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6624 | break; |
| 6625 | case BO_Mul: |
| 6626 | case BO_LAnd: |
| 6627 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6628 | // '*' and '&&' reduction ops - initializer is '1'. |
| 6629 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 6630 | } |
| 6631 | break; |
| 6632 | case BO_And: { |
| 6633 | // '&' reduction op - initializer is '~0'. |
| 6634 | QualType OrigType = Type; |
| 6635 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 6636 | Type = ComplexTy->getElementType(); |
| 6637 | } |
| 6638 | if (Type->isRealFloatingType()) { |
| 6639 | llvm::APFloat InitValue = |
| 6640 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 6641 | /*isIEEE=*/true); |
| 6642 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6643 | Type, ELoc); |
| 6644 | } else if (Type->isScalarType()) { |
| 6645 | auto Size = Context.getTypeSize(Type); |
| 6646 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 6647 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 6648 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6649 | } |
| 6650 | if (Init && OrigType->isAnyComplexType()) { |
| 6651 | // Init = 0xFFFF + 0xFFFFi; |
| 6652 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 6653 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 6654 | } |
| 6655 | Type = OrigType; |
| 6656 | break; |
| 6657 | } |
| 6658 | case BO_LT: |
| 6659 | case BO_GT: { |
| 6660 | // 'min' reduction op - initializer is 'Largest representable number in |
| 6661 | // the reduction list item type'. |
| 6662 | // 'max' reduction op - initializer is 'Least representable number in |
| 6663 | // the reduction list item type'. |
| 6664 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 6665 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 6666 | auto Size = Context.getTypeSize(Type); |
| 6667 | QualType IntTy = |
| 6668 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 6669 | llvm::APInt InitValue = |
| 6670 | (BOK != BO_LT) |
| 6671 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 6672 | : llvm::APInt::getMinValue(Size) |
| 6673 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 6674 | : llvm::APInt::getMaxValue(Size); |
| 6675 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6676 | if (Type->isPointerType()) { |
| 6677 | // Cast to pointer type. |
| 6678 | auto CastExpr = BuildCStyleCastExpr( |
| 6679 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 6680 | SourceLocation(), Init); |
| 6681 | if (CastExpr.isInvalid()) |
| 6682 | continue; |
| 6683 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6684 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6685 | } else if (Type->isRealFloatingType()) { |
| 6686 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 6687 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 6688 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6689 | Type, ELoc); |
| 6690 | } |
| 6691 | break; |
| 6692 | } |
| 6693 | case BO_PtrMemD: |
| 6694 | case BO_PtrMemI: |
| 6695 | case BO_MulAssign: |
| 6696 | case BO_Div: |
| 6697 | case BO_Rem: |
| 6698 | case BO_Sub: |
| 6699 | case BO_Shl: |
| 6700 | case BO_Shr: |
| 6701 | case BO_LE: |
| 6702 | case BO_GE: |
| 6703 | case BO_EQ: |
| 6704 | case BO_NE: |
| 6705 | case BO_AndAssign: |
| 6706 | case BO_XorAssign: |
| 6707 | case BO_OrAssign: |
| 6708 | case BO_Assign: |
| 6709 | case BO_AddAssign: |
| 6710 | case BO_SubAssign: |
| 6711 | case BO_DivAssign: |
| 6712 | case BO_RemAssign: |
| 6713 | case BO_ShlAssign: |
| 6714 | case BO_ShrAssign: |
| 6715 | case BO_Comma: |
| 6716 | llvm_unreachable("Unexpected reduction operation"); |
| 6717 | } |
| 6718 | if (Init) { |
| 6719 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 6720 | /*TypeMayContainAuto=*/false); |
| 6721 | } else { |
| 6722 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
| 6723 | } |
| 6724 | if (!RHSVD->hasInit()) { |
| 6725 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 6726 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6727 | if (VD) { |
| 6728 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6729 | VarDecl::DeclarationOnly; |
| 6730 | Diag(VD->getLocation(), |
| 6731 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6732 | << VD; |
| 6733 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6734 | continue; |
| 6735 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6736 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 6737 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6738 | ExprResult ReductionOp = |
| 6739 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 6740 | LHSDRE, RHSDRE); |
| 6741 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 6742 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6743 | ReductionOp = |
| 6744 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6745 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 6746 | } else { |
| 6747 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 6748 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 6749 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 6750 | ReductionOp = |
| 6751 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6752 | BO_Assign, LHSDRE, ConditionalOp); |
| 6753 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6754 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6755 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6756 | if (ReductionOp.isInvalid()) |
| 6757 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6758 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6759 | if (VD) |
| 6760 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 6761 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6762 | LHSs.push_back(LHSDRE); |
| 6763 | RHSs.push_back(RHSDRE); |
| 6764 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6765 | } |
| 6766 | |
| 6767 | if (Vars.empty()) |
| 6768 | return nullptr; |
| 6769 | |
| 6770 | return OMPReductionClause::Create( |
| 6771 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6772 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, LHSs, |
| 6773 | RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6774 | } |
| 6775 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6776 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 6777 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 6778 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 6779 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6780 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6781 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6782 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6783 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 6784 | LinKind == OMPC_LINEAR_unknown) { |
| 6785 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 6786 | LinKind = OMPC_LINEAR_val; |
| 6787 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6788 | for (auto &RefExpr : VarList) { |
| 6789 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 6790 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6791 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6792 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6793 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6794 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6795 | continue; |
| 6796 | } |
| 6797 | |
| 6798 | // OpenMP [2.14.3.7, linear clause] |
| 6799 | // A list item that appears in a linear clause is subject to the private |
| 6800 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 6801 | // noted. In addition, the value of the new list item on each iteration |
| 6802 | // of the associated loop(s) corresponds to the value of the original |
| 6803 | // list item before entering the construct plus the logical number of |
| 6804 | // the iteration times linear-step. |
| 6805 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6806 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6807 | // OpenMP [2.1, C/C++] |
| 6808 | // A list item is a variable name. |
| 6809 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6810 | // A variable that is part of another variable (as an array or |
| 6811 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6812 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6813 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6814 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6815 | continue; |
| 6816 | } |
| 6817 | |
| 6818 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6819 | |
| 6820 | // OpenMP [2.14.3.7, linear clause] |
| 6821 | // A list-item cannot appear in more than one linear clause. |
| 6822 | // A list-item that appears in a linear clause cannot appear in any |
| 6823 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6824 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6825 | if (DVar.RefExpr) { |
| 6826 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6827 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6828 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6829 | continue; |
| 6830 | } |
| 6831 | |
| 6832 | QualType QType = VD->getType(); |
| 6833 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 6834 | // It will be analyzed later. |
| 6835 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6836 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6837 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6838 | continue; |
| 6839 | } |
| 6840 | |
| 6841 | // A variable must not have an incomplete type or a reference type. |
| 6842 | if (RequireCompleteType(ELoc, QType, |
| 6843 | diag::err_omp_linear_incomplete_type)) { |
| 6844 | continue; |
| 6845 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 6846 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 6847 | !QType->isReferenceType()) { |
| 6848 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 6849 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 6850 | continue; |
| 6851 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6852 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6853 | |
| 6854 | // A list item must not be const-qualified. |
| 6855 | if (QType.isConstant(Context)) { |
| 6856 | Diag(ELoc, diag::err_omp_const_variable) |
| 6857 | << getOpenMPClauseName(OMPC_linear); |
| 6858 | bool IsDecl = |
| 6859 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6860 | Diag(VD->getLocation(), |
| 6861 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6862 | << VD; |
| 6863 | continue; |
| 6864 | } |
| 6865 | |
| 6866 | // A list item must be of integral or pointer type. |
| 6867 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 6868 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6869 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 6870 | !Ty->isPointerType())) { |
| 6871 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 6872 | bool IsDecl = |
| 6873 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6874 | Diag(VD->getLocation(), |
| 6875 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6876 | << VD; |
| 6877 | continue; |
| 6878 | } |
| 6879 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6880 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6881 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 6882 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6883 | auto *PrivateRef = buildDeclRefExpr( |
| 6884 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6885 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6886 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6887 | Expr *InitExpr; |
| 6888 | if (LinKind == OMPC_LINEAR_uval) |
| 6889 | InitExpr = VD->getInit(); |
| 6890 | else |
| 6891 | InitExpr = DE; |
| 6892 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6893 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6894 | auto InitRef = buildDeclRefExpr( |
| 6895 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6896 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 6897 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6898 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6899 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6900 | } |
| 6901 | |
| 6902 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6903 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6904 | |
| 6905 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6906 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6907 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 6908 | !Step->isInstantiationDependent() && |
| 6909 | !Step->containsUnexpandedParameterPack()) { |
| 6910 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6911 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6912 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6913 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6914 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6915 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6916 | // Build var to save the step value. |
| 6917 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6918 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6919 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6920 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6921 | ExprResult CalcStep = |
| 6922 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6923 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6924 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6925 | // Warn about zero linear step (it would be probably better specified as |
| 6926 | // making corresponding variables 'const'). |
| 6927 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6928 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 6929 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6930 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 6931 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6932 | if (!IsConstant && CalcStep.isUsable()) { |
| 6933 | // Calculate the step beforehand instead of doing this on each iteration. |
| 6934 | // (This is not used if the number of iterations may be kfold-ed). |
| 6935 | CalcStepExpr = CalcStep.get(); |
| 6936 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6937 | } |
| 6938 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6939 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 6940 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 6941 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6942 | } |
| 6943 | |
| 6944 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 6945 | Expr *NumIterations, Sema &SemaRef, |
| 6946 | Scope *S) { |
| 6947 | // Walk the vars and build update/final expressions for the CodeGen. |
| 6948 | SmallVector<Expr *, 8> Updates; |
| 6949 | SmallVector<Expr *, 8> Finals; |
| 6950 | Expr *Step = Clause.getStep(); |
| 6951 | Expr *CalcStep = Clause.getCalcStep(); |
| 6952 | // OpenMP [2.14.3.7, linear clause] |
| 6953 | // If linear-step is not specified it is assumed to be 1. |
| 6954 | if (Step == nullptr) |
| 6955 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 6956 | else if (CalcStep) |
| 6957 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 6958 | bool HasErrors = false; |
| 6959 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6960 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6961 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6962 | for (auto &RefExpr : Clause.varlists()) { |
| 6963 | Expr *InitExpr = *CurInit; |
| 6964 | |
| 6965 | // Build privatized reference to the current linear var. |
| 6966 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6967 | Expr *CapturedRef; |
| 6968 | if (LinKind == OMPC_LINEAR_uval) |
| 6969 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 6970 | else |
| 6971 | CapturedRef = |
| 6972 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 6973 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 6974 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6975 | |
| 6976 | // Build update: Var = InitExpr + IV * Step |
| 6977 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6978 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6979 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6980 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 6981 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6982 | |
| 6983 | // Build final: Var = InitExpr + NumIterations * Step |
| 6984 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6985 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6986 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6987 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 6988 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6989 | if (!Update.isUsable() || !Final.isUsable()) { |
| 6990 | Updates.push_back(nullptr); |
| 6991 | Finals.push_back(nullptr); |
| 6992 | HasErrors = true; |
| 6993 | } else { |
| 6994 | Updates.push_back(Update.get()); |
| 6995 | Finals.push_back(Final.get()); |
| 6996 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6997 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6998 | } |
| 6999 | Clause.setUpdates(Updates); |
| 7000 | Clause.setFinals(Finals); |
| 7001 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7002 | } |
| 7003 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7004 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 7005 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 7006 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 7007 | |
| 7008 | SmallVector<Expr *, 8> Vars; |
| 7009 | for (auto &RefExpr : VarList) { |
| 7010 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 7011 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7012 | // It will be analyzed later. |
| 7013 | Vars.push_back(RefExpr); |
| 7014 | continue; |
| 7015 | } |
| 7016 | |
| 7017 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7018 | // OpenMP [2.1, C/C++] |
| 7019 | // A list item is a variable name. |
| 7020 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7021 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7022 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7023 | continue; |
| 7024 | } |
| 7025 | |
| 7026 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7027 | |
| 7028 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7029 | // The type of list items appearing in the aligned clause must be |
| 7030 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7031 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7032 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7033 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7034 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 7035 | !Ty->isPointerType())) { |
| 7036 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 7037 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 7038 | bool IsDecl = |
| 7039 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7040 | Diag(VD->getLocation(), |
| 7041 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7042 | << VD; |
| 7043 | continue; |
| 7044 | } |
| 7045 | |
| 7046 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7047 | // A list-item cannot appear in more than one aligned clause. |
| 7048 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 7049 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 7050 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 7051 | << getOpenMPClauseName(OMPC_aligned); |
| 7052 | continue; |
| 7053 | } |
| 7054 | |
| 7055 | Vars.push_back(DE); |
| 7056 | } |
| 7057 | |
| 7058 | // OpenMP [2.8.1, simd construct, Description] |
| 7059 | // The parameter of the aligned clause, alignment, must be a constant |
| 7060 | // positive integer expression. |
| 7061 | // If no optional parameter is specified, implementation-defined default |
| 7062 | // alignments for SIMD instructions on the target platforms are assumed. |
| 7063 | if (Alignment != nullptr) { |
| 7064 | ExprResult AlignResult = |
| 7065 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 7066 | if (AlignResult.isInvalid()) |
| 7067 | return nullptr; |
| 7068 | Alignment = AlignResult.get(); |
| 7069 | } |
| 7070 | if (Vars.empty()) |
| 7071 | return nullptr; |
| 7072 | |
| 7073 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 7074 | EndLoc, Vars, Alignment); |
| 7075 | } |
| 7076 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7077 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 7078 | SourceLocation StartLoc, |
| 7079 | SourceLocation LParenLoc, |
| 7080 | SourceLocation EndLoc) { |
| 7081 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7082 | SmallVector<Expr *, 8> SrcExprs; |
| 7083 | SmallVector<Expr *, 8> DstExprs; |
| 7084 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7085 | for (auto &RefExpr : VarList) { |
| 7086 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 7087 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7088 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7089 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7090 | SrcExprs.push_back(nullptr); |
| 7091 | DstExprs.push_back(nullptr); |
| 7092 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7093 | continue; |
| 7094 | } |
| 7095 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7096 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7097 | // OpenMP [2.1, C/C++] |
| 7098 | // A list item is a variable name. |
| 7099 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7100 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7101 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7102 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7103 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7104 | continue; |
| 7105 | } |
| 7106 | |
| 7107 | Decl *D = DE->getDecl(); |
| 7108 | VarDecl *VD = cast<VarDecl>(D); |
| 7109 | |
| 7110 | QualType Type = VD->getType(); |
| 7111 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7112 | // It will be analyzed later. |
| 7113 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7114 | SrcExprs.push_back(nullptr); |
| 7115 | DstExprs.push_back(nullptr); |
| 7116 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7117 | continue; |
| 7118 | } |
| 7119 | |
| 7120 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 7121 | // A list item that appears in a copyin clause must be threadprivate. |
| 7122 | if (!DSAStack->isThreadPrivate(VD)) { |
| 7123 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7124 | << getOpenMPClauseName(OMPC_copyin) |
| 7125 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7126 | continue; |
| 7127 | } |
| 7128 | |
| 7129 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7130 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7131 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7132 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7133 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7134 | auto *SrcVD = |
| 7135 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 7136 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7137 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7138 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 7139 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7140 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 7141 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7142 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7143 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7144 | // For arrays generate assignment operation for single element and replace |
| 7145 | // it by the original array element in CodeGen. |
| 7146 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7147 | PseudoDstExpr, PseudoSrcExpr); |
| 7148 | if (AssignmentOp.isInvalid()) |
| 7149 | continue; |
| 7150 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7151 | /*DiscardedValue=*/true); |
| 7152 | if (AssignmentOp.isInvalid()) |
| 7153 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7154 | |
| 7155 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 7156 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7157 | SrcExprs.push_back(PseudoSrcExpr); |
| 7158 | DstExprs.push_back(PseudoDstExpr); |
| 7159 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7160 | } |
| 7161 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7162 | if (Vars.empty()) |
| 7163 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7164 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7165 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7166 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7167 | } |
| 7168 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7169 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7170 | SourceLocation StartLoc, |
| 7171 | SourceLocation LParenLoc, |
| 7172 | SourceLocation EndLoc) { |
| 7173 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7174 | SmallVector<Expr *, 8> SrcExprs; |
| 7175 | SmallVector<Expr *, 8> DstExprs; |
| 7176 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7177 | for (auto &RefExpr : VarList) { |
| 7178 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7179 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7180 | // It will be analyzed later. |
| 7181 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7182 | SrcExprs.push_back(nullptr); |
| 7183 | DstExprs.push_back(nullptr); |
| 7184 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7185 | continue; |
| 7186 | } |
| 7187 | |
| 7188 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7189 | // OpenMP [2.1, C/C++] |
| 7190 | // A list item is a variable name. |
| 7191 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7192 | // A list item that appears in a copyin clause must be threadprivate. |
| 7193 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7194 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7195 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7196 | continue; |
| 7197 | } |
| 7198 | |
| 7199 | Decl *D = DE->getDecl(); |
| 7200 | VarDecl *VD = cast<VarDecl>(D); |
| 7201 | |
| 7202 | QualType Type = VD->getType(); |
| 7203 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7204 | // It will be analyzed later. |
| 7205 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7206 | SrcExprs.push_back(nullptr); |
| 7207 | DstExprs.push_back(nullptr); |
| 7208 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7209 | continue; |
| 7210 | } |
| 7211 | |
| 7212 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 7213 | // A list item that appears in a copyprivate clause may not appear in a |
| 7214 | // private or firstprivate clause on the single construct. |
| 7215 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7216 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7217 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 7218 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7219 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7220 | << getOpenMPClauseName(DVar.CKind) |
| 7221 | << getOpenMPClauseName(OMPC_copyprivate); |
| 7222 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7223 | continue; |
| 7224 | } |
| 7225 | |
| 7226 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 7227 | // All list items that appear in a copyprivate clause must be either |
| 7228 | // threadprivate or private in the enclosing context. |
| 7229 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7230 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7231 | if (DVar.CKind == OMPC_shared) { |
| 7232 | Diag(ELoc, diag::err_omp_required_access) |
| 7233 | << getOpenMPClauseName(OMPC_copyprivate) |
| 7234 | << "threadprivate or private in the enclosing context"; |
| 7235 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7236 | continue; |
| 7237 | } |
| 7238 | } |
| 7239 | } |
| 7240 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7241 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7242 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7243 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7244 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 7245 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7246 | bool IsDecl = |
| 7247 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7248 | Diag(VD->getLocation(), |
| 7249 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7250 | << VD; |
| 7251 | continue; |
| 7252 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7253 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7254 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7255 | // A variable of class type (or array thereof) that appears in a |
| 7256 | // copyin clause requires an accessible, unambiguous copy assignment |
| 7257 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7258 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 7259 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7260 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7261 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 7262 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7263 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7264 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7265 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7266 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 7267 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7268 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7269 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7270 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7271 | PseudoDstExpr, PseudoSrcExpr); |
| 7272 | if (AssignmentOp.isInvalid()) |
| 7273 | continue; |
| 7274 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7275 | /*DiscardedValue=*/true); |
| 7276 | if (AssignmentOp.isInvalid()) |
| 7277 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7278 | |
| 7279 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 7280 | // implicitly private. |
| 7281 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7282 | SrcExprs.push_back(PseudoSrcExpr); |
| 7283 | DstExprs.push_back(PseudoDstExpr); |
| 7284 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7285 | } |
| 7286 | |
| 7287 | if (Vars.empty()) |
| 7288 | return nullptr; |
| 7289 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7290 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 7291 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7292 | } |
| 7293 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7294 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 7295 | SourceLocation StartLoc, |
| 7296 | SourceLocation LParenLoc, |
| 7297 | SourceLocation EndLoc) { |
| 7298 | if (VarList.empty()) |
| 7299 | return nullptr; |
| 7300 | |
| 7301 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 7302 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7303 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7304 | OMPClause * |
| 7305 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 7306 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 7307 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 7308 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7309 | if (DepKind == OMPC_DEPEND_unknown) { |
| 7310 | std::string Values; |
| 7311 | std::string Sep(", "); |
| 7312 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 7313 | Values += "'"; |
| 7314 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 7315 | Values += "'"; |
| 7316 | switch (i) { |
| 7317 | case OMPC_DEPEND_unknown - 2: |
| 7318 | Values += " or "; |
| 7319 | break; |
| 7320 | case OMPC_DEPEND_unknown - 1: |
| 7321 | break; |
| 7322 | default: |
| 7323 | Values += Sep; |
| 7324 | break; |
| 7325 | } |
| 7326 | } |
| 7327 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 7328 | << Values << getOpenMPClauseName(OMPC_depend); |
| 7329 | return nullptr; |
| 7330 | } |
| 7331 | SmallVector<Expr *, 8> Vars; |
| 7332 | for (auto &RefExpr : VarList) { |
| 7333 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7334 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7335 | // It will be analyzed later. |
| 7336 | Vars.push_back(RefExpr); |
| 7337 | continue; |
| 7338 | } |
| 7339 | |
| 7340 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7341 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 7342 | // A variable that is part of another variable (such as a field of a |
| 7343 | // structure) but is not an array element or an array section cannot appear |
| 7344 | // in a depend clause. |
| 7345 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7346 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7347 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7348 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7349 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 7350 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7351 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7352 | !ASE->getBase()->getType()->isArrayType())) { |
| 7353 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7354 | << RefExpr->getSourceRange(); |
| 7355 | continue; |
| 7356 | } |
| 7357 | |
| 7358 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 7359 | } |
| 7360 | |
| 7361 | if (Vars.empty()) |
| 7362 | return nullptr; |
| 7363 | |
| 7364 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 7365 | DepLoc, ColonLoc, Vars); |
| 7366 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7367 | |
| 7368 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 7369 | SourceLocation LParenLoc, |
| 7370 | SourceLocation EndLoc) { |
| 7371 | Expr *ValExpr = Device; |
| 7372 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7373 | !ValExpr->isInstantiationDependent()) { |
| 7374 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7375 | ExprResult Value = PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7376 | if (Value.isInvalid()) |
| 7377 | return nullptr; |
| 7378 | |
| 7379 | // OpenMP [2.9.1, Restrictions] |
| 7380 | // The device expression must evaluate to a non-negative integer value. |
| 7381 | llvm::APSInt Result; |
| 7382 | if (Value.get()->isIntegerConstantExpr(Result, Context) && |
| 7383 | Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7384 | Diag(Loc, diag::err_omp_negative_expression_in_clause) |
| 7385 | << "device" << ValExpr->getSourceRange(); |
| 7386 | return nullptr; |
| 7387 | } |
| 7388 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7389 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7390 | } |