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 { |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +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 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 80 | public: |
| 81 | struct MapInfo { |
| 82 | Expr *RefExpr; |
| 83 | }; |
| 84 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 85 | private: |
| 86 | struct DSAInfo { |
| 87 | OpenMPClauseKind Attributes; |
| 88 | DeclRefExpr *RefExpr; |
| 89 | }; |
| 90 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 91 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 92 | typedef llvm::DenseSet<VarDecl *> LoopControlVariablesSetTy; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 93 | typedef llvm::SmallDenseMap<VarDecl *, MapInfo, 64> MappedDeclsTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 94 | |
| 95 | struct SharingMapTy { |
| 96 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 97 | AlignedMapTy AlignedMap; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 98 | MappedDeclsTy MappedDecls; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 99 | LoopControlVariablesSetTy LCVSet; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 100 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 101 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 102 | OpenMPDirectiveKind Directive; |
| 103 | DeclarationNameInfo DirectiveName; |
| 104 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 105 | SourceLocation ConstructLoc; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 106 | /// \brief first argument (Expr *) contains optional argument of the |
| 107 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 108 | /// clause, false otherwise. |
| 109 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 110 | bool NowaitRegion; |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 111 | bool CancelRegion; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 112 | unsigned CollapseNumber; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 113 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 114 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 115 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 116 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 117 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 118 | ConstructLoc(Loc), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 119 | CancelRegion(false), CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 120 | SharingMapTy() |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 121 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 122 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 123 | ConstructLoc(), OrderedRegion(), NowaitRegion(false), |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 124 | CancelRegion(false), CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 128 | |
| 129 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 130 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 131 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 132 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 133 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 134 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 135 | bool ForceCapturing; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 136 | |
| 137 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 138 | |
| 139 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 140 | |
| 141 | /// \brief Checks if the variable is a local for OpenMP region. |
| 142 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 143 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 144 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 145 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 146 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 147 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 148 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 149 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 150 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 151 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 152 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 153 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 154 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 155 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 156 | Scope *CurScope, SourceLocation Loc) { |
| 157 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 158 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | void pop() { |
| 162 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 163 | Stack.pop_back(); |
| 164 | } |
| 165 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 166 | /// \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] | 167 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 168 | /// for diagnostics. |
| 169 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 170 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 171 | /// \brief Register specified variable as loop control variable. |
| 172 | void addLoopControlVariable(VarDecl *D); |
| 173 | /// \brief Check if the specified variable is a loop control variable for |
| 174 | /// current region. |
| 175 | bool isLoopControlVariable(VarDecl *D); |
| 176 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 177 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 178 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 179 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 180 | /// \brief Returns data sharing attributes from top of the stack for the |
| 181 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 182 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 183 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 184 | DSAVarData getImplicitDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 185 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 186 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 187 | /// predicate. |
| 188 | template <class ClausesPredicate, class DirectivesPredicate> |
| 189 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 190 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 191 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 192 | /// match specified \a CPred predicate in any innermost directive which |
| 193 | /// matches \a DPred predicate. |
| 194 | template <class ClausesPredicate, class DirectivesPredicate> |
| 195 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 196 | DirectivesPredicate DPred, |
| 197 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 198 | /// \brief Checks if the specified variables has explicit data-sharing |
| 199 | /// attributes which match specified \a CPred predicate at the specified |
| 200 | /// OpenMP region. |
| 201 | bool hasExplicitDSA(VarDecl *D, |
| 202 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 203 | unsigned Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 204 | |
| 205 | /// \brief Returns true if the directive at level \Level matches in the |
| 206 | /// specified \a DPred predicate. |
| 207 | bool hasExplicitDirective( |
| 208 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 209 | unsigned Level); |
| 210 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 211 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 212 | template <class NamedDirectivesPredicate> |
| 213 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 214 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 215 | /// \brief Returns currently analyzed directive. |
| 216 | OpenMPDirectiveKind getCurrentDirective() const { |
| 217 | return Stack.back().Directive; |
| 218 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 219 | /// \brief Returns parent directive. |
| 220 | OpenMPDirectiveKind getParentDirective() const { |
| 221 | if (Stack.size() > 2) |
| 222 | return Stack[Stack.size() - 2].Directive; |
| 223 | return OMPD_unknown; |
| 224 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 225 | |
| 226 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 227 | void setDefaultDSANone(SourceLocation Loc) { |
| 228 | Stack.back().DefaultAttr = DSA_none; |
| 229 | Stack.back().DefaultAttrLoc = Loc; |
| 230 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 231 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 232 | void setDefaultDSAShared(SourceLocation Loc) { |
| 233 | Stack.back().DefaultAttr = DSA_shared; |
| 234 | Stack.back().DefaultAttrLoc = Loc; |
| 235 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 236 | |
| 237 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 238 | return Stack.back().DefaultAttr; |
| 239 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 240 | SourceLocation getDefaultDSALocation() const { |
| 241 | return Stack.back().DefaultAttrLoc; |
| 242 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 243 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 244 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 245 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 246 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 247 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 250 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 251 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 252 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 253 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 254 | } |
| 255 | /// \brief Returns true, if parent region is ordered (has associated |
| 256 | /// 'ordered' clause), false - otherwise. |
| 257 | bool isParentOrderedRegion() const { |
| 258 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 259 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 260 | return false; |
| 261 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 262 | /// \brief Returns optional parameter for the ordered region. |
| 263 | Expr *getParentOrderedRegionParam() const { |
| 264 | if (Stack.size() > 2) |
| 265 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 266 | return nullptr; |
| 267 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 268 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 269 | void setNowaitRegion(bool IsNowait = true) { |
| 270 | Stack.back().NowaitRegion = IsNowait; |
| 271 | } |
| 272 | /// \brief Returns true, if parent region is nowait (has associated |
| 273 | /// 'nowait' clause), false - otherwise. |
| 274 | bool isParentNowaitRegion() const { |
| 275 | if (Stack.size() > 2) |
| 276 | return Stack[Stack.size() - 2].NowaitRegion; |
| 277 | return false; |
| 278 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 279 | /// \brief Marks parent region as cancel region. |
| 280 | void setParentCancelRegion(bool Cancel = true) { |
| 281 | if (Stack.size() > 2) |
| 282 | Stack[Stack.size() - 2].CancelRegion = |
| 283 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 284 | } |
| 285 | /// \brief Return true if current region has inner cancel construct. |
| 286 | bool isCancelRegion() const { |
| 287 | return Stack.back().CancelRegion; |
| 288 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 289 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 290 | /// \brief Set collapse value for the region. |
| 291 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 292 | /// \brief Return collapse value for region. |
| 293 | unsigned getCollapseNumber() const { |
| 294 | return Stack.back().CollapseNumber; |
| 295 | } |
| 296 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 297 | /// \brief Marks current target region as one with closely nested teams |
| 298 | /// region. |
| 299 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 300 | if (Stack.size() > 2) |
| 301 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 302 | } |
| 303 | /// \brief Returns true, if current region has closely nested teams region. |
| 304 | bool hasInnerTeamsRegion() const { |
| 305 | return getInnerTeamsRegionLoc().isValid(); |
| 306 | } |
| 307 | /// \brief Returns location of the nested teams region (if any). |
| 308 | SourceLocation getInnerTeamsRegionLoc() const { |
| 309 | if (Stack.size() > 1) |
| 310 | return Stack.back().InnerTeamsRegionLoc; |
| 311 | return SourceLocation(); |
| 312 | } |
| 313 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 314 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 315 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 316 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 317 | |
| 318 | MapInfo getMapInfoForVar(VarDecl *VD) { |
| 319 | MapInfo VarMI = {0}; |
| 320 | for (auto Cnt = Stack.size() - 1; Cnt > 0; --Cnt) { |
| 321 | if (Stack[Cnt].MappedDecls.count(VD)) { |
| 322 | VarMI = Stack[Cnt].MappedDecls[VD]; |
| 323 | break; |
| 324 | } |
| 325 | } |
| 326 | return VarMI; |
| 327 | } |
| 328 | |
| 329 | void addMapInfoForVar(VarDecl *VD, MapInfo MI) { |
| 330 | if (Stack.size() > 1) { |
| 331 | Stack.back().MappedDecls[VD] = MI; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | MapInfo IsMappedInCurrentRegion(VarDecl *VD) { |
| 336 | assert(Stack.size() > 1 && "Target level is 0"); |
| 337 | MapInfo VarMI = {0}; |
| 338 | if (Stack.size() > 1 && Stack.back().MappedDecls.count(VD)) { |
| 339 | VarMI = Stack.back().MappedDecls[VD]; |
| 340 | } |
| 341 | return VarMI; |
| 342 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 343 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 344 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 345 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 346 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
| 347 | DKind == OMPD_taskloop; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 348 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 349 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 350 | |
| 351 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 352 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 353 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 354 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 355 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 356 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 357 | // in a region but not in construct] |
| 358 | // File-scope or namespace-scope variables referenced in called routines |
| 359 | // in the region are shared unless they appear in a threadprivate |
| 360 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 361 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 362 | DVar.CKind = OMPC_shared; |
| 363 | |
| 364 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 365 | // in a region but not in construct] |
| 366 | // Variables with static storage duration that are declared in called |
| 367 | // routines in the region are shared. |
| 368 | if (D->hasGlobalStorage()) |
| 369 | DVar.CKind = OMPC_shared; |
| 370 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 371 | return DVar; |
| 372 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 373 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 374 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 375 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 376 | // in a Construct, C/C++, predetermined, p.1] |
| 377 | // Variables with automatic storage duration that are declared in a scope |
| 378 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 379 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 380 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 381 | DVar.CKind = OMPC_private; |
| 382 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 385 | // Explicitly specified attributes and local variables with predetermined |
| 386 | // attributes. |
| 387 | if (Iter->SharingMap.count(D)) { |
| 388 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 389 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 390 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 391 | return DVar; |
| 392 | } |
| 393 | |
| 394 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 395 | // in a Construct, C/C++, implicitly determined, p.1] |
| 396 | // In a parallel or task construct, the data-sharing attributes of these |
| 397 | // variables are determined by the default clause, if present. |
| 398 | switch (Iter->DefaultAttr) { |
| 399 | case DSA_shared: |
| 400 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 401 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 402 | return DVar; |
| 403 | case DSA_none: |
| 404 | return DVar; |
| 405 | case DSA_unspecified: |
| 406 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 407 | // in a Construct, implicitly determined, p.2] |
| 408 | // In a parallel construct, if no default clause is present, these |
| 409 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 410 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 411 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 412 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 413 | DVar.CKind = OMPC_shared; |
| 414 | return DVar; |
| 415 | } |
| 416 | |
| 417 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 418 | // in a Construct, implicitly determined, p.4] |
| 419 | // In a task construct, if no default clause is present, a variable that in |
| 420 | // the enclosing context is determined to be shared by all implicit tasks |
| 421 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 422 | if (DVar.DKind == OMPD_task) { |
| 423 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 424 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 425 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 426 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 427 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 428 | // in a Construct, implicitly determined, p.6] |
| 429 | // In a task construct, if no default clause is present, a variable |
| 430 | // whose data-sharing attribute is not determined by the rules above is |
| 431 | // firstprivate. |
| 432 | DVarTemp = getDSA(I, D); |
| 433 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 434 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 435 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 436 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 437 | return DVar; |
| 438 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 439 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 440 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 441 | } |
| 442 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 443 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 444 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | return DVar; |
| 446 | } |
| 447 | } |
| 448 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 449 | // in a Construct, implicitly determined, p.3] |
| 450 | // For constructs other than task, if no default clause is present, these |
| 451 | // variables inherit their data-sharing attributes from the enclosing |
| 452 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 453 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 456 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 457 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 458 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 459 | auto It = Stack.back().AlignedMap.find(D); |
| 460 | if (It == Stack.back().AlignedMap.end()) { |
| 461 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 462 | Stack.back().AlignedMap[D] = NewDE; |
| 463 | return nullptr; |
| 464 | } else { |
| 465 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 466 | return It->second; |
| 467 | } |
| 468 | return nullptr; |
| 469 | } |
| 470 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 471 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 472 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 473 | D = D->getCanonicalDecl(); |
| 474 | Stack.back().LCVSet.insert(D); |
| 475 | } |
| 476 | |
| 477 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 478 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 479 | D = D->getCanonicalDecl(); |
| 480 | return Stack.back().LCVSet.count(D) > 0; |
| 481 | } |
| 482 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 483 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 484 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 485 | if (A == OMPC_threadprivate) { |
| 486 | Stack[0].SharingMap[D].Attributes = A; |
| 487 | Stack[0].SharingMap[D].RefExpr = E; |
| 488 | } else { |
| 489 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 490 | Stack.back().SharingMap[D].Attributes = A; |
| 491 | Stack.back().SharingMap[D].RefExpr = E; |
| 492 | } |
| 493 | } |
| 494 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 495 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 496 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 497 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 498 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 499 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 500 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 501 | ++I; |
| 502 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 503 | if (I == E) |
| 504 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 505 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 506 | Scope *CurScope = getCurScope(); |
| 507 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 508 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 509 | } |
| 510 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 511 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 512 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 513 | } |
| 514 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 515 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 516 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 517 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 518 | DeclContext *DC = SemaRef.CurContext; |
| 519 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 520 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 521 | VarDecl *Decl = |
| 522 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 523 | if (Attrs) { |
| 524 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 525 | I != E; ++I) |
| 526 | Decl->addAttr(*I); |
| 527 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 528 | Decl->setImplicit(); |
| 529 | return Decl; |
| 530 | } |
| 531 | |
| 532 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 533 | SourceLocation Loc, |
| 534 | bool RefersToCapture = false) { |
| 535 | D->setReferenced(); |
| 536 | D->markUsed(S.Context); |
| 537 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 538 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 539 | VK_LValue); |
| 540 | } |
| 541 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 542 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 543 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 544 | DSAVarData DVar; |
| 545 | |
| 546 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 547 | // in a Construct, C/C++, predetermined, p.1] |
| 548 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 549 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 550 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 551 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 552 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 553 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 554 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 555 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 556 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 557 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 558 | } |
| 559 | if (Stack[0].SharingMap.count(D)) { |
| 560 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 561 | DVar.CKind = OMPC_threadprivate; |
| 562 | return DVar; |
| 563 | } |
| 564 | |
| 565 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 566 | // in a Construct, C/C++, predetermined, p.1] |
| 567 | // Variables with automatic storage duration that are declared in a scope |
| 568 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 569 | OpenMPDirectiveKind Kind = |
| 570 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 571 | auto StartI = std::next(Stack.rbegin()); |
| 572 | auto EndI = std::prev(Stack.rend()); |
| 573 | if (FromParent && StartI != EndI) { |
| 574 | StartI = std::next(StartI); |
| 575 | } |
| 576 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 577 | if (isOpenMPLocal(D, StartI) && |
| 578 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 579 | D->getStorageClass() == SC_None)) || |
| 580 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 581 | DVar.CKind = OMPC_private; |
| 582 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 583 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 584 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 585 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 586 | // in a Construct, C/C++, predetermined, p.4] |
| 587 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 588 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 589 | // in a Construct, C/C++, predetermined, p.7] |
| 590 | // Variables with static storage duration that are declared in a scope |
| 591 | // inside the construct are shared. |
Kelvin Li | 4eea8c6 | 2015-09-15 18:56:58 +0000 | [diff] [blame] | 592 | if (D->isStaticDataMember()) { |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 593 | DSAVarData DVarTemp = |
| 594 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 595 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 596 | return DVar; |
| 597 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 598 | DVar.CKind = OMPC_shared; |
| 599 | return DVar; |
| 600 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 604 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 605 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 606 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 607 | // in a Construct, C/C++, predetermined, p.6] |
| 608 | // Variables with const qualified type having no mutable member are |
| 609 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 610 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 611 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 612 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 613 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 614 | // Variables with const-qualified type having no mutable member may be |
| 615 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 616 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 617 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 618 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 619 | return DVar; |
| 620 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 621 | DVar.CKind = OMPC_shared; |
| 622 | return DVar; |
| 623 | } |
| 624 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 625 | // Explicitly specified attributes and local variables with predetermined |
| 626 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 627 | auto I = std::prev(StartI); |
| 628 | if (I->SharingMap.count(D)) { |
| 629 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 630 | DVar.CKind = I->SharingMap[D].Attributes; |
| 631 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | return DVar; |
| 635 | } |
| 636 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 637 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 638 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 639 | auto StartI = Stack.rbegin(); |
| 640 | auto EndI = std::prev(Stack.rend()); |
| 641 | if (FromParent && StartI != EndI) { |
| 642 | StartI = std::next(StartI); |
| 643 | } |
| 644 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 647 | template <class ClausesPredicate, class DirectivesPredicate> |
| 648 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 649 | DirectivesPredicate DPred, |
| 650 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 651 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 652 | auto StartI = std::next(Stack.rbegin()); |
| 653 | auto EndI = std::prev(Stack.rend()); |
| 654 | if (FromParent && StartI != EndI) { |
| 655 | StartI = std::next(StartI); |
| 656 | } |
| 657 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 658 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 659 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 660 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 661 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 662 | return DVar; |
| 663 | } |
| 664 | return DSAVarData(); |
| 665 | } |
| 666 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 667 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 668 | DSAStackTy::DSAVarData |
| 669 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 670 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 671 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 672 | auto StartI = std::next(Stack.rbegin()); |
| 673 | auto EndI = std::prev(Stack.rend()); |
| 674 | if (FromParent && StartI != EndI) { |
| 675 | StartI = std::next(StartI); |
| 676 | } |
| 677 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 678 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 679 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 680 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 681 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 682 | return DVar; |
| 683 | return DSAVarData(); |
| 684 | } |
| 685 | return DSAVarData(); |
| 686 | } |
| 687 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 688 | bool DSAStackTy::hasExplicitDSA( |
| 689 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 690 | unsigned Level) { |
| 691 | if (CPred(ClauseKindMode)) |
| 692 | return true; |
| 693 | if (isClauseParsingMode()) |
| 694 | ++Level; |
| 695 | D = D->getCanonicalDecl(); |
| 696 | auto StartI = Stack.rbegin(); |
| 697 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 698 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 699 | return false; |
| 700 | std::advance(StartI, Level); |
| 701 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 702 | CPred(StartI->SharingMap[D].Attributes); |
| 703 | } |
| 704 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 705 | bool DSAStackTy::hasExplicitDirective( |
| 706 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 707 | unsigned Level) { |
| 708 | if (isClauseParsingMode()) |
| 709 | ++Level; |
| 710 | auto StartI = Stack.rbegin(); |
| 711 | auto EndI = std::prev(Stack.rend()); |
| 712 | if (std::distance(StartI, EndI) <= (int)Level) |
| 713 | return false; |
| 714 | std::advance(StartI, Level); |
| 715 | return DPred(StartI->Directive); |
| 716 | } |
| 717 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 718 | template <class NamedDirectivesPredicate> |
| 719 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 720 | auto StartI = std::next(Stack.rbegin()); |
| 721 | auto EndI = std::prev(Stack.rend()); |
| 722 | if (FromParent && StartI != EndI) { |
| 723 | StartI = std::next(StartI); |
| 724 | } |
| 725 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 726 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 727 | return true; |
| 728 | } |
| 729 | return false; |
| 730 | } |
| 731 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 732 | void Sema::InitDataSharingAttributesStack() { |
| 733 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 734 | } |
| 735 | |
| 736 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 737 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 738 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 739 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 740 | VD = VD->getCanonicalDecl(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 741 | |
| 742 | // If we are attempting to capture a global variable in a directive with |
| 743 | // 'target' we return true so that this global is also mapped to the device. |
| 744 | // |
| 745 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 746 | // then it should not be captured. Therefore, an extra check has to be |
| 747 | // inserted here once support for 'declare target' is added. |
| 748 | // |
| 749 | if (!VD->hasLocalStorage()) { |
| 750 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 751 | !DSAStack->isClauseParsingMode()) { |
| 752 | return true; |
| 753 | } |
| 754 | if (DSAStack->getCurScope() && |
| 755 | DSAStack->hasDirective( |
| 756 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 757 | SourceLocation Loc) -> bool { |
| 758 | return isOpenMPTargetDirective(K); |
| 759 | }, |
| 760 | false)) { |
| 761 | return true; |
| 762 | } |
| 763 | } |
| 764 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 765 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 766 | (!DSAStack->isClauseParsingMode() || |
| 767 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 768 | if (DSAStack->isLoopControlVariable(VD) || |
| 769 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 770 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 771 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 772 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 773 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 774 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 775 | return true; |
| 776 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 777 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 778 | return DVarPrivate.CKind != OMPC_unknown; |
| 779 | } |
| 780 | return false; |
| 781 | } |
| 782 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 783 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 784 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 785 | return DSAStack->hasExplicitDSA( |
| 786 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 787 | } |
| 788 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 789 | bool Sema::isOpenMPTargetCapturedVar(VarDecl *VD, unsigned Level) { |
| 790 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 791 | // Return true if the current level is no longer enclosed in a target region. |
| 792 | |
| 793 | return !VD->hasLocalStorage() && |
| 794 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 795 | } |
| 796 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 797 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 798 | |
| 799 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 800 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 801 | Scope *CurScope, SourceLocation Loc) { |
| 802 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 803 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 804 | } |
| 805 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 806 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 807 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 808 | } |
| 809 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 810 | void Sema::EndOpenMPClause() { |
| 811 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 814 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 815 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 816 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 817 | // clause requires an accessible, unambiguous default constructor for the |
| 818 | // class type, unless the list item is also specified in a firstprivate |
| 819 | // clause. |
| 820 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 821 | for (auto *C : D->clauses()) { |
| 822 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 823 | SmallVector<Expr *, 8> PrivateCopies; |
| 824 | for (auto *DE : Clause->varlists()) { |
| 825 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 826 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 827 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 828 | } |
| 829 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 830 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 831 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 832 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 833 | // Generate helper private variable and initialize it with the |
| 834 | // default value. The address of the original variable is replaced |
| 835 | // by the address of the new private variable in CodeGen. This new |
| 836 | // variable is not added to IdResolver, so the code in the OpenMP |
| 837 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 838 | auto *VDPrivate = buildVarDecl( |
| 839 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 840 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 841 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 842 | if (VDPrivate->isInvalidDecl()) |
| 843 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 844 | PrivateCopies.push_back(buildDeclRefExpr( |
| 845 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 846 | } else { |
| 847 | // The variable is also a firstprivate, so initialization sequence |
| 848 | // for private copy is generated already. |
| 849 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 850 | } |
| 851 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 852 | // Set initializers to private copies if no errors were found. |
| 853 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 854 | Clause->setPrivateCopies(PrivateCopies); |
| 855 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 856 | } |
| 857 | } |
| 858 | } |
| 859 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 860 | DSAStack->pop(); |
| 861 | DiscardCleanupsInEvaluationContext(); |
| 862 | PopExpressionEvaluationContext(); |
| 863 | } |
| 864 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 865 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 866 | Expr *NumIterations, Sema &SemaRef, |
| 867 | Scope *S); |
| 868 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 869 | namespace { |
| 870 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 871 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 872 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 873 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 874 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 875 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 876 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 877 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 878 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 879 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 880 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 881 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 882 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 883 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 884 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 885 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 886 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 887 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 888 | |
| 889 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 890 | CXXScopeSpec &ScopeSpec, |
| 891 | const DeclarationNameInfo &Id) { |
| 892 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 893 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 894 | |
| 895 | if (Lookup.isAmbiguous()) |
| 896 | return ExprError(); |
| 897 | |
| 898 | VarDecl *VD; |
| 899 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 900 | if (TypoCorrection Corrected = CorrectTypo( |
| 901 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 902 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 903 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 904 | PDiag(Lookup.empty() |
| 905 | ? diag::err_undeclared_var_use_suggest |
| 906 | : diag::err_omp_expected_var_arg_suggest) |
| 907 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 908 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 909 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 910 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 911 | : diag::err_omp_expected_var_arg) |
| 912 | << Id.getName(); |
| 913 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 914 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 915 | } else { |
| 916 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 917 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 918 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 919 | return ExprError(); |
| 920 | } |
| 921 | } |
| 922 | Lookup.suppressDiagnostics(); |
| 923 | |
| 924 | // OpenMP [2.9.2, Syntax, C/C++] |
| 925 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 926 | if (!VD->hasGlobalStorage()) { |
| 927 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 928 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 929 | bool IsDecl = |
| 930 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 931 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 932 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 933 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 934 | return ExprError(); |
| 935 | } |
| 936 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 937 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 938 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 939 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 940 | // A threadprivate directive for file-scope variables must appear outside |
| 941 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 942 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 943 | !getCurLexicalContext()->isTranslationUnit()) { |
| 944 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 945 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 946 | bool IsDecl = |
| 947 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 948 | Diag(VD->getLocation(), |
| 949 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 950 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 951 | return ExprError(); |
| 952 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 953 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 954 | // A threadprivate directive for static class member variables must appear |
| 955 | // in the class definition, in the same scope in which the member |
| 956 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 957 | if (CanonicalVD->isStaticDataMember() && |
| 958 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 959 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 960 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 961 | bool IsDecl = |
| 962 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 963 | Diag(VD->getLocation(), |
| 964 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 965 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 966 | return ExprError(); |
| 967 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 968 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 969 | // A threadprivate directive for namespace-scope variables must appear |
| 970 | // outside any definition or declaration other than the namespace |
| 971 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 972 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 973 | (!getCurLexicalContext()->isFileContext() || |
| 974 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 975 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 976 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 977 | bool IsDecl = |
| 978 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 979 | Diag(VD->getLocation(), |
| 980 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 981 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 982 | return ExprError(); |
| 983 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 984 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 985 | // A threadprivate directive for static block-scope variables must appear |
| 986 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 987 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 988 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 989 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 990 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 991 | bool IsDecl = |
| 992 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 993 | Diag(VD->getLocation(), |
| 994 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 995 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 996 | return ExprError(); |
| 997 | } |
| 998 | |
| 999 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1000 | // A threadprivate directive must lexically precede all references to any |
| 1001 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1002 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1003 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1004 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1005 | return ExprError(); |
| 1006 | } |
| 1007 | |
| 1008 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1009 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1010 | return DE; |
| 1011 | } |
| 1012 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1013 | Sema::DeclGroupPtrTy |
| 1014 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1015 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1016 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1017 | CurContext->addDecl(D); |
| 1018 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1019 | } |
| 1020 | return DeclGroupPtrTy(); |
| 1021 | } |
| 1022 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1023 | namespace { |
| 1024 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1025 | Sema &SemaRef; |
| 1026 | |
| 1027 | public: |
| 1028 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1029 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1030 | if (VD->hasLocalStorage()) { |
| 1031 | SemaRef.Diag(E->getLocStart(), |
| 1032 | diag::err_omp_local_var_in_threadprivate_init) |
| 1033 | << E->getSourceRange(); |
| 1034 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1035 | << VD << VD->getSourceRange(); |
| 1036 | return true; |
| 1037 | } |
| 1038 | } |
| 1039 | return false; |
| 1040 | } |
| 1041 | bool VisitStmt(const Stmt *S) { |
| 1042 | for (auto Child : S->children()) { |
| 1043 | if (Child && Visit(Child)) |
| 1044 | return true; |
| 1045 | } |
| 1046 | return false; |
| 1047 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1048 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1049 | }; |
| 1050 | } // namespace |
| 1051 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1052 | OMPThreadPrivateDecl * |
| 1053 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1054 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1055 | for (auto &RefExpr : VarList) { |
| 1056 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1057 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1058 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1059 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1060 | QualType QType = VD->getType(); |
| 1061 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1062 | // It will be analyzed later. |
| 1063 | Vars.push_back(DE); |
| 1064 | continue; |
| 1065 | } |
| 1066 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1067 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1068 | // A threadprivate variable must not have an incomplete type. |
| 1069 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1070 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1071 | continue; |
| 1072 | } |
| 1073 | |
| 1074 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1075 | // A threadprivate variable must not have a reference type. |
| 1076 | if (VD->getType()->isReferenceType()) { |
| 1077 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1078 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1079 | bool IsDecl = |
| 1080 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1081 | Diag(VD->getLocation(), |
| 1082 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1083 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1084 | continue; |
| 1085 | } |
| 1086 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1087 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1088 | // the corresponding diagnostic. |
| 1089 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1090 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1091 | getLangOpts().OpenMPUseTLS && |
| 1092 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1093 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1094 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1095 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1096 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1097 | bool IsDecl = |
| 1098 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1099 | Diag(VD->getLocation(), |
| 1100 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1101 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1102 | continue; |
| 1103 | } |
| 1104 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1105 | // Check if initial value of threadprivate variable reference variable with |
| 1106 | // local storage (it is not supported by runtime). |
| 1107 | if (auto Init = VD->getAnyInitializer()) { |
| 1108 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1109 | if (Checker.Visit(Init)) |
| 1110 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1113 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1114 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1115 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1116 | Context, SourceRange(Loc, Loc))); |
| 1117 | if (auto *ML = Context.getASTMutationListener()) |
| 1118 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1119 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1120 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1121 | if (!Vars.empty()) { |
| 1122 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1123 | Vars); |
| 1124 | D->setAccess(AS_public); |
| 1125 | } |
| 1126 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1127 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1128 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1129 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1130 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1131 | bool IsLoopIterVar = false) { |
| 1132 | if (DVar.RefExpr) { |
| 1133 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1134 | << getOpenMPClauseName(DVar.CKind); |
| 1135 | return; |
| 1136 | } |
| 1137 | enum { |
| 1138 | PDSA_StaticMemberShared, |
| 1139 | PDSA_StaticLocalVarShared, |
| 1140 | PDSA_LoopIterVarPrivate, |
| 1141 | PDSA_LoopIterVarLinear, |
| 1142 | PDSA_LoopIterVarLastprivate, |
| 1143 | PDSA_ConstVarShared, |
| 1144 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1145 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1146 | PDSA_LocalVarPrivate, |
| 1147 | PDSA_Implicit |
| 1148 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1149 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1150 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1151 | if (IsLoopIterVar) { |
| 1152 | if (DVar.CKind == OMPC_private) |
| 1153 | Reason = PDSA_LoopIterVarPrivate; |
| 1154 | else if (DVar.CKind == OMPC_lastprivate) |
| 1155 | Reason = PDSA_LoopIterVarLastprivate; |
| 1156 | else |
| 1157 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1158 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1159 | Reason = PDSA_TaskVarFirstprivate; |
| 1160 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1161 | } else if (VD->isStaticLocal()) |
| 1162 | Reason = PDSA_StaticLocalVarShared; |
| 1163 | else if (VD->isStaticDataMember()) |
| 1164 | Reason = PDSA_StaticMemberShared; |
| 1165 | else if (VD->isFileVarDecl()) |
| 1166 | Reason = PDSA_GlobalVarShared; |
| 1167 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1168 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1169 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1170 | ReportHint = true; |
| 1171 | Reason = PDSA_LocalVarPrivate; |
| 1172 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1173 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1174 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1175 | << Reason << ReportHint |
| 1176 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1177 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1178 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1179 | << getOpenMPClauseName(DVar.CKind); |
| 1180 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1183 | namespace { |
| 1184 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1185 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1186 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1187 | bool ErrorFound; |
| 1188 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1189 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1190 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1191 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1192 | public: |
| 1193 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1194 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1195 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1196 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1197 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1198 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1199 | auto DVar = Stack->getTopDSA(VD, false); |
| 1200 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1201 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1202 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1203 | auto ELoc = E->getExprLoc(); |
| 1204 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1205 | // The default(none) clause requires that each variable that is referenced |
| 1206 | // in the construct, and does not have a predetermined data-sharing |
| 1207 | // attribute, must have its data-sharing attribute explicitly determined |
| 1208 | // by being listed in a data-sharing attribute clause. |
| 1209 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1210 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1211 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1212 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1213 | return; |
| 1214 | } |
| 1215 | |
| 1216 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1217 | // A list item that appears in a reduction clause of the innermost |
| 1218 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1219 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1220 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1221 | [](OpenMPDirectiveKind K) -> bool { |
| 1222 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1223 | isOpenMPWorksharingDirective(K) || |
| 1224 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1225 | }, |
| 1226 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1227 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1228 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1229 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1230 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1231 | return; |
| 1232 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1233 | |
| 1234 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1235 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1236 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1237 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1241 | for (auto *C : S->clauses()) { |
| 1242 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1243 | // for task directives. |
| 1244 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1245 | for (auto *CC : C->children()) { |
| 1246 | if (CC) |
| 1247 | Visit(CC); |
| 1248 | } |
| 1249 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1250 | } |
| 1251 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1252 | for (auto *C : S->children()) { |
| 1253 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1254 | Visit(C); |
| 1255 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1256 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1257 | |
| 1258 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1259 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1260 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1261 | return VarsWithInheritedDSA; |
| 1262 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1263 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1264 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1265 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1266 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1267 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1268 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1269 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1270 | switch (DKind) { |
| 1271 | case OMPD_parallel: { |
| 1272 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1273 | QualType KmpInt32PtrTy = |
| 1274 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1275 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1276 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1277 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1278 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1279 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1280 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1281 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1282 | break; |
| 1283 | } |
| 1284 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1285 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1286 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1287 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1288 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1289 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1290 | break; |
| 1291 | } |
| 1292 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1293 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1294 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1295 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1296 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1297 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1298 | break; |
| 1299 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1300 | case OMPD_for_simd: { |
| 1301 | Sema::CapturedParamNameType Params[] = { |
| 1302 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1303 | }; |
| 1304 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1305 | Params); |
| 1306 | break; |
| 1307 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1308 | case OMPD_sections: { |
| 1309 | Sema::CapturedParamNameType Params[] = { |
| 1310 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1311 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1312 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1313 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1314 | break; |
| 1315 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1316 | case OMPD_section: { |
| 1317 | Sema::CapturedParamNameType Params[] = { |
| 1318 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1319 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1320 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1321 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1322 | break; |
| 1323 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1324 | case OMPD_single: { |
| 1325 | Sema::CapturedParamNameType Params[] = { |
| 1326 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1327 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1328 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1329 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1330 | break; |
| 1331 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1332 | case OMPD_master: { |
| 1333 | Sema::CapturedParamNameType Params[] = { |
| 1334 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1335 | }; |
| 1336 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1337 | Params); |
| 1338 | break; |
| 1339 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1340 | case OMPD_critical: { |
| 1341 | Sema::CapturedParamNameType Params[] = { |
| 1342 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1343 | }; |
| 1344 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1345 | Params); |
| 1346 | break; |
| 1347 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1348 | case OMPD_parallel_for: { |
| 1349 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1350 | QualType KmpInt32PtrTy = |
| 1351 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1352 | Sema::CapturedParamNameType Params[] = { |
| 1353 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1354 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1355 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1356 | }; |
| 1357 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1358 | Params); |
| 1359 | break; |
| 1360 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1361 | case OMPD_parallel_for_simd: { |
| 1362 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1363 | QualType KmpInt32PtrTy = |
| 1364 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1365 | Sema::CapturedParamNameType Params[] = { |
| 1366 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1367 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1368 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1369 | }; |
| 1370 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1371 | Params); |
| 1372 | break; |
| 1373 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1374 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1375 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1376 | QualType KmpInt32PtrTy = |
| 1377 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1378 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1379 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1380 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1381 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1382 | }; |
| 1383 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1384 | Params); |
| 1385 | break; |
| 1386 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1387 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1388 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1389 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1390 | FunctionProtoType::ExtProtoInfo EPI; |
| 1391 | EPI.Variadic = true; |
| 1392 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1393 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1394 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1395 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1396 | std::make_pair(".privates.", |
| 1397 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1398 | std::make_pair( |
| 1399 | ".copy_fn.", |
| 1400 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1401 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1402 | }; |
| 1403 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1404 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1405 | // Mark this captured region as inlined, because we don't use outlined |
| 1406 | // function directly. |
| 1407 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1408 | AlwaysInlineAttr::CreateImplicit( |
| 1409 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1410 | break; |
| 1411 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1412 | case OMPD_ordered: { |
| 1413 | Sema::CapturedParamNameType Params[] = { |
| 1414 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1415 | }; |
| 1416 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1417 | Params); |
| 1418 | break; |
| 1419 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1420 | case OMPD_atomic: { |
| 1421 | Sema::CapturedParamNameType Params[] = { |
| 1422 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1423 | }; |
| 1424 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1425 | Params); |
| 1426 | break; |
| 1427 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1428 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1429 | case OMPD_target: { |
| 1430 | Sema::CapturedParamNameType Params[] = { |
| 1431 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1432 | }; |
| 1433 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1434 | Params); |
| 1435 | break; |
| 1436 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1437 | case OMPD_teams: { |
| 1438 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1439 | QualType KmpInt32PtrTy = |
| 1440 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1441 | Sema::CapturedParamNameType Params[] = { |
| 1442 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1443 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1444 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1445 | }; |
| 1446 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1447 | Params); |
| 1448 | break; |
| 1449 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1450 | case OMPD_taskgroup: { |
| 1451 | Sema::CapturedParamNameType Params[] = { |
| 1452 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1453 | }; |
| 1454 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1455 | Params); |
| 1456 | break; |
| 1457 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1458 | case OMPD_taskloop: { |
| 1459 | Sema::CapturedParamNameType Params[] = { |
| 1460 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1461 | }; |
| 1462 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1463 | Params); |
| 1464 | break; |
| 1465 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1466 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1467 | case OMPD_taskyield: |
| 1468 | case OMPD_barrier: |
| 1469 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1470 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1471 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1472 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1473 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1474 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1475 | llvm_unreachable("Unknown OpenMP directive"); |
| 1476 | } |
| 1477 | } |
| 1478 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1479 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1480 | ArrayRef<OMPClause *> Clauses) { |
| 1481 | if (!S.isUsable()) { |
| 1482 | ActOnCapturedRegionError(); |
| 1483 | return StmtError(); |
| 1484 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1485 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1486 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1487 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1488 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1489 | (getLangOpts().OpenMPUseTLS && |
| 1490 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1491 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1492 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1493 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1494 | for (auto *VarRef : Clause->children()) { |
| 1495 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1496 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1497 | } |
| 1498 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1499 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1500 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1501 | Clause->getClauseKind() == OMPC_schedule) { |
| 1502 | // Mark all variables in private list clauses as used in inner region. |
| 1503 | // Required for proper codegen of combined directives. |
| 1504 | // TODO: add processing for other clauses. |
| 1505 | if (auto *E = cast_or_null<Expr>( |
| 1506 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1507 | MarkDeclarationsReferencedInExpr(E); |
| 1508 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | return ActOnCapturedRegionEnd(S.get()); |
| 1512 | } |
| 1513 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1514 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1515 | OpenMPDirectiveKind CurrentRegion, |
| 1516 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1517 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1518 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1519 | // Allowed nesting of constructs |
| 1520 | // +------------------+-----------------+------------------------------------+ |
| 1521 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1522 | // +------------------+-----------------+------------------------------------+ |
| 1523 | // | parallel | parallel | * | |
| 1524 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1525 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1526 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1527 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1528 | // | parallel | simd | * | |
| 1529 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1530 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1531 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1532 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1533 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1534 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1535 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1536 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1537 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1538 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1539 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1540 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1541 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1542 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1543 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1544 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1545 | // | parallel | cancellation | | |
| 1546 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1547 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1548 | // | parallel | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1549 | // +------------------+-----------------+------------------------------------+ |
| 1550 | // | for | parallel | * | |
| 1551 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1552 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1553 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1554 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1555 | // | for | simd | * | |
| 1556 | // | for | sections | + | |
| 1557 | // | for | section | + | |
| 1558 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1559 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1560 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1561 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1562 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1563 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1564 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1565 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1566 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1567 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1568 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1569 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1570 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1571 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1572 | // | for | cancellation | | |
| 1573 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1574 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1575 | // | for | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1576 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1577 | // | master | parallel | * | |
| 1578 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1579 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1580 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1581 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1582 | // | master | simd | * | |
| 1583 | // | master | sections | + | |
| 1584 | // | master | section | + | |
| 1585 | // | master | single | + | |
| 1586 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1587 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1588 | // | master |parallel sections| * | |
| 1589 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1590 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1591 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1592 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1593 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1594 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1595 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1596 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1597 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1598 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1599 | // | master | cancellation | | |
| 1600 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1601 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1602 | // | master | taskloop | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1603 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1604 | // | critical | parallel | * | |
| 1605 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1606 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1607 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1608 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1609 | // | critical | simd | * | |
| 1610 | // | critical | sections | + | |
| 1611 | // | critical | section | + | |
| 1612 | // | critical | single | + | |
| 1613 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1614 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1615 | // | critical |parallel sections| * | |
| 1616 | // | critical | task | * | |
| 1617 | // | critical | taskyield | * | |
| 1618 | // | critical | barrier | + | |
| 1619 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1620 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1621 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1622 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1623 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1624 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1625 | // | critical | cancellation | | |
| 1626 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1627 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1628 | // | critical | taskloop | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1629 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1630 | // | simd | parallel | | |
| 1631 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1632 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1633 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1634 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1635 | // | simd | simd | | |
| 1636 | // | simd | sections | | |
| 1637 | // | simd | section | | |
| 1638 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1639 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1640 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1641 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1642 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1643 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1644 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1645 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1646 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1647 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1648 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1649 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1650 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1651 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1652 | // | simd | cancellation | | |
| 1653 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1654 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1655 | // | simd | taskloop | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1656 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1657 | // | for simd | parallel | | |
| 1658 | // | for simd | for | | |
| 1659 | // | for simd | for simd | | |
| 1660 | // | for simd | master | | |
| 1661 | // | for simd | critical | | |
| 1662 | // | for simd | simd | | |
| 1663 | // | for simd | sections | | |
| 1664 | // | for simd | section | | |
| 1665 | // | for simd | single | | |
| 1666 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1667 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1668 | // | for simd |parallel sections| | |
| 1669 | // | for simd | task | | |
| 1670 | // | for simd | taskyield | | |
| 1671 | // | for simd | barrier | | |
| 1672 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1673 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1674 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1675 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1676 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1677 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1678 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1679 | // | for simd | cancellation | | |
| 1680 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1681 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1682 | // | for simd | taskloop | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1683 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1684 | // | parallel for simd| parallel | | |
| 1685 | // | parallel for simd| for | | |
| 1686 | // | parallel for simd| for simd | | |
| 1687 | // | parallel for simd| master | | |
| 1688 | // | parallel for simd| critical | | |
| 1689 | // | parallel for simd| simd | | |
| 1690 | // | parallel for simd| sections | | |
| 1691 | // | parallel for simd| section | | |
| 1692 | // | parallel for simd| single | | |
| 1693 | // | parallel for simd| parallel for | | |
| 1694 | // | parallel for simd|parallel for simd| | |
| 1695 | // | parallel for simd|parallel sections| | |
| 1696 | // | parallel for simd| task | | |
| 1697 | // | parallel for simd| taskyield | | |
| 1698 | // | parallel for simd| barrier | | |
| 1699 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1700 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1701 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1702 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1703 | // | parallel for simd| atomic | | |
| 1704 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1705 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1706 | // | parallel for simd| cancellation | | |
| 1707 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1708 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1709 | // | parallel for simd| taskloop | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1710 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1711 | // | sections | parallel | * | |
| 1712 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1713 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1714 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1715 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1716 | // | sections | simd | * | |
| 1717 | // | sections | sections | + | |
| 1718 | // | sections | section | * | |
| 1719 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1720 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1721 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1722 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1723 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1724 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1725 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1726 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1727 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1728 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1729 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1730 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1731 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1732 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1733 | // | sections | cancellation | | |
| 1734 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1735 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1736 | // | sections | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1737 | // +------------------+-----------------+------------------------------------+ |
| 1738 | // | section | parallel | * | |
| 1739 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1740 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1741 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1742 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1743 | // | section | simd | * | |
| 1744 | // | section | sections | + | |
| 1745 | // | section | section | + | |
| 1746 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1747 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1748 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1749 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1750 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1751 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1752 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1753 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1754 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1755 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1756 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1757 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1758 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1759 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1760 | // | section | cancellation | | |
| 1761 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1762 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1763 | // | section | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1764 | // +------------------+-----------------+------------------------------------+ |
| 1765 | // | single | parallel | * | |
| 1766 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1767 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1768 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1769 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1770 | // | single | simd | * | |
| 1771 | // | single | sections | + | |
| 1772 | // | single | section | + | |
| 1773 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1774 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1775 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1776 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1777 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1778 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1779 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1780 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1781 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1782 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1783 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1784 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1785 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1786 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1787 | // | single | cancellation | | |
| 1788 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1789 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1790 | // | single | taskloop | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1791 | // +------------------+-----------------+------------------------------------+ |
| 1792 | // | parallel for | parallel | * | |
| 1793 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1794 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1795 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1796 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1797 | // | parallel for | simd | * | |
| 1798 | // | parallel for | sections | + | |
| 1799 | // | parallel for | section | + | |
| 1800 | // | parallel for | single | + | |
| 1801 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1802 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1803 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1804 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1805 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1806 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1807 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1808 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1809 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1810 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1811 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1812 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1813 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1814 | // | parallel for | cancellation | | |
| 1815 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1816 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1817 | // | parallel for | taskloop | * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1818 | // +------------------+-----------------+------------------------------------+ |
| 1819 | // | parallel sections| parallel | * | |
| 1820 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1821 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1822 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1823 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1824 | // | parallel sections| simd | * | |
| 1825 | // | parallel sections| sections | + | |
| 1826 | // | parallel sections| section | * | |
| 1827 | // | parallel sections| single | + | |
| 1828 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1829 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1830 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1831 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1832 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1833 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1834 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1835 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1836 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1837 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1838 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1839 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1840 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1841 | // | parallel sections| cancellation | | |
| 1842 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1843 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1844 | // | parallel sections| taskloop | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1845 | // +------------------+-----------------+------------------------------------+ |
| 1846 | // | task | parallel | * | |
| 1847 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1848 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1849 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1850 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1851 | // | task | simd | * | |
| 1852 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1853 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1854 | // | task | single | + | |
| 1855 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1856 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1857 | // | task |parallel sections| * | |
| 1858 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1859 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1860 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1861 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1862 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1863 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1864 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1865 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1866 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1867 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1868 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1869 | // | | point | ! | |
| 1870 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1871 | // | task | taskloop | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1872 | // +------------------+-----------------+------------------------------------+ |
| 1873 | // | ordered | parallel | * | |
| 1874 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1875 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1876 | // | ordered | master | * | |
| 1877 | // | ordered | critical | * | |
| 1878 | // | ordered | simd | * | |
| 1879 | // | ordered | sections | + | |
| 1880 | // | ordered | section | + | |
| 1881 | // | ordered | single | + | |
| 1882 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1883 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1884 | // | ordered |parallel sections| * | |
| 1885 | // | ordered | task | * | |
| 1886 | // | ordered | taskyield | * | |
| 1887 | // | ordered | barrier | + | |
| 1888 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1889 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1890 | // | ordered | flush | * | |
| 1891 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1892 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1893 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1894 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1895 | // | ordered | cancellation | | |
| 1896 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1897 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1898 | // | ordered | taskloop | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1899 | // +------------------+-----------------+------------------------------------+ |
| 1900 | // | atomic | parallel | | |
| 1901 | // | atomic | for | | |
| 1902 | // | atomic | for simd | | |
| 1903 | // | atomic | master | | |
| 1904 | // | atomic | critical | | |
| 1905 | // | atomic | simd | | |
| 1906 | // | atomic | sections | | |
| 1907 | // | atomic | section | | |
| 1908 | // | atomic | single | | |
| 1909 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1910 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1911 | // | atomic |parallel sections| | |
| 1912 | // | atomic | task | | |
| 1913 | // | atomic | taskyield | | |
| 1914 | // | atomic | barrier | | |
| 1915 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1916 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1917 | // | atomic | flush | | |
| 1918 | // | atomic | ordered | | |
| 1919 | // | atomic | atomic | | |
| 1920 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1921 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1922 | // | atomic | cancellation | | |
| 1923 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1924 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1925 | // | atomic | taskloop | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1926 | // +------------------+-----------------+------------------------------------+ |
| 1927 | // | target | parallel | * | |
| 1928 | // | target | for | * | |
| 1929 | // | target | for simd | * | |
| 1930 | // | target | master | * | |
| 1931 | // | target | critical | * | |
| 1932 | // | target | simd | * | |
| 1933 | // | target | sections | * | |
| 1934 | // | target | section | * | |
| 1935 | // | target | single | * | |
| 1936 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1937 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1938 | // | target |parallel sections| * | |
| 1939 | // | target | task | * | |
| 1940 | // | target | taskyield | * | |
| 1941 | // | target | barrier | * | |
| 1942 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1943 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1944 | // | target | flush | * | |
| 1945 | // | target | ordered | * | |
| 1946 | // | target | atomic | * | |
| 1947 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1948 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1949 | // | target | cancellation | | |
| 1950 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1951 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1952 | // | target | taskloop | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1953 | // +------------------+-----------------+------------------------------------+ |
| 1954 | // | teams | parallel | * | |
| 1955 | // | teams | for | + | |
| 1956 | // | teams | for simd | + | |
| 1957 | // | teams | master | + | |
| 1958 | // | teams | critical | + | |
| 1959 | // | teams | simd | + | |
| 1960 | // | teams | sections | + | |
| 1961 | // | teams | section | + | |
| 1962 | // | teams | single | + | |
| 1963 | // | teams | parallel for | * | |
| 1964 | // | teams |parallel for simd| * | |
| 1965 | // | teams |parallel sections| * | |
| 1966 | // | teams | task | + | |
| 1967 | // | teams | taskyield | + | |
| 1968 | // | teams | barrier | + | |
| 1969 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1970 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1971 | // | teams | flush | + | |
| 1972 | // | teams | ordered | + | |
| 1973 | // | teams | atomic | + | |
| 1974 | // | teams | target | + | |
| 1975 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1976 | // | teams | cancellation | | |
| 1977 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1978 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 1979 | // | teams | taskloop | + | |
| 1980 | // +------------------+-----------------+------------------------------------+ |
| 1981 | // | taskloop | parallel | * | |
| 1982 | // | taskloop | for | + | |
| 1983 | // | taskloop | for simd | + | |
| 1984 | // | taskloop | master | + | |
| 1985 | // | taskloop | critical | * | |
| 1986 | // | taskloop | simd | * | |
| 1987 | // | taskloop | sections | + | |
| 1988 | // | taskloop | section | + | |
| 1989 | // | taskloop | single | + | |
| 1990 | // | taskloop | parallel for | * | |
| 1991 | // | taskloop |parallel for simd| * | |
| 1992 | // | taskloop |parallel sections| * | |
| 1993 | // | taskloop | task | * | |
| 1994 | // | taskloop | taskyield | * | |
| 1995 | // | taskloop | barrier | + | |
| 1996 | // | taskloop | taskwait | * | |
| 1997 | // | taskloop | taskgroup | * | |
| 1998 | // | taskloop | flush | * | |
| 1999 | // | taskloop | ordered | + | |
| 2000 | // | taskloop | atomic | * | |
| 2001 | // | taskloop | target | * | |
| 2002 | // | taskloop | teams | + | |
| 2003 | // | taskloop | cancellation | | |
| 2004 | // | | point | | |
| 2005 | // | taskloop | cancel | | |
| 2006 | // | taskloop | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2007 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2008 | if (Stack->getCurScope()) { |
| 2009 | auto ParentRegion = Stack->getParentDirective(); |
| 2010 | bool NestingProhibited = false; |
| 2011 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2012 | enum { |
| 2013 | NoRecommend, |
| 2014 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2015 | ShouldBeInOrderedRegion, |
| 2016 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2017 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2018 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2019 | // OpenMP [2.16, Nesting of Regions] |
| 2020 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2021 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2022 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2023 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2024 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2025 | return true; |
| 2026 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2027 | if (ParentRegion == OMPD_atomic) { |
| 2028 | // OpenMP [2.16, Nesting of Regions] |
| 2029 | // OpenMP constructs may not be nested inside an atomic region. |
| 2030 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2031 | return true; |
| 2032 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2033 | if (CurrentRegion == OMPD_section) { |
| 2034 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2035 | // Orphaned section directives are prohibited. That is, the section |
| 2036 | // directives must appear within the sections construct and must not be |
| 2037 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2038 | if (ParentRegion != OMPD_sections && |
| 2039 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2040 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2041 | << (ParentRegion != OMPD_unknown) |
| 2042 | << getOpenMPDirectiveName(ParentRegion); |
| 2043 | return true; |
| 2044 | } |
| 2045 | return false; |
| 2046 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2047 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2048 | // called from OpenMP regions with the required preconditions). |
| 2049 | if (ParentRegion == OMPD_unknown) |
| 2050 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2051 | if (CurrentRegion == OMPD_cancellation_point || |
| 2052 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2053 | // OpenMP [2.16, Nesting of Regions] |
| 2054 | // A cancellation point construct for which construct-type-clause is |
| 2055 | // taskgroup must be nested inside a task construct. A cancellation |
| 2056 | // point construct for which construct-type-clause is not taskgroup must |
| 2057 | // be closely nested inside an OpenMP construct that matches the type |
| 2058 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2059 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2060 | // nested inside a task construct. A cancel construct for which |
| 2061 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2062 | // OpenMP construct that matches the type specified in |
| 2063 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2064 | NestingProhibited = |
| 2065 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2066 | (CancelRegion == OMPD_for && |
| 2067 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2068 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2069 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2070 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2071 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2072 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2073 | // OpenMP [2.16, Nesting of Regions] |
| 2074 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2075 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2076 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 2077 | ParentRegion == OMPD_task || |
| 2078 | ParentRegion == OMPD_taskloop; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2079 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2080 | // OpenMP [2.16, Nesting of Regions] |
| 2081 | // A critical region may not be nested (closely or otherwise) inside a |
| 2082 | // critical region with the same name. Note that this restriction is not |
| 2083 | // sufficient to prevent deadlock. |
| 2084 | SourceLocation PreviousCriticalLoc; |
| 2085 | bool DeadLock = |
| 2086 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2087 | OpenMPDirectiveKind K, |
| 2088 | const DeclarationNameInfo &DNI, |
| 2089 | SourceLocation Loc) |
| 2090 | ->bool { |
| 2091 | if (K == OMPD_critical && |
| 2092 | DNI.getName() == CurrentName.getName()) { |
| 2093 | PreviousCriticalLoc = Loc; |
| 2094 | return true; |
| 2095 | } else |
| 2096 | return false; |
| 2097 | }, |
| 2098 | false /* skip top directive */); |
| 2099 | if (DeadLock) { |
| 2100 | SemaRef.Diag(StartLoc, |
| 2101 | diag::err_omp_prohibited_region_critical_same_name) |
| 2102 | << CurrentName.getName(); |
| 2103 | if (PreviousCriticalLoc.isValid()) |
| 2104 | SemaRef.Diag(PreviousCriticalLoc, |
| 2105 | diag::note_omp_previous_critical_region); |
| 2106 | return true; |
| 2107 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2108 | } else if (CurrentRegion == OMPD_barrier) { |
| 2109 | // OpenMP [2.16, Nesting of Regions] |
| 2110 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2111 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2112 | NestingProhibited = |
| 2113 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2114 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 2115 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
| 2116 | ParentRegion == OMPD_taskloop; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2117 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2118 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2119 | // OpenMP [2.16, Nesting of Regions] |
| 2120 | // A worksharing region may not be closely nested inside a worksharing, |
| 2121 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2122 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2123 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2124 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 2125 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
| 2126 | ParentRegion == OMPD_taskloop; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2127 | Recommend = ShouldBeInParallelRegion; |
| 2128 | } else if (CurrentRegion == OMPD_ordered) { |
| 2129 | // OpenMP [2.16, Nesting of Regions] |
| 2130 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2131 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2132 | // An ordered region must be closely nested inside a loop region (or |
| 2133 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2134 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2135 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2136 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2137 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2138 | ParentRegion == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 2139 | ParentRegion == OMPD_taskloop || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2140 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2141 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2142 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2143 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2144 | // OpenMP [2.16, Nesting of Regions] |
| 2145 | // If specified, a teams construct must be contained within a target |
| 2146 | // construct. |
| 2147 | NestingProhibited = ParentRegion != OMPD_target; |
| 2148 | Recommend = ShouldBeInTargetRegion; |
| 2149 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2150 | } |
| 2151 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2152 | // OpenMP [2.16, Nesting of Regions] |
| 2153 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2154 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2155 | // constructs that can be closely nested in the teams region. |
| 2156 | // TODO: add distribute directive. |
| 2157 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 2158 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2159 | } |
| 2160 | if (NestingProhibited) { |
| 2161 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2162 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2163 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2164 | return true; |
| 2165 | } |
| 2166 | } |
| 2167 | return false; |
| 2168 | } |
| 2169 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2170 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2171 | ArrayRef<OMPClause *> Clauses, |
| 2172 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2173 | bool ErrorFound = false; |
| 2174 | unsigned NamedModifiersNumber = 0; |
| 2175 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2176 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2177 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2178 | for (const auto *C : Clauses) { |
| 2179 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2180 | // At most one if clause without a directive-name-modifier can appear on |
| 2181 | // the directive. |
| 2182 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2183 | if (FoundNameModifiers[CurNM]) { |
| 2184 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2185 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2186 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2187 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2188 | } else if (CurNM != OMPD_unknown) { |
| 2189 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2190 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2191 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2192 | FoundNameModifiers[CurNM] = IC; |
| 2193 | if (CurNM == OMPD_unknown) |
| 2194 | continue; |
| 2195 | // Check if the specified name modifier is allowed for the current |
| 2196 | // directive. |
| 2197 | // At most one if clause with the particular directive-name-modifier can |
| 2198 | // appear on the directive. |
| 2199 | bool MatchFound = false; |
| 2200 | for (auto NM : AllowedNameModifiers) { |
| 2201 | if (CurNM == NM) { |
| 2202 | MatchFound = true; |
| 2203 | break; |
| 2204 | } |
| 2205 | } |
| 2206 | if (!MatchFound) { |
| 2207 | S.Diag(IC->getNameModifierLoc(), |
| 2208 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2209 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2210 | ErrorFound = true; |
| 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | // If any if clause on the directive includes a directive-name-modifier then |
| 2215 | // all if clauses on the directive must include a directive-name-modifier. |
| 2216 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2217 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2218 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2219 | diag::err_omp_no_more_if_clause); |
| 2220 | } else { |
| 2221 | std::string Values; |
| 2222 | std::string Sep(", "); |
| 2223 | unsigned AllowedCnt = 0; |
| 2224 | unsigned TotalAllowedNum = |
| 2225 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2226 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2227 | ++Cnt) { |
| 2228 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2229 | if (!FoundNameModifiers[NM]) { |
| 2230 | Values += "'"; |
| 2231 | Values += getOpenMPDirectiveName(NM); |
| 2232 | Values += "'"; |
| 2233 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2234 | Values += " or "; |
| 2235 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2236 | Values += Sep; |
| 2237 | ++AllowedCnt; |
| 2238 | } |
| 2239 | } |
| 2240 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2241 | diag::err_omp_unnamed_if_clause) |
| 2242 | << (TotalAllowedNum > 1) << Values; |
| 2243 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2244 | for (auto Loc : NameModifierLoc) { |
| 2245 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2246 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2247 | ErrorFound = true; |
| 2248 | } |
| 2249 | return ErrorFound; |
| 2250 | } |
| 2251 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2252 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2253 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2254 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2255 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2256 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2257 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2258 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2259 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2260 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2261 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2262 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2263 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2264 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2265 | if (AStmt) { |
| 2266 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2267 | |
| 2268 | // Check default data sharing attributes for referenced variables. |
| 2269 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2270 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2271 | if (DSAChecker.isErrorFound()) |
| 2272 | return StmtError(); |
| 2273 | // Generate list of implicitly defined firstprivate variables. |
| 2274 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2275 | |
| 2276 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2277 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2278 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2279 | SourceLocation(), SourceLocation())) { |
| 2280 | ClausesWithImplicit.push_back(Implicit); |
| 2281 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2282 | DSAChecker.getImplicitFirstprivate().size(); |
| 2283 | } else |
| 2284 | ErrorFound = true; |
| 2285 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2286 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2287 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2288 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2289 | switch (Kind) { |
| 2290 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2291 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2292 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2293 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2294 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2295 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2296 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2297 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2298 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2299 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2300 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2301 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2302 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2303 | case OMPD_for_simd: |
| 2304 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2305 | EndLoc, VarsWithInheritedDSA); |
| 2306 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2307 | case OMPD_sections: |
| 2308 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2309 | EndLoc); |
| 2310 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2311 | case OMPD_section: |
| 2312 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2313 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2314 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2315 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2316 | case OMPD_single: |
| 2317 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2318 | EndLoc); |
| 2319 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2320 | case OMPD_master: |
| 2321 | assert(ClausesWithImplicit.empty() && |
| 2322 | "No clauses are allowed for 'omp master' directive"); |
| 2323 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2324 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2325 | case OMPD_critical: |
| 2326 | assert(ClausesWithImplicit.empty() && |
| 2327 | "No clauses are allowed for 'omp critical' directive"); |
| 2328 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2329 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2330 | case OMPD_parallel_for: |
| 2331 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2332 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2333 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2334 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2335 | case OMPD_parallel_for_simd: |
| 2336 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2337 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2338 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2339 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2340 | case OMPD_parallel_sections: |
| 2341 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2342 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2343 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2344 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2345 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2346 | Res = |
| 2347 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2348 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2349 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2350 | case OMPD_taskyield: |
| 2351 | assert(ClausesWithImplicit.empty() && |
| 2352 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2353 | assert(AStmt == nullptr && |
| 2354 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2355 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2356 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2357 | case OMPD_barrier: |
| 2358 | assert(ClausesWithImplicit.empty() && |
| 2359 | "No clauses are allowed for 'omp barrier' directive"); |
| 2360 | assert(AStmt == nullptr && |
| 2361 | "No associated statement allowed for 'omp barrier' directive"); |
| 2362 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2363 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2364 | case OMPD_taskwait: |
| 2365 | assert(ClausesWithImplicit.empty() && |
| 2366 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2367 | assert(AStmt == nullptr && |
| 2368 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2369 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2370 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2371 | case OMPD_taskgroup: |
| 2372 | assert(ClausesWithImplicit.empty() && |
| 2373 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2374 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2375 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2376 | case OMPD_flush: |
| 2377 | assert(AStmt == nullptr && |
| 2378 | "No associated statement allowed for 'omp flush' directive"); |
| 2379 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2380 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2381 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2382 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2383 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2384 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2385 | case OMPD_atomic: |
| 2386 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2387 | EndLoc); |
| 2388 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2389 | case OMPD_teams: |
| 2390 | Res = |
| 2391 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2392 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2393 | case OMPD_target: |
| 2394 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2395 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2396 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2397 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2398 | case OMPD_cancellation_point: |
| 2399 | assert(ClausesWithImplicit.empty() && |
| 2400 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2401 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2402 | "cancellation point' directive"); |
| 2403 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2404 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2405 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2406 | assert(AStmt == nullptr && |
| 2407 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2408 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2409 | CancelRegion); |
| 2410 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2411 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2412 | case OMPD_target_data: |
| 2413 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2414 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2415 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2416 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 2417 | case OMPD_taskloop: |
| 2418 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2419 | EndLoc, VarsWithInheritedDSA); |
| 2420 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2421 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2422 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2423 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2424 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2425 | llvm_unreachable("Unknown OpenMP directive"); |
| 2426 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2427 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2428 | for (auto P : VarsWithInheritedDSA) { |
| 2429 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2430 | << P.first << P.second->getSourceRange(); |
| 2431 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2432 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2433 | |
| 2434 | if (!AllowedNameModifiers.empty()) |
| 2435 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2436 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2437 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2438 | if (ErrorFound) |
| 2439 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2440 | return Res; |
| 2441 | } |
| 2442 | |
| 2443 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2444 | Stmt *AStmt, |
| 2445 | SourceLocation StartLoc, |
| 2446 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2447 | if (!AStmt) |
| 2448 | return StmtError(); |
| 2449 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2450 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2451 | // 1.2.2 OpenMP Language Terminology |
| 2452 | // Structured block - An executable statement with a single entry at the |
| 2453 | // top and a single exit at the bottom. |
| 2454 | // The point of exit cannot be a branch out of the structured block. |
| 2455 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2456 | CS->getCapturedDecl()->setNothrow(); |
| 2457 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2458 | getCurFunction()->setHasBranchProtectedScope(); |
| 2459 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2460 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2461 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2464 | namespace { |
| 2465 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2466 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2467 | /// for IR generation. |
| 2468 | class OpenMPIterationSpaceChecker { |
| 2469 | /// \brief Reference to Sema. |
| 2470 | Sema &SemaRef; |
| 2471 | /// \brief A location for diagnostics (when there is no some better location). |
| 2472 | SourceLocation DefaultLoc; |
| 2473 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2474 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2475 | /// \brief A source location for referring to loop init later. |
| 2476 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2477 | /// \brief A source location for referring to condition later. |
| 2478 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2479 | /// \brief A source location for referring to increment later. |
| 2480 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2481 | /// \brief Loop variable. |
| 2482 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2483 | /// \brief Reference to loop variable. |
| 2484 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2485 | /// \brief Lower bound (initializer for the var). |
| 2486 | Expr *LB; |
| 2487 | /// \brief Upper bound. |
| 2488 | Expr *UB; |
| 2489 | /// \brief Loop step (increment). |
| 2490 | Expr *Step; |
| 2491 | /// \brief This flag is true when condition is one of: |
| 2492 | /// Var < UB |
| 2493 | /// Var <= UB |
| 2494 | /// UB > Var |
| 2495 | /// UB >= Var |
| 2496 | bool TestIsLessOp; |
| 2497 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2498 | bool TestIsStrictOp; |
| 2499 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2500 | bool SubtractStep; |
| 2501 | |
| 2502 | public: |
| 2503 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2504 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2505 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2506 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2507 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2508 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2509 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2510 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2511 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2512 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2513 | /// for less/greater and for strict/non-strict comparison. |
| 2514 | bool CheckCond(Expr *S); |
| 2515 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2516 | /// does not conform, otherwise save loop step (#Step). |
| 2517 | bool CheckInc(Expr *S); |
| 2518 | /// \brief Return the loop counter variable. |
| 2519 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2520 | /// \brief Return the reference expression to loop counter variable. |
| 2521 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2522 | /// \brief Source range of the loop init. |
| 2523 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2524 | /// \brief Source range of the loop condition. |
| 2525 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2526 | /// \brief Source range of the loop increment. |
| 2527 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2528 | /// \brief True if the step should be subtracted. |
| 2529 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2530 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2531 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2532 | /// \brief Build the precondition expression for the loops. |
| 2533 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2534 | /// \brief Build reference expression to the counter be used for codegen. |
| 2535 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2536 | /// \brief Build reference expression to the private counter be used for |
| 2537 | /// codegen. |
| 2538 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2539 | /// \brief Build initization of the counter be used for codegen. |
| 2540 | Expr *BuildCounterInit() const; |
| 2541 | /// \brief Build step of the counter be used for codegen. |
| 2542 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2543 | /// \brief Return true if any expression is dependent. |
| 2544 | bool Dependent() const; |
| 2545 | |
| 2546 | private: |
| 2547 | /// \brief Check the right-hand side of an assignment in the increment |
| 2548 | /// expression. |
| 2549 | bool CheckIncRHS(Expr *RHS); |
| 2550 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2551 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2552 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2553 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2554 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2555 | /// \brief Helper to set loop increment. |
| 2556 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2557 | }; |
| 2558 | |
| 2559 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2560 | if (!Var) { |
| 2561 | assert(!LB && !UB && !Step); |
| 2562 | return false; |
| 2563 | } |
| 2564 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2565 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2566 | } |
| 2567 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2568 | template <typename T> |
| 2569 | static T *getExprAsWritten(T *E) { |
| 2570 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2571 | E = ExprTemp->getSubExpr(); |
| 2572 | |
| 2573 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2574 | E = MTE->GetTemporaryExpr(); |
| 2575 | |
| 2576 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2577 | E = Binder->getSubExpr(); |
| 2578 | |
| 2579 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2580 | E = ICE->getSubExprAsWritten(); |
| 2581 | return E->IgnoreParens(); |
| 2582 | } |
| 2583 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2584 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2585 | DeclRefExpr *NewVarRefExpr, |
| 2586 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2587 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2588 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2589 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2590 | if (!NewVar || !NewLB) |
| 2591 | return true; |
| 2592 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2593 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2594 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2595 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2596 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2597 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2598 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2599 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2600 | LB = NewLB; |
| 2601 | return false; |
| 2602 | } |
| 2603 | |
| 2604 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2605 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2606 | // State consistency checking to ensure correct usage. |
| 2607 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2608 | !TestIsLessOp && !TestIsStrictOp); |
| 2609 | if (!NewUB) |
| 2610 | return true; |
| 2611 | UB = NewUB; |
| 2612 | TestIsLessOp = LessOp; |
| 2613 | TestIsStrictOp = StrictOp; |
| 2614 | ConditionSrcRange = SR; |
| 2615 | ConditionLoc = SL; |
| 2616 | return false; |
| 2617 | } |
| 2618 | |
| 2619 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2620 | // State consistency checking to ensure correct usage. |
| 2621 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2622 | if (!NewStep) |
| 2623 | return true; |
| 2624 | if (!NewStep->isValueDependent()) { |
| 2625 | // Check that the step is integer expression. |
| 2626 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2627 | ExprResult Val = |
| 2628 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2629 | if (Val.isInvalid()) |
| 2630 | return true; |
| 2631 | NewStep = Val.get(); |
| 2632 | |
| 2633 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2634 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2635 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2636 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2637 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2638 | // the loop. |
| 2639 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2640 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2641 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2642 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2643 | // the loop. |
| 2644 | llvm::APSInt Result; |
| 2645 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2646 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2647 | bool IsConstNeg = |
| 2648 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2649 | bool IsConstPos = |
| 2650 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2651 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2652 | if (UB && (IsConstZero || |
| 2653 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2654 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2655 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2656 | diag::err_omp_loop_incr_not_compatible) |
| 2657 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2658 | SemaRef.Diag(ConditionLoc, |
| 2659 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2660 | << TestIsLessOp << ConditionSrcRange; |
| 2661 | return true; |
| 2662 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2663 | if (TestIsLessOp == Subtract) { |
| 2664 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2665 | NewStep).get(); |
| 2666 | Subtract = !Subtract; |
| 2667 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | Step = NewStep; |
| 2671 | SubtractStep = Subtract; |
| 2672 | return false; |
| 2673 | } |
| 2674 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2675 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2676 | // Check init-expr for canonical loop form and save loop counter |
| 2677 | // variable - #Var and its initialization value - #LB. |
| 2678 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2679 | // var = lb |
| 2680 | // integer-type var = lb |
| 2681 | // random-access-iterator-type var = lb |
| 2682 | // pointer-type var = lb |
| 2683 | // |
| 2684 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2685 | if (EmitDiags) { |
| 2686 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2687 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2688 | return true; |
| 2689 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2690 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2691 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2692 | S = E->IgnoreParens(); |
| 2693 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2694 | if (BO->getOpcode() == BO_Assign) |
| 2695 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2696 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2697 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2698 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2699 | if (DS->isSingleDecl()) { |
| 2700 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2701 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2702 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2703 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2704 | SemaRef.Diag(S->getLocStart(), |
| 2705 | diag::ext_omp_loop_not_canonical_init) |
| 2706 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2707 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2708 | } |
| 2709 | } |
| 2710 | } |
| 2711 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2712 | if (CE->getOperator() == OO_Equal) |
| 2713 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2714 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2715 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2716 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2717 | if (EmitDiags) { |
| 2718 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2719 | << S->getSourceRange(); |
| 2720 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2721 | return true; |
| 2722 | } |
| 2723 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2724 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2725 | /// variable (which may be the loop variable) if possible. |
| 2726 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2727 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2728 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2729 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2730 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2731 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2732 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2733 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2734 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2735 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2736 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2737 | if (!DRE) |
| 2738 | return nullptr; |
| 2739 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2740 | } |
| 2741 | |
| 2742 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2743 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2744 | // less/greater and for strict/non-strict comparison. |
| 2745 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2746 | // var relational-op b |
| 2747 | // b relational-op var |
| 2748 | // |
| 2749 | if (!S) { |
| 2750 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2751 | return true; |
| 2752 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2753 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2754 | SourceLocation CondLoc = S->getLocStart(); |
| 2755 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2756 | if (BO->isRelationalOp()) { |
| 2757 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2758 | return SetUB(BO->getRHS(), |
| 2759 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2760 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2761 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2762 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2763 | return SetUB(BO->getLHS(), |
| 2764 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2765 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2766 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2767 | } |
| 2768 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2769 | if (CE->getNumArgs() == 2) { |
| 2770 | auto Op = CE->getOperator(); |
| 2771 | switch (Op) { |
| 2772 | case OO_Greater: |
| 2773 | case OO_GreaterEqual: |
| 2774 | case OO_Less: |
| 2775 | case OO_LessEqual: |
| 2776 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2777 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2778 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2779 | CE->getOperatorLoc()); |
| 2780 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2781 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2782 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2783 | CE->getOperatorLoc()); |
| 2784 | break; |
| 2785 | default: |
| 2786 | break; |
| 2787 | } |
| 2788 | } |
| 2789 | } |
| 2790 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2791 | << S->getSourceRange() << Var; |
| 2792 | return true; |
| 2793 | } |
| 2794 | |
| 2795 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2796 | // RHS of canonical loop form increment can be: |
| 2797 | // var + incr |
| 2798 | // incr + var |
| 2799 | // var - incr |
| 2800 | // |
| 2801 | RHS = RHS->IgnoreParenImpCasts(); |
| 2802 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2803 | if (BO->isAdditiveOp()) { |
| 2804 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2805 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2806 | return SetStep(BO->getRHS(), !IsAdd); |
| 2807 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2808 | return SetStep(BO->getLHS(), false); |
| 2809 | } |
| 2810 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2811 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2812 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2813 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2814 | return SetStep(CE->getArg(1), !IsAdd); |
| 2815 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2816 | return SetStep(CE->getArg(0), false); |
| 2817 | } |
| 2818 | } |
| 2819 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2820 | << RHS->getSourceRange() << Var; |
| 2821 | return true; |
| 2822 | } |
| 2823 | |
| 2824 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2825 | // Check incr-expr for canonical loop form and return true if it |
| 2826 | // does not conform. |
| 2827 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2828 | // ++var |
| 2829 | // var++ |
| 2830 | // --var |
| 2831 | // var-- |
| 2832 | // var += incr |
| 2833 | // var -= incr |
| 2834 | // var = var + incr |
| 2835 | // var = incr + var |
| 2836 | // var = var - incr |
| 2837 | // |
| 2838 | if (!S) { |
| 2839 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2840 | return true; |
| 2841 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2842 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2843 | S = S->IgnoreParens(); |
| 2844 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2845 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2846 | return SetStep( |
| 2847 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2848 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2849 | false); |
| 2850 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2851 | switch (BO->getOpcode()) { |
| 2852 | case BO_AddAssign: |
| 2853 | case BO_SubAssign: |
| 2854 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2855 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2856 | break; |
| 2857 | case BO_Assign: |
| 2858 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2859 | return CheckIncRHS(BO->getRHS()); |
| 2860 | break; |
| 2861 | default: |
| 2862 | break; |
| 2863 | } |
| 2864 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2865 | switch (CE->getOperator()) { |
| 2866 | case OO_PlusPlus: |
| 2867 | case OO_MinusMinus: |
| 2868 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2869 | return SetStep( |
| 2870 | SemaRef.ActOnIntegerConstant( |
| 2871 | CE->getLocStart(), |
| 2872 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2873 | false); |
| 2874 | break; |
| 2875 | case OO_PlusEqual: |
| 2876 | case OO_MinusEqual: |
| 2877 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2878 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2879 | break; |
| 2880 | case OO_Equal: |
| 2881 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2882 | return CheckIncRHS(CE->getArg(1)); |
| 2883 | break; |
| 2884 | default: |
| 2885 | break; |
| 2886 | } |
| 2887 | } |
| 2888 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2889 | << S->getSourceRange() << Var; |
| 2890 | return true; |
| 2891 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2892 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2893 | namespace { |
| 2894 | // Transform variables declared in GNU statement expressions to new ones to |
| 2895 | // avoid crash on codegen. |
| 2896 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 2897 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 2898 | |
| 2899 | public: |
| 2900 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 2901 | |
| 2902 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 2903 | if (auto *VD = cast<VarDecl>(D)) |
| 2904 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 2905 | !isa<ImplicitParamDecl>(D)) { |
| 2906 | auto *NewVD = VarDecl::Create( |
| 2907 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 2908 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 2909 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 2910 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 2911 | NewVD->setInit(VD->getInit()); |
| 2912 | NewVD->setInitStyle(VD->getInitStyle()); |
| 2913 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 2914 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 2915 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 2916 | NewVD->setConstexpr(VD->isConstexpr()); |
| 2917 | NewVD->setInitCapture(VD->isInitCapture()); |
| 2918 | NewVD->setPreviousDeclInSameBlockScope( |
| 2919 | VD->isPreviousDeclInSameBlockScope()); |
| 2920 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 2921 | if (VD->hasAttrs()) |
| 2922 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2923 | transformedLocalDecl(VD, NewVD); |
| 2924 | return NewVD; |
| 2925 | } |
| 2926 | return BaseTransform::TransformDefinition(Loc, D); |
| 2927 | } |
| 2928 | |
| 2929 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 2930 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 2931 | if (E->getDecl() != NewD) { |
| 2932 | NewD->setReferenced(); |
| 2933 | NewD->markUsed(SemaRef.Context); |
| 2934 | return DeclRefExpr::Create( |
| 2935 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 2936 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 2937 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 2938 | } |
| 2939 | return BaseTransform::TransformDeclRefExpr(E); |
| 2940 | } |
| 2941 | }; |
| 2942 | } |
| 2943 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2944 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2945 | Expr * |
| 2946 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2947 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2948 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2949 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2950 | auto VarType = Var->getType().getNonReferenceType(); |
| 2951 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2952 | SemaRef.getLangOpts().CPlusPlus) { |
| 2953 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2954 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 2955 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 2956 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 2957 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 2958 | if (!Upper || !Lower) |
| 2959 | return nullptr; |
| 2960 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 2961 | Sema::AA_Converting, |
| 2962 | /*AllowExplicit=*/true) |
| 2963 | .get(); |
| 2964 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 2965 | Sema::AA_Converting, |
| 2966 | /*AllowExplicit=*/true) |
| 2967 | .get(); |
| 2968 | if (!Upper || !Lower) |
| 2969 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2970 | |
| 2971 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2972 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2973 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2974 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2975 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2976 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2977 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2978 | return nullptr; |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | if (!Diff.isUsable()) |
| 2983 | return nullptr; |
| 2984 | |
| 2985 | // Upper - Lower [- 1] |
| 2986 | if (TestIsStrictOp) |
| 2987 | Diff = SemaRef.BuildBinOp( |
| 2988 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2989 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2990 | if (!Diff.isUsable()) |
| 2991 | return nullptr; |
| 2992 | |
| 2993 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2994 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2995 | if (NewStep.isInvalid()) |
| 2996 | return nullptr; |
| 2997 | NewStep = SemaRef.PerformImplicitConversion( |
| 2998 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2999 | /*AllowExplicit=*/true); |
| 3000 | if (NewStep.isInvalid()) |
| 3001 | return nullptr; |
| 3002 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3003 | if (!Diff.isUsable()) |
| 3004 | return nullptr; |
| 3005 | |
| 3006 | // Parentheses (for dumping/debugging purposes only). |
| 3007 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3008 | if (!Diff.isUsable()) |
| 3009 | return nullptr; |
| 3010 | |
| 3011 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3012 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3013 | if (NewStep.isInvalid()) |
| 3014 | return nullptr; |
| 3015 | NewStep = SemaRef.PerformImplicitConversion( |
| 3016 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3017 | /*AllowExplicit=*/true); |
| 3018 | if (NewStep.isInvalid()) |
| 3019 | return nullptr; |
| 3020 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3021 | if (!Diff.isUsable()) |
| 3022 | return nullptr; |
| 3023 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3024 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3025 | QualType Type = Diff.get()->getType(); |
| 3026 | auto &C = SemaRef.Context; |
| 3027 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3028 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3029 | if (!Type->isIntegerType() || UseVarType) { |
| 3030 | unsigned NewSize = |
| 3031 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3032 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3033 | : Type->hasSignedIntegerRepresentation(); |
| 3034 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3035 | Diff = SemaRef.PerformImplicitConversion( |
| 3036 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3037 | if (!Diff.isUsable()) |
| 3038 | return nullptr; |
| 3039 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3040 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3041 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3042 | if (NewSize != C.getTypeSize(Type)) { |
| 3043 | if (NewSize < C.getTypeSize(Type)) { |
| 3044 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3045 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3046 | << InitSrcRange << ConditionSrcRange; |
| 3047 | } |
| 3048 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3049 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3050 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3051 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3052 | Sema::AA_Converting, true); |
| 3053 | if (!Diff.isUsable()) |
| 3054 | return nullptr; |
| 3055 | } |
| 3056 | } |
| 3057 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3058 | return Diff.get(); |
| 3059 | } |
| 3060 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3061 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3062 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3063 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3064 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3065 | TransformToNewDefs Transform(SemaRef); |
| 3066 | |
| 3067 | auto NewLB = Transform.TransformExpr(LB); |
| 3068 | auto NewUB = Transform.TransformExpr(UB); |
| 3069 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3070 | return Cond; |
| 3071 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3072 | Sema::AA_Converting, |
| 3073 | /*AllowExplicit=*/true); |
| 3074 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3075 | Sema::AA_Converting, |
| 3076 | /*AllowExplicit=*/true); |
| 3077 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3078 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3079 | auto CondExpr = SemaRef.BuildBinOp( |
| 3080 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3081 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3082 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3083 | if (CondExpr.isUsable()) { |
| 3084 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3085 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3086 | /*AllowExplicit=*/true); |
| 3087 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3088 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3089 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3090 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3091 | } |
| 3092 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3093 | /// \brief Build reference expression to the counter be used for codegen. |
| 3094 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3095 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3096 | DefaultLoc); |
| 3097 | } |
| 3098 | |
| 3099 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3100 | if (Var && !Var->isInvalidDecl()) { |
| 3101 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3102 | auto *PrivateVar = |
| 3103 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3104 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3105 | if (PrivateVar->isInvalidDecl()) |
| 3106 | return nullptr; |
| 3107 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3108 | } |
| 3109 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | /// \brief Build initization of the counter be used for codegen. |
| 3113 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3114 | |
| 3115 | /// \brief Build step of the counter be used for codegen. |
| 3116 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3117 | |
| 3118 | /// \brief Iteration space of a single for loop. |
| 3119 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3120 | /// \brief Condition of the loop. |
| 3121 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3122 | /// \brief This expression calculates the number of iterations in the loop. |
| 3123 | /// It is always possible to calculate it before starting the loop. |
| 3124 | Expr *NumIterations; |
| 3125 | /// \brief The loop counter variable. |
| 3126 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3127 | /// \brief Private loop counter variable. |
| 3128 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3129 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3130 | Expr *CounterInit; |
| 3131 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3132 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3133 | Expr *CounterStep; |
| 3134 | /// \brief Should step be subtracted? |
| 3135 | bool Subtract; |
| 3136 | /// \brief Source range of the loop init. |
| 3137 | SourceRange InitSrcRange; |
| 3138 | /// \brief Source range of the loop condition. |
| 3139 | SourceRange CondSrcRange; |
| 3140 | /// \brief Source range of the loop increment. |
| 3141 | SourceRange IncSrcRange; |
| 3142 | }; |
| 3143 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3144 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3145 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3146 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3147 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3148 | assert(Init && "Expected loop in canonical form."); |
| 3149 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 3150 | if (CollapseIteration > 0 && |
| 3151 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3152 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 3153 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3154 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 3155 | } |
| 3156 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 3157 | } |
| 3158 | } |
| 3159 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3160 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3161 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3162 | static bool CheckOpenMPIterationSpace( |
| 3163 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3164 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3165 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3166 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3167 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3168 | // OpenMP [2.6, Canonical Loop Form] |
| 3169 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3170 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3171 | if (!For) { |
| 3172 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3173 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3174 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3175 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3176 | if (NestedLoopCount > 1) { |
| 3177 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3178 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3179 | diag::note_omp_collapse_ordered_expr) |
| 3180 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3181 | << OrderedLoopCountExpr->getSourceRange(); |
| 3182 | else if (CollapseLoopCountExpr) |
| 3183 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3184 | diag::note_omp_collapse_ordered_expr) |
| 3185 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3186 | else |
| 3187 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3188 | diag::note_omp_collapse_ordered_expr) |
| 3189 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3190 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3191 | return true; |
| 3192 | } |
| 3193 | assert(For->getBody()); |
| 3194 | |
| 3195 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3196 | |
| 3197 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3198 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3199 | if (ISC.CheckInit(Init)) { |
| 3200 | return true; |
| 3201 | } |
| 3202 | |
| 3203 | bool HasErrors = false; |
| 3204 | |
| 3205 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3206 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3207 | |
| 3208 | // OpenMP [2.6, Canonical Loop Form] |
| 3209 | // Var is one of the following: |
| 3210 | // A variable of signed or unsigned integer type. |
| 3211 | // For C++, a variable of a random access iterator type. |
| 3212 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3213 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3214 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3215 | !VarType->isPointerType() && |
| 3216 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3217 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3218 | << SemaRef.getLangOpts().CPlusPlus; |
| 3219 | HasErrors = true; |
| 3220 | } |
| 3221 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3222 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3223 | // Construct |
| 3224 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3225 | // parallel for construct is (are) private. |
| 3226 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3227 | // with just one associated for-loop is linear with a constant-linear-step |
| 3228 | // that is the increment of the associated for-loop. |
| 3229 | // Exclude loop var from the list of variables with implicitly defined data |
| 3230 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3231 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3232 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3233 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3234 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3235 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3236 | // with just one associated for-loop may be listed in a linear clause with a |
| 3237 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3238 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3239 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3240 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3241 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3242 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3243 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3244 | auto PredeterminedCKind = |
| 3245 | isOpenMPSimdDirective(DKind) |
| 3246 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3247 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3248 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3249 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 3250 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) && |
| 3251 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3252 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate && |
| 3253 | DVar.CKind != OMPC_threadprivate)) && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3254 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 3255 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3256 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3257 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3258 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3259 | if (DVar.RefExpr == nullptr) |
| 3260 | DVar.CKind = PredeterminedCKind; |
| 3261 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3262 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3263 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3264 | // Make the loop iteration variable private (for worksharing constructs), |
| 3265 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3266 | // lastprivate (for simd directives with several collapsed or ordered |
| 3267 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3268 | if (DVar.CKind == OMPC_unknown) |
| 3269 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3270 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3271 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3274 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3275 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3276 | // Check test-expr. |
| 3277 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3278 | |
| 3279 | // Check incr-expr. |
| 3280 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3281 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3282 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3283 | return HasErrors; |
| 3284 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3285 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3286 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3287 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 3288 | DSA.getCurScope(), |
| 3289 | (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3290 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3291 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3292 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3293 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3294 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3295 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3296 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3297 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3298 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3299 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3300 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3301 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3302 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3303 | ResultIterSpace.CounterInit == nullptr || |
| 3304 | ResultIterSpace.CounterStep == nullptr); |
| 3305 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3306 | return HasErrors; |
| 3307 | } |
| 3308 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3309 | /// \brief Build 'VarRef = Start. |
| 3310 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3311 | ExprResult VarRef, ExprResult Start) { |
| 3312 | TransformToNewDefs Transform(SemaRef); |
| 3313 | // Build 'VarRef = Start. |
| 3314 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3315 | if (NewStart.isInvalid()) |
| 3316 | return ExprError(); |
| 3317 | NewStart = SemaRef.PerformImplicitConversion( |
| 3318 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3319 | Sema::AA_Converting, |
| 3320 | /*AllowExplicit=*/true); |
| 3321 | if (NewStart.isInvalid()) |
| 3322 | return ExprError(); |
| 3323 | NewStart = SemaRef.PerformImplicitConversion( |
| 3324 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3325 | /*AllowExplicit=*/true); |
| 3326 | if (!NewStart.isUsable()) |
| 3327 | return ExprError(); |
| 3328 | |
| 3329 | auto Init = |
| 3330 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3331 | return Init; |
| 3332 | } |
| 3333 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3334 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3335 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3336 | SourceLocation Loc, ExprResult VarRef, |
| 3337 | ExprResult Start, ExprResult Iter, |
| 3338 | ExprResult Step, bool Subtract) { |
| 3339 | // Add parentheses (for debugging purposes only). |
| 3340 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3341 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3342 | !Step.isUsable()) |
| 3343 | return ExprError(); |
| 3344 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3345 | TransformToNewDefs Transform(SemaRef); |
| 3346 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3347 | if (NewStep.isInvalid()) |
| 3348 | return ExprError(); |
| 3349 | NewStep = SemaRef.PerformImplicitConversion( |
| 3350 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3351 | Sema::AA_Converting, |
| 3352 | /*AllowExplicit=*/true); |
| 3353 | if (NewStep.isInvalid()) |
| 3354 | return ExprError(); |
| 3355 | ExprResult Update = |
| 3356 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3357 | if (!Update.isUsable()) |
| 3358 | return ExprError(); |
| 3359 | |
| 3360 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3361 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3362 | if (NewStart.isInvalid()) |
| 3363 | return ExprError(); |
| 3364 | NewStart = SemaRef.PerformImplicitConversion( |
| 3365 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3366 | Sema::AA_Converting, |
| 3367 | /*AllowExplicit=*/true); |
| 3368 | if (NewStart.isInvalid()) |
| 3369 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3370 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3371 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3372 | if (!Update.isUsable()) |
| 3373 | return ExprError(); |
| 3374 | |
| 3375 | Update = SemaRef.PerformImplicitConversion( |
| 3376 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3377 | if (!Update.isUsable()) |
| 3378 | return ExprError(); |
| 3379 | |
| 3380 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3381 | return Update; |
| 3382 | } |
| 3383 | |
| 3384 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3385 | /// bits. |
| 3386 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3387 | Sema &SemaRef) { |
| 3388 | if (E == nullptr) |
| 3389 | return ExprError(); |
| 3390 | auto &C = SemaRef.Context; |
| 3391 | QualType OldType = E->getType(); |
| 3392 | unsigned HasBits = C.getTypeSize(OldType); |
| 3393 | if (HasBits >= Bits) |
| 3394 | return ExprResult(E); |
| 3395 | // OK to convert to signed, because new type has more bits than old. |
| 3396 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3397 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3398 | true); |
| 3399 | } |
| 3400 | |
| 3401 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3402 | /// into \a Bits bits. |
| 3403 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3404 | if (E == nullptr) |
| 3405 | return false; |
| 3406 | llvm::APSInt Result; |
| 3407 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3408 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3409 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | /// \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] | 3413 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3414 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3415 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3416 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3417 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3418 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3419 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3420 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3421 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3422 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3423 | // Found 'collapse' clause - calculate collapse number. |
| 3424 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3425 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3426 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3427 | } |
| 3428 | if (OrderedLoopCountExpr) { |
| 3429 | // Found 'ordered' clause - calculate collapse number. |
| 3430 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3431 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3432 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3433 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3434 | diag::err_omp_wrong_ordered_loop_count) |
| 3435 | << OrderedLoopCountExpr->getSourceRange(); |
| 3436 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3437 | diag::note_collapse_loop_count) |
| 3438 | << CollapseLoopCountExpr->getSourceRange(); |
| 3439 | } |
| 3440 | NestedLoopCount = Result.getLimitedValue(); |
| 3441 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3442 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3443 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3444 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3445 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3446 | IterSpaces.resize(NestedLoopCount); |
| 3447 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3448 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3449 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3450 | NestedLoopCount, CollapseLoopCountExpr, |
| 3451 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3452 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3453 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3454 | // 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] | 3455 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3456 | // All loops associated with the construct must be perfectly nested; that |
| 3457 | // is, there must be no intervening code nor any OpenMP directive between |
| 3458 | // any two loops. |
| 3459 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3462 | Built.clear(/* size */ NestedLoopCount); |
| 3463 | |
| 3464 | if (SemaRef.CurContext->isDependentContext()) |
| 3465 | return NestedLoopCount; |
| 3466 | |
| 3467 | // An example of what is generated for the following code: |
| 3468 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3469 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3470 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3471 | // for (k = 0; k < NK; ++k) |
| 3472 | // for (j = J0; j < NJ; j+=2) { |
| 3473 | // <loop body> |
| 3474 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3475 | // |
| 3476 | // We generate the code below. |
| 3477 | // Note: the loop body may be outlined in CodeGen. |
| 3478 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3479 | // iterations and operator+= to calculate counter value. |
| 3480 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3481 | // or i64 is currently supported). |
| 3482 | // |
| 3483 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3484 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3485 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3486 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3487 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3488 | // <loop body (using local i and j)> |
| 3489 | // } |
| 3490 | // i = NI; // assign final values of counters |
| 3491 | // j = NJ; |
| 3492 | // |
| 3493 | |
| 3494 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3495 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3496 | // Precondition tests if there is at least one iteration (all conditions are |
| 3497 | // true). |
| 3498 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3499 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3500 | ExprResult LastIteration32 = WidenIterationCount( |
| 3501 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3502 | N0->IgnoreImpCasts(), N0->getType(), |
| 3503 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3504 | .get(), |
| 3505 | SemaRef); |
| 3506 | ExprResult LastIteration64 = WidenIterationCount( |
| 3507 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3508 | N0->IgnoreImpCasts(), N0->getType(), |
| 3509 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3510 | .get(), |
| 3511 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3512 | |
| 3513 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3514 | return NestedLoopCount; |
| 3515 | |
| 3516 | auto &C = SemaRef.Context; |
| 3517 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3518 | |
| 3519 | Scope *CurScope = DSA.getCurScope(); |
| 3520 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3521 | if (PreCond.isUsable()) { |
| 3522 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3523 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3524 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3525 | auto N = IterSpaces[Cnt].NumIterations; |
| 3526 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3527 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3528 | LastIteration32 = SemaRef.BuildBinOp( |
| 3529 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3530 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3531 | Sema::AA_Converting, |
| 3532 | /*AllowExplicit=*/true) |
| 3533 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3534 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3535 | LastIteration64 = SemaRef.BuildBinOp( |
| 3536 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3537 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3538 | Sema::AA_Converting, |
| 3539 | /*AllowExplicit=*/true) |
| 3540 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3541 | } |
| 3542 | |
| 3543 | // Choose either the 32-bit or 64-bit version. |
| 3544 | ExprResult LastIteration = LastIteration64; |
| 3545 | if (LastIteration32.isUsable() && |
| 3546 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3547 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3548 | FitsInto( |
| 3549 | 32 /* Bits */, |
| 3550 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3551 | LastIteration64.get(), SemaRef))) |
| 3552 | LastIteration = LastIteration32; |
| 3553 | |
| 3554 | if (!LastIteration.isUsable()) |
| 3555 | return 0; |
| 3556 | |
| 3557 | // Save the number of iterations. |
| 3558 | ExprResult NumIterations = LastIteration; |
| 3559 | { |
| 3560 | LastIteration = SemaRef.BuildBinOp( |
| 3561 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3562 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3563 | if (!LastIteration.isUsable()) |
| 3564 | return 0; |
| 3565 | } |
| 3566 | |
| 3567 | // Calculate the last iteration number beforehand instead of doing this on |
| 3568 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3569 | llvm::APSInt Result; |
| 3570 | bool IsConstant = |
| 3571 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3572 | ExprResult CalcLastIteration; |
| 3573 | if (!IsConstant) { |
| 3574 | SourceLocation SaveLoc; |
| 3575 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3576 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3577 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3578 | ExprResult SaveRef = buildDeclRefExpr( |
| 3579 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3580 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3581 | SaveRef.get(), LastIteration.get()); |
| 3582 | LastIteration = SaveRef; |
| 3583 | |
| 3584 | // Prepare SaveRef + 1. |
| 3585 | NumIterations = SemaRef.BuildBinOp( |
| 3586 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3587 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3588 | if (!NumIterations.isUsable()) |
| 3589 | return 0; |
| 3590 | } |
| 3591 | |
| 3592 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3593 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3594 | QualType VType = LastIteration.get()->getType(); |
| 3595 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3596 | ExprResult LB, UB, IL, ST, EUB; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 3597 | if ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3598 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3599 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3600 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3601 | SemaRef.AddInitializerToDecl( |
| 3602 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3603 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3604 | |
| 3605 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3606 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3607 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3608 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3609 | /*DirectInit*/ false, |
| 3610 | /*TypeMayContainAuto*/ false); |
| 3611 | |
| 3612 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3613 | // This will be used to implement clause 'lastprivate'. |
| 3614 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3615 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3616 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3617 | SemaRef.AddInitializerToDecl( |
| 3618 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3619 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3620 | |
| 3621 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3622 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3623 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3624 | SemaRef.AddInitializerToDecl( |
| 3625 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3626 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3627 | |
| 3628 | // Build expression: UB = min(UB, LastIteration) |
| 3629 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3630 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3631 | UB.get(), LastIteration.get()); |
| 3632 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3633 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3634 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3635 | CondOp.get()); |
| 3636 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3637 | } |
| 3638 | |
| 3639 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3640 | ExprResult IV; |
| 3641 | ExprResult Init; |
| 3642 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3643 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3644 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 3645 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3646 | ? LB.get() |
| 3647 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3648 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3649 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3650 | } |
| 3651 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3652 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3653 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3654 | ExprResult Cond = |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 3655 | (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3656 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3657 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3658 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3659 | |
| 3660 | // Loop increment (IV = IV + 1) |
| 3661 | SourceLocation IncLoc; |
| 3662 | ExprResult Inc = |
| 3663 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3664 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3665 | if (!Inc.isUsable()) |
| 3666 | return 0; |
| 3667 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3668 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3669 | if (!Inc.isUsable()) |
| 3670 | return 0; |
| 3671 | |
| 3672 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3673 | // Used for directives with static scheduling. |
| 3674 | ExprResult NextLB, NextUB; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 3675 | if (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3676 | // LB + ST |
| 3677 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3678 | if (!NextLB.isUsable()) |
| 3679 | return 0; |
| 3680 | // LB = LB + ST |
| 3681 | NextLB = |
| 3682 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3683 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3684 | if (!NextLB.isUsable()) |
| 3685 | return 0; |
| 3686 | // UB + ST |
| 3687 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3688 | if (!NextUB.isUsable()) |
| 3689 | return 0; |
| 3690 | // UB = UB + ST |
| 3691 | NextUB = |
| 3692 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3693 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3694 | if (!NextUB.isUsable()) |
| 3695 | return 0; |
| 3696 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3697 | |
| 3698 | // Build updates and final values of the loop counters. |
| 3699 | bool HasErrors = false; |
| 3700 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3701 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3702 | Built.Updates.resize(NestedLoopCount); |
| 3703 | Built.Finals.resize(NestedLoopCount); |
| 3704 | { |
| 3705 | ExprResult Div; |
| 3706 | // Go from inner nested loop to outer. |
| 3707 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3708 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3709 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3710 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3711 | // where Div is product of previous iterations' IS.NumIters. |
| 3712 | ExprResult Iter; |
| 3713 | if (Div.isUsable()) { |
| 3714 | Iter = |
| 3715 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3716 | } else { |
| 3717 | Iter = IV; |
| 3718 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3719 | "unusable div expected on first iteration only"); |
| 3720 | } |
| 3721 | |
| 3722 | if (Cnt != 0 && Iter.isUsable()) |
| 3723 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3724 | IS.NumIterations); |
| 3725 | if (!Iter.isUsable()) { |
| 3726 | HasErrors = true; |
| 3727 | break; |
| 3728 | } |
| 3729 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3730 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3731 | auto *CounterVar = buildDeclRefExpr( |
| 3732 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3733 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3734 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3735 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3736 | IS.CounterInit); |
| 3737 | if (!Init.isUsable()) { |
| 3738 | HasErrors = true; |
| 3739 | break; |
| 3740 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3741 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3742 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3743 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3744 | if (!Update.isUsable()) { |
| 3745 | HasErrors = true; |
| 3746 | break; |
| 3747 | } |
| 3748 | |
| 3749 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3750 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3751 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3752 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3753 | if (!Final.isUsable()) { |
| 3754 | HasErrors = true; |
| 3755 | break; |
| 3756 | } |
| 3757 | |
| 3758 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3759 | if (Cnt != 0) { |
| 3760 | if (Div.isUnset()) |
| 3761 | Div = IS.NumIterations; |
| 3762 | else |
| 3763 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3764 | IS.NumIterations); |
| 3765 | |
| 3766 | // Add parentheses (for debugging purposes only). |
| 3767 | if (Div.isUsable()) |
| 3768 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3769 | if (!Div.isUsable()) { |
| 3770 | HasErrors = true; |
| 3771 | break; |
| 3772 | } |
| 3773 | } |
| 3774 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3775 | HasErrors = true; |
| 3776 | break; |
| 3777 | } |
| 3778 | // Save results |
| 3779 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3780 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3781 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3782 | Built.Updates[Cnt] = Update.get(); |
| 3783 | Built.Finals[Cnt] = Final.get(); |
| 3784 | } |
| 3785 | } |
| 3786 | |
| 3787 | if (HasErrors) |
| 3788 | return 0; |
| 3789 | |
| 3790 | // Save results |
| 3791 | Built.IterationVarRef = IV.get(); |
| 3792 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3793 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3794 | Built.CalcLastIteration = |
| 3795 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3796 | Built.PreCond = PreCond.get(); |
| 3797 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3798 | Built.Init = Init.get(); |
| 3799 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3800 | Built.LB = LB.get(); |
| 3801 | Built.UB = UB.get(); |
| 3802 | Built.IL = IL.get(); |
| 3803 | Built.ST = ST.get(); |
| 3804 | Built.EUB = EUB.get(); |
| 3805 | Built.NLB = NextLB.get(); |
| 3806 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3807 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3808 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3809 | } |
| 3810 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3811 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3812 | auto CollapseClauses = |
| 3813 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 3814 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 3815 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3816 | return nullptr; |
| 3817 | } |
| 3818 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3819 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3820 | auto OrderedClauses = |
| 3821 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 3822 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 3823 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3824 | return nullptr; |
| 3825 | } |
| 3826 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3827 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 3828 | const Expr *Safelen) { |
| 3829 | llvm::APSInt SimdlenRes, SafelenRes; |
| 3830 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 3831 | Simdlen->isInstantiationDependent() || |
| 3832 | Simdlen->containsUnexpandedParameterPack()) |
| 3833 | return false; |
| 3834 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 3835 | Safelen->isInstantiationDependent() || |
| 3836 | Safelen->containsUnexpandedParameterPack()) |
| 3837 | return false; |
| 3838 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 3839 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 3840 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3841 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3842 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3843 | if (SimdlenRes > SafelenRes) { |
| 3844 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 3845 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 3846 | return true; |
| 3847 | } |
| 3848 | return false; |
| 3849 | } |
| 3850 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3851 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3852 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3853 | SourceLocation EndLoc, |
| 3854 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3855 | if (!AStmt) |
| 3856 | return StmtError(); |
| 3857 | |
| 3858 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3859 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3860 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3861 | // define the nested loops number. |
| 3862 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3863 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3864 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3865 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3866 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3867 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3868 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3869 | "omp simd loop exprs were not built"); |
| 3870 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3871 | if (!CurContext->isDependentContext()) { |
| 3872 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3873 | for (auto C : Clauses) { |
| 3874 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3875 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3876 | B.NumIterations, *this, CurScope)) |
| 3877 | return StmtError(); |
| 3878 | } |
| 3879 | } |
| 3880 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3881 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3882 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3883 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3884 | OMPSafelenClause *Safelen = nullptr; |
| 3885 | OMPSimdlenClause *Simdlen = nullptr; |
| 3886 | for (auto *Clause : Clauses) { |
| 3887 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3888 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3889 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3890 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3891 | if (Safelen && Simdlen) |
| 3892 | break; |
| 3893 | } |
| 3894 | if (Simdlen && Safelen && |
| 3895 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3896 | Safelen->getSafelen())) |
| 3897 | return StmtError(); |
| 3898 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3899 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3900 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3901 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3904 | StmtResult Sema::ActOnOpenMPForDirective( |
| 3905 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3906 | SourceLocation EndLoc, |
| 3907 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3908 | if (!AStmt) |
| 3909 | return StmtError(); |
| 3910 | |
| 3911 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3912 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3913 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3914 | // define the nested loops number. |
| 3915 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3916 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3917 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3918 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3919 | return StmtError(); |
| 3920 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3921 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3922 | "omp for loop exprs were not built"); |
| 3923 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 3924 | if (!CurContext->isDependentContext()) { |
| 3925 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3926 | for (auto C : Clauses) { |
| 3927 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3928 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3929 | B.NumIterations, *this, CurScope)) |
| 3930 | return StmtError(); |
| 3931 | } |
| 3932 | } |
| 3933 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3934 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3935 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3936 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3937 | } |
| 3938 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3939 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 3940 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3941 | SourceLocation EndLoc, |
| 3942 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3943 | if (!AStmt) |
| 3944 | return StmtError(); |
| 3945 | |
| 3946 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3947 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3948 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3949 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3950 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3951 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 3952 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3953 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3954 | if (NestedLoopCount == 0) |
| 3955 | return StmtError(); |
| 3956 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3957 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3958 | "omp for simd loop exprs were not built"); |
| 3959 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 3960 | if (!CurContext->isDependentContext()) { |
| 3961 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3962 | for (auto C : Clauses) { |
| 3963 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3964 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3965 | B.NumIterations, *this, CurScope)) |
| 3966 | return StmtError(); |
| 3967 | } |
| 3968 | } |
| 3969 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3970 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3971 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3972 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3973 | OMPSafelenClause *Safelen = nullptr; |
| 3974 | OMPSimdlenClause *Simdlen = nullptr; |
| 3975 | for (auto *Clause : Clauses) { |
| 3976 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3977 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3978 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3979 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3980 | if (Safelen && Simdlen) |
| 3981 | break; |
| 3982 | } |
| 3983 | if (Simdlen && Safelen && |
| 3984 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3985 | Safelen->getSafelen())) |
| 3986 | return StmtError(); |
| 3987 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3988 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3989 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3990 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3991 | } |
| 3992 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3993 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3994 | Stmt *AStmt, |
| 3995 | SourceLocation StartLoc, |
| 3996 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3997 | if (!AStmt) |
| 3998 | return StmtError(); |
| 3999 | |
| 4000 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4001 | auto BaseStmt = AStmt; |
| 4002 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4003 | BaseStmt = CS->getCapturedStmt(); |
| 4004 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4005 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4006 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4007 | return StmtError(); |
| 4008 | // All associated statements must be '#pragma omp section' except for |
| 4009 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4010 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4011 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4012 | if (SectionStmt) |
| 4013 | Diag(SectionStmt->getLocStart(), |
| 4014 | diag::err_omp_sections_substmt_not_section); |
| 4015 | return StmtError(); |
| 4016 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4017 | cast<OMPSectionDirective>(SectionStmt) |
| 4018 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4019 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4020 | } else { |
| 4021 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4022 | return StmtError(); |
| 4023 | } |
| 4024 | |
| 4025 | getCurFunction()->setHasBranchProtectedScope(); |
| 4026 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4027 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4028 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4031 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4032 | SourceLocation StartLoc, |
| 4033 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4034 | if (!AStmt) |
| 4035 | return StmtError(); |
| 4036 | |
| 4037 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4038 | |
| 4039 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4040 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4041 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4042 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4043 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4044 | } |
| 4045 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4046 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4047 | Stmt *AStmt, |
| 4048 | SourceLocation StartLoc, |
| 4049 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4050 | if (!AStmt) |
| 4051 | return StmtError(); |
| 4052 | |
| 4053 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4054 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4055 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4056 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4057 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4058 | // The copyprivate clause must not be used with the nowait clause. |
| 4059 | OMPClause *Nowait = nullptr; |
| 4060 | OMPClause *Copyprivate = nullptr; |
| 4061 | for (auto *Clause : Clauses) { |
| 4062 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4063 | Nowait = Clause; |
| 4064 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4065 | Copyprivate = Clause; |
| 4066 | if (Copyprivate && Nowait) { |
| 4067 | Diag(Copyprivate->getLocStart(), |
| 4068 | diag::err_omp_single_copyprivate_with_nowait); |
| 4069 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4070 | return StmtError(); |
| 4071 | } |
| 4072 | } |
| 4073 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4074 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4075 | } |
| 4076 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4077 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4078 | SourceLocation StartLoc, |
| 4079 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4080 | if (!AStmt) |
| 4081 | return StmtError(); |
| 4082 | |
| 4083 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4084 | |
| 4085 | getCurFunction()->setHasBranchProtectedScope(); |
| 4086 | |
| 4087 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4088 | } |
| 4089 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4090 | StmtResult |
| 4091 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 4092 | Stmt *AStmt, SourceLocation StartLoc, |
| 4093 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4094 | if (!AStmt) |
| 4095 | return StmtError(); |
| 4096 | |
| 4097 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4098 | |
| 4099 | getCurFunction()->setHasBranchProtectedScope(); |
| 4100 | |
| 4101 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4102 | AStmt); |
| 4103 | } |
| 4104 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4105 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4106 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4107 | SourceLocation EndLoc, |
| 4108 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4109 | if (!AStmt) |
| 4110 | return StmtError(); |
| 4111 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4112 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4113 | // 1.2.2 OpenMP Language Terminology |
| 4114 | // Structured block - An executable statement with a single entry at the |
| 4115 | // top and a single exit at the bottom. |
| 4116 | // The point of exit cannot be a branch out of the structured block. |
| 4117 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4118 | CS->getCapturedDecl()->setNothrow(); |
| 4119 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4120 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4121 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4122 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4123 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4124 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4125 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4126 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4127 | if (NestedLoopCount == 0) |
| 4128 | return StmtError(); |
| 4129 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4130 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4131 | "omp parallel for loop exprs were not built"); |
| 4132 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4133 | if (!CurContext->isDependentContext()) { |
| 4134 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4135 | for (auto C : Clauses) { |
| 4136 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4137 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4138 | B.NumIterations, *this, CurScope)) |
| 4139 | return StmtError(); |
| 4140 | } |
| 4141 | } |
| 4142 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4143 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4144 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4145 | NestedLoopCount, Clauses, AStmt, B, |
| 4146 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4149 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4150 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4151 | SourceLocation EndLoc, |
| 4152 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4153 | if (!AStmt) |
| 4154 | return StmtError(); |
| 4155 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4156 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4157 | // 1.2.2 OpenMP Language Terminology |
| 4158 | // Structured block - An executable statement with a single entry at the |
| 4159 | // top and a single exit at the bottom. |
| 4160 | // The point of exit cannot be a branch out of the structured block. |
| 4161 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4162 | CS->getCapturedDecl()->setNothrow(); |
| 4163 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4164 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4165 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4166 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4167 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4168 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4169 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4170 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4171 | if (NestedLoopCount == 0) |
| 4172 | return StmtError(); |
| 4173 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4174 | if (!CurContext->isDependentContext()) { |
| 4175 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4176 | for (auto C : Clauses) { |
| 4177 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4178 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4179 | B.NumIterations, *this, CurScope)) |
| 4180 | return StmtError(); |
| 4181 | } |
| 4182 | } |
| 4183 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4184 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4185 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4186 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4187 | OMPSafelenClause *Safelen = nullptr; |
| 4188 | OMPSimdlenClause *Simdlen = nullptr; |
| 4189 | for (auto *Clause : Clauses) { |
| 4190 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4191 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4192 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4193 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4194 | if (Safelen && Simdlen) |
| 4195 | break; |
| 4196 | } |
| 4197 | if (Simdlen && Safelen && |
| 4198 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4199 | Safelen->getSafelen())) |
| 4200 | return StmtError(); |
| 4201 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4202 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4203 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4204 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4207 | StmtResult |
| 4208 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4209 | Stmt *AStmt, SourceLocation StartLoc, |
| 4210 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4211 | if (!AStmt) |
| 4212 | return StmtError(); |
| 4213 | |
| 4214 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4215 | auto BaseStmt = AStmt; |
| 4216 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4217 | BaseStmt = CS->getCapturedStmt(); |
| 4218 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4219 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4220 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4221 | return StmtError(); |
| 4222 | // All associated statements must be '#pragma omp section' except for |
| 4223 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4224 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4225 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4226 | if (SectionStmt) |
| 4227 | Diag(SectionStmt->getLocStart(), |
| 4228 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4229 | return StmtError(); |
| 4230 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4231 | cast<OMPSectionDirective>(SectionStmt) |
| 4232 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4233 | } |
| 4234 | } else { |
| 4235 | Diag(AStmt->getLocStart(), |
| 4236 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4237 | return StmtError(); |
| 4238 | } |
| 4239 | |
| 4240 | getCurFunction()->setHasBranchProtectedScope(); |
| 4241 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4242 | return OMPParallelSectionsDirective::Create( |
| 4243 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4246 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4247 | Stmt *AStmt, SourceLocation StartLoc, |
| 4248 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4249 | if (!AStmt) |
| 4250 | return StmtError(); |
| 4251 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4252 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4253 | // 1.2.2 OpenMP Language Terminology |
| 4254 | // Structured block - An executable statement with a single entry at the |
| 4255 | // top and a single exit at the bottom. |
| 4256 | // The point of exit cannot be a branch out of the structured block. |
| 4257 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4258 | CS->getCapturedDecl()->setNothrow(); |
| 4259 | |
| 4260 | getCurFunction()->setHasBranchProtectedScope(); |
| 4261 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4262 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4263 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4264 | } |
| 4265 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4266 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4267 | SourceLocation EndLoc) { |
| 4268 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4269 | } |
| 4270 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4271 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4272 | SourceLocation EndLoc) { |
| 4273 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4274 | } |
| 4275 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4276 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4277 | SourceLocation EndLoc) { |
| 4278 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4279 | } |
| 4280 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4281 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4282 | SourceLocation StartLoc, |
| 4283 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4284 | if (!AStmt) |
| 4285 | return StmtError(); |
| 4286 | |
| 4287 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4288 | |
| 4289 | getCurFunction()->setHasBranchProtectedScope(); |
| 4290 | |
| 4291 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4292 | } |
| 4293 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4294 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4295 | SourceLocation StartLoc, |
| 4296 | SourceLocation EndLoc) { |
| 4297 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4298 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4299 | } |
| 4300 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4301 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4302 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4303 | SourceLocation StartLoc, |
| 4304 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4305 | if (!AStmt) |
| 4306 | return StmtError(); |
| 4307 | |
| 4308 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4309 | |
| 4310 | getCurFunction()->setHasBranchProtectedScope(); |
| 4311 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4312 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4313 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4314 | for (auto *C: Clauses) { |
| 4315 | if (C->getClauseKind() == OMPC_threads) |
| 4316 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4317 | else if (C->getClauseKind() == OMPC_simd) |
| 4318 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4319 | } |
| 4320 | |
| 4321 | // TODO: this must happen only if 'threads' clause specified or if no clauses |
| 4322 | // is specified. |
| 4323 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4324 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4325 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) << (TC != nullptr); |
| 4326 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4327 | return StmtError(); |
| 4328 | } |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4329 | if (!SC && isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
| 4330 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4331 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4332 | // that can appear in the simd region. |
| 4333 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 4334 | return StmtError(); |
| 4335 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4336 | |
| 4337 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4338 | } |
| 4339 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4340 | namespace { |
| 4341 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4342 | /// construct. |
| 4343 | class OpenMPAtomicUpdateChecker { |
| 4344 | /// \brief Error results for atomic update expressions. |
| 4345 | enum ExprAnalysisErrorCode { |
| 4346 | /// \brief A statement is not an expression statement. |
| 4347 | NotAnExpression, |
| 4348 | /// \brief Expression is not builtin binary or unary operation. |
| 4349 | NotABinaryOrUnaryExpression, |
| 4350 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4351 | NotAnUnaryIncDecExpression, |
| 4352 | /// \brief An expression is not of scalar type. |
| 4353 | NotAScalarType, |
| 4354 | /// \brief A binary operation is not an assignment operation. |
| 4355 | NotAnAssignmentOp, |
| 4356 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4357 | NotABinaryExpression, |
| 4358 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4359 | /// expression. |
| 4360 | NotABinaryOperator, |
| 4361 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4362 | /// part. |
| 4363 | NotAnUpdateExpression, |
| 4364 | /// \brief No errors is found. |
| 4365 | NoError |
| 4366 | }; |
| 4367 | /// \brief Reference to Sema. |
| 4368 | Sema &SemaRef; |
| 4369 | /// \brief A location for note diagnostics (when error is found). |
| 4370 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4371 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4372 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4373 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4374 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4375 | /// \brief Helper expression of the form |
| 4376 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4377 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4378 | Expr *UpdateExpr; |
| 4379 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4380 | /// important for non-associative operations. |
| 4381 | bool IsXLHSInRHSPart; |
| 4382 | BinaryOperatorKind Op; |
| 4383 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4384 | /// \brief true if the source expression is a postfix unary operation, false |
| 4385 | /// if it is a prefix unary operation. |
| 4386 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4387 | |
| 4388 | public: |
| 4389 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4390 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4391 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4392 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4393 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4394 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4395 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4396 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4397 | /// \param NoteId Diagnostic note for the main error message. |
| 4398 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4399 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4400 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4401 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4402 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4403 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4404 | /// \brief Return the update expression used in calculation of the updated |
| 4405 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4406 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4407 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4408 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4409 | /// false otherwise. |
| 4410 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4411 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4412 | /// \brief true if the source expression is a postfix unary operation, false |
| 4413 | /// if it is a prefix unary operation. |
| 4414 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4415 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4416 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4417 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4418 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4419 | }; |
| 4420 | } // namespace |
| 4421 | |
| 4422 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4423 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4424 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4425 | SourceLocation ErrorLoc, NoteLoc; |
| 4426 | SourceRange ErrorRange, NoteRange; |
| 4427 | // Allowed constructs are: |
| 4428 | // x = x binop expr; |
| 4429 | // x = expr binop x; |
| 4430 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4431 | X = AtomicBinOp->getLHS(); |
| 4432 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4433 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4434 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4435 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4436 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4437 | Op = AtomicInnerBinOp->getOpcode(); |
| 4438 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4439 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4440 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4441 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4442 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4443 | /*Canonical=*/true); |
| 4444 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4445 | /*Canonical=*/true); |
| 4446 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4447 | /*Canonical=*/true); |
| 4448 | if (XId == LHSId) { |
| 4449 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4450 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4451 | } else if (XId == RHSId) { |
| 4452 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4453 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4454 | } else { |
| 4455 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4456 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4457 | NoteLoc = X->getExprLoc(); |
| 4458 | NoteRange = X->getSourceRange(); |
| 4459 | ErrorFound = NotAnUpdateExpression; |
| 4460 | } |
| 4461 | } else { |
| 4462 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4463 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4464 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4465 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4466 | ErrorFound = NotABinaryOperator; |
| 4467 | } |
| 4468 | } else { |
| 4469 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4470 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4471 | ErrorFound = NotABinaryExpression; |
| 4472 | } |
| 4473 | } else { |
| 4474 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4475 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4476 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4477 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4478 | ErrorFound = NotAnAssignmentOp; |
| 4479 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4480 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4481 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4482 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4483 | return true; |
| 4484 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4485 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4486 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4490 | unsigned NoteId) { |
| 4491 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4492 | SourceLocation ErrorLoc, NoteLoc; |
| 4493 | SourceRange ErrorRange, NoteRange; |
| 4494 | // Allowed constructs are: |
| 4495 | // x++; |
| 4496 | // x--; |
| 4497 | // ++x; |
| 4498 | // --x; |
| 4499 | // x binop= expr; |
| 4500 | // x = x binop expr; |
| 4501 | // x = expr binop x; |
| 4502 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4503 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4504 | if (AtomicBody->getType()->isScalarType() || |
| 4505 | AtomicBody->isInstantiationDependent()) { |
| 4506 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4507 | AtomicBody->IgnoreParenImpCasts())) { |
| 4508 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4509 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4510 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4511 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4512 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4513 | X = AtomicCompAssignOp->getLHS(); |
| 4514 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4515 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4516 | AtomicBody->IgnoreParenImpCasts())) { |
| 4517 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4518 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4519 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4520 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4521 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4522 | // Check for Unary Operation |
| 4523 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4524 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4525 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4526 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4527 | X = AtomicUnaryOp->getSubExpr(); |
| 4528 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4529 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4530 | } else { |
| 4531 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4532 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4533 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4534 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4535 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4536 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4537 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4538 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4539 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4540 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4541 | } |
| 4542 | } else { |
| 4543 | ErrorFound = NotAScalarType; |
| 4544 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4545 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4546 | } |
| 4547 | } else { |
| 4548 | ErrorFound = NotAnExpression; |
| 4549 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4550 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4551 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4552 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4553 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4554 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4555 | return true; |
| 4556 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4557 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4558 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4559 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4560 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4561 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4562 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4563 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4564 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4565 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4566 | auto Update = |
| 4567 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4568 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4569 | if (Update.isInvalid()) |
| 4570 | return true; |
| 4571 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4572 | Sema::AA_Casting); |
| 4573 | if (Update.isInvalid()) |
| 4574 | return true; |
| 4575 | UpdateExpr = Update.get(); |
| 4576 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4577 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4578 | } |
| 4579 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4580 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4581 | Stmt *AStmt, |
| 4582 | SourceLocation StartLoc, |
| 4583 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4584 | if (!AStmt) |
| 4585 | return StmtError(); |
| 4586 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4587 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4588 | // 1.2.2 OpenMP Language Terminology |
| 4589 | // Structured block - An executable statement with a single entry at the |
| 4590 | // top and a single exit at the bottom. |
| 4591 | // The point of exit cannot be a branch out of the structured block. |
| 4592 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4593 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4594 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4595 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4596 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4597 | C->getClauseKind() == OMPC_update || |
| 4598 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4599 | if (AtomicKind != OMPC_unknown) { |
| 4600 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4601 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4602 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4603 | << getOpenMPClauseName(AtomicKind); |
| 4604 | } else { |
| 4605 | AtomicKind = C->getClauseKind(); |
| 4606 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4607 | } |
| 4608 | } |
| 4609 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4610 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4611 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4612 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4613 | Body = EWC->getSubExpr(); |
| 4614 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4615 | Expr *X = nullptr; |
| 4616 | Expr *V = nullptr; |
| 4617 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4618 | Expr *UE = nullptr; |
| 4619 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4620 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4621 | // OpenMP [2.12.6, atomic Construct] |
| 4622 | // In the next expressions: |
| 4623 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4624 | // * During the execution of an atomic region, multiple syntactic |
| 4625 | // occurrences of x must designate the same storage location. |
| 4626 | // * Neither of v and expr (as applicable) may access the storage location |
| 4627 | // designated by x. |
| 4628 | // * Neither of x and expr (as applicable) may access the storage location |
| 4629 | // designated by v. |
| 4630 | // * expr is an expression with scalar type. |
| 4631 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4632 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4633 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4634 | // (expr). This requirement is satisfied if the operators in expr have |
| 4635 | // precedence greater than binop, or by using parentheses around expr or |
| 4636 | // subexpressions of expr. |
| 4637 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4638 | // binop x. This requirement is satisfied if the operators in expr have |
| 4639 | // precedence equal to or greater than binop, or by using parentheses around |
| 4640 | // expr or subexpressions of expr. |
| 4641 | // * For forms that allow multiple occurrences of x, the number of times |
| 4642 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4643 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4644 | enum { |
| 4645 | NotAnExpression, |
| 4646 | NotAnAssignmentOp, |
| 4647 | NotAScalarType, |
| 4648 | NotAnLValue, |
| 4649 | NoError |
| 4650 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4651 | SourceLocation ErrorLoc, NoteLoc; |
| 4652 | SourceRange ErrorRange, NoteRange; |
| 4653 | // If clause is read: |
| 4654 | // v = x; |
| 4655 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4656 | auto AtomicBinOp = |
| 4657 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4658 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4659 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4660 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4661 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4662 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4663 | if (!X->isLValue() || !V->isLValue()) { |
| 4664 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4665 | ErrorFound = NotAnLValue; |
| 4666 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4667 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4668 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4669 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4670 | } |
| 4671 | } else if (!X->isInstantiationDependent() || |
| 4672 | !V->isInstantiationDependent()) { |
| 4673 | auto NotScalarExpr = |
| 4674 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4675 | ? V |
| 4676 | : X; |
| 4677 | ErrorFound = NotAScalarType; |
| 4678 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4679 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4680 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4681 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4682 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4683 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4684 | ErrorFound = NotAnAssignmentOp; |
| 4685 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4686 | ErrorRange = AtomicBody->getSourceRange(); |
| 4687 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4688 | : AtomicBody->getExprLoc(); |
| 4689 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4690 | : AtomicBody->getSourceRange(); |
| 4691 | } |
| 4692 | } else { |
| 4693 | ErrorFound = NotAnExpression; |
| 4694 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4695 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4696 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4697 | if (ErrorFound != NoError) { |
| 4698 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4699 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4700 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4701 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4702 | return StmtError(); |
| 4703 | } else if (CurContext->isDependentContext()) |
| 4704 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4705 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4706 | enum { |
| 4707 | NotAnExpression, |
| 4708 | NotAnAssignmentOp, |
| 4709 | NotAScalarType, |
| 4710 | NotAnLValue, |
| 4711 | NoError |
| 4712 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4713 | SourceLocation ErrorLoc, NoteLoc; |
| 4714 | SourceRange ErrorRange, NoteRange; |
| 4715 | // If clause is write: |
| 4716 | // x = expr; |
| 4717 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4718 | auto AtomicBinOp = |
| 4719 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4720 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4721 | X = AtomicBinOp->getLHS(); |
| 4722 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4723 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4724 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4725 | if (!X->isLValue()) { |
| 4726 | ErrorFound = NotAnLValue; |
| 4727 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4728 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4729 | NoteLoc = X->getExprLoc(); |
| 4730 | NoteRange = X->getSourceRange(); |
| 4731 | } |
| 4732 | } else if (!X->isInstantiationDependent() || |
| 4733 | !E->isInstantiationDependent()) { |
| 4734 | auto NotScalarExpr = |
| 4735 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4736 | ? E |
| 4737 | : X; |
| 4738 | ErrorFound = NotAScalarType; |
| 4739 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4740 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4741 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4742 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4743 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4744 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4745 | ErrorFound = NotAnAssignmentOp; |
| 4746 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4747 | ErrorRange = AtomicBody->getSourceRange(); |
| 4748 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4749 | : AtomicBody->getExprLoc(); |
| 4750 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4751 | : AtomicBody->getSourceRange(); |
| 4752 | } |
| 4753 | } else { |
| 4754 | ErrorFound = NotAnExpression; |
| 4755 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4756 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4757 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4758 | if (ErrorFound != NoError) { |
| 4759 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4760 | << ErrorRange; |
| 4761 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4762 | << NoteRange; |
| 4763 | return StmtError(); |
| 4764 | } else if (CurContext->isDependentContext()) |
| 4765 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4766 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4767 | // If clause is update: |
| 4768 | // x++; |
| 4769 | // x--; |
| 4770 | // ++x; |
| 4771 | // --x; |
| 4772 | // x binop= expr; |
| 4773 | // x = x binop expr; |
| 4774 | // x = expr binop x; |
| 4775 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4776 | if (Checker.checkStatement( |
| 4777 | Body, (AtomicKind == OMPC_update) |
| 4778 | ? diag::err_omp_atomic_update_not_expression_statement |
| 4779 | : diag::err_omp_atomic_not_expression_statement, |
| 4780 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4781 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4782 | if (!CurContext->isDependentContext()) { |
| 4783 | E = Checker.getExpr(); |
| 4784 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4785 | UE = Checker.getUpdateExpr(); |
| 4786 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4787 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4788 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4789 | enum { |
| 4790 | NotAnAssignmentOp, |
| 4791 | NotACompoundStatement, |
| 4792 | NotTwoSubstatements, |
| 4793 | NotASpecificExpression, |
| 4794 | NoError |
| 4795 | } ErrorFound = NoError; |
| 4796 | SourceLocation ErrorLoc, NoteLoc; |
| 4797 | SourceRange ErrorRange, NoteRange; |
| 4798 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 4799 | // If clause is a capture: |
| 4800 | // v = x++; |
| 4801 | // v = x--; |
| 4802 | // v = ++x; |
| 4803 | // v = --x; |
| 4804 | // v = x binop= expr; |
| 4805 | // v = x = x binop expr; |
| 4806 | // v = x = expr binop x; |
| 4807 | auto *AtomicBinOp = |
| 4808 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4809 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4810 | V = AtomicBinOp->getLHS(); |
| 4811 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4812 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4813 | if (Checker.checkStatement( |
| 4814 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 4815 | diag::note_omp_atomic_update)) |
| 4816 | return StmtError(); |
| 4817 | E = Checker.getExpr(); |
| 4818 | X = Checker.getX(); |
| 4819 | UE = Checker.getUpdateExpr(); |
| 4820 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 4821 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4822 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4823 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4824 | ErrorRange = AtomicBody->getSourceRange(); |
| 4825 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4826 | : AtomicBody->getExprLoc(); |
| 4827 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4828 | : AtomicBody->getSourceRange(); |
| 4829 | ErrorFound = NotAnAssignmentOp; |
| 4830 | } |
| 4831 | if (ErrorFound != NoError) { |
| 4832 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 4833 | << ErrorRange; |
| 4834 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4835 | return StmtError(); |
| 4836 | } else if (CurContext->isDependentContext()) { |
| 4837 | UE = V = E = X = nullptr; |
| 4838 | } |
| 4839 | } else { |
| 4840 | // If clause is a capture: |
| 4841 | // { v = x; x = expr; } |
| 4842 | // { v = x; x++; } |
| 4843 | // { v = x; x--; } |
| 4844 | // { v = x; ++x; } |
| 4845 | // { v = x; --x; } |
| 4846 | // { v = x; x binop= expr; } |
| 4847 | // { v = x; x = x binop expr; } |
| 4848 | // { v = x; x = expr binop x; } |
| 4849 | // { x++; v = x; } |
| 4850 | // { x--; v = x; } |
| 4851 | // { ++x; v = x; } |
| 4852 | // { --x; v = x; } |
| 4853 | // { x binop= expr; v = x; } |
| 4854 | // { x = x binop expr; v = x; } |
| 4855 | // { x = expr binop x; v = x; } |
| 4856 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 4857 | // Check that this is { expr1; expr2; } |
| 4858 | if (CS->size() == 2) { |
| 4859 | auto *First = CS->body_front(); |
| 4860 | auto *Second = CS->body_back(); |
| 4861 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 4862 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4863 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 4864 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4865 | // Need to find what subexpression is 'v' and what is 'x'. |
| 4866 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4867 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 4868 | BinaryOperator *BinOp = nullptr; |
| 4869 | if (IsUpdateExprFound) { |
| 4870 | BinOp = dyn_cast<BinaryOperator>(First); |
| 4871 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4872 | } |
| 4873 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4874 | // { v = x; x++; } |
| 4875 | // { v = x; x--; } |
| 4876 | // { v = x; ++x; } |
| 4877 | // { v = x; --x; } |
| 4878 | // { v = x; x binop= expr; } |
| 4879 | // { v = x; x = x binop expr; } |
| 4880 | // { v = x; x = expr binop x; } |
| 4881 | // Check that the first expression has form v = x. |
| 4882 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4883 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4884 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4885 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4886 | IsUpdateExprFound = XId == PossibleXId; |
| 4887 | if (IsUpdateExprFound) { |
| 4888 | V = BinOp->getLHS(); |
| 4889 | X = Checker.getX(); |
| 4890 | E = Checker.getExpr(); |
| 4891 | UE = Checker.getUpdateExpr(); |
| 4892 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4893 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4894 | } |
| 4895 | } |
| 4896 | if (!IsUpdateExprFound) { |
| 4897 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 4898 | BinOp = nullptr; |
| 4899 | if (IsUpdateExprFound) { |
| 4900 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 4901 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4902 | } |
| 4903 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4904 | // { x++; v = x; } |
| 4905 | // { x--; v = x; } |
| 4906 | // { ++x; v = x; } |
| 4907 | // { --x; v = x; } |
| 4908 | // { x binop= expr; v = x; } |
| 4909 | // { x = x binop expr; v = x; } |
| 4910 | // { x = expr binop x; v = x; } |
| 4911 | // Check that the second expression has form v = x. |
| 4912 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4913 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4914 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4915 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4916 | IsUpdateExprFound = XId == PossibleXId; |
| 4917 | if (IsUpdateExprFound) { |
| 4918 | V = BinOp->getLHS(); |
| 4919 | X = Checker.getX(); |
| 4920 | E = Checker.getExpr(); |
| 4921 | UE = Checker.getUpdateExpr(); |
| 4922 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4923 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4924 | } |
| 4925 | } |
| 4926 | } |
| 4927 | if (!IsUpdateExprFound) { |
| 4928 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4929 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 4930 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 4931 | if (!FirstExpr || !SecondExpr || |
| 4932 | !(FirstExpr->isInstantiationDependent() || |
| 4933 | SecondExpr->isInstantiationDependent())) { |
| 4934 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 4935 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4936 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4937 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 4938 | : First->getLocStart(); |
| 4939 | NoteRange = ErrorRange = FirstBinOp |
| 4940 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4941 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4942 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4943 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 4944 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 4945 | ErrorFound = NotAnAssignmentOp; |
| 4946 | NoteLoc = ErrorLoc = SecondBinOp |
| 4947 | ? SecondBinOp->getOperatorLoc() |
| 4948 | : Second->getLocStart(); |
| 4949 | NoteRange = ErrorRange = |
| 4950 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 4951 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4952 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4953 | auto *PossibleXRHSInFirst = |
| 4954 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4955 | auto *PossibleXLHSInSecond = |
| 4956 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4957 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 4958 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 4959 | /*Canonical=*/true); |
| 4960 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 4961 | /*Canonical=*/true); |
| 4962 | IsUpdateExprFound = X1Id == X2Id; |
| 4963 | if (IsUpdateExprFound) { |
| 4964 | V = FirstBinOp->getLHS(); |
| 4965 | X = SecondBinOp->getLHS(); |
| 4966 | E = SecondBinOp->getRHS(); |
| 4967 | UE = nullptr; |
| 4968 | IsXLHSInRHSPart = false; |
| 4969 | IsPostfixUpdate = true; |
| 4970 | } else { |
| 4971 | ErrorFound = NotASpecificExpression; |
| 4972 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 4973 | ErrorRange = FirstBinOp->getSourceRange(); |
| 4974 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 4975 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 4976 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4977 | } |
| 4978 | } |
| 4979 | } |
| 4980 | } |
| 4981 | } else { |
| 4982 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4983 | NoteRange = ErrorRange = |
| 4984 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4985 | ErrorFound = NotTwoSubstatements; |
| 4986 | } |
| 4987 | } else { |
| 4988 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4989 | NoteRange = ErrorRange = |
| 4990 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4991 | ErrorFound = NotACompoundStatement; |
| 4992 | } |
| 4993 | if (ErrorFound != NoError) { |
| 4994 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 4995 | << ErrorRange; |
| 4996 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4997 | return StmtError(); |
| 4998 | } else if (CurContext->isDependentContext()) { |
| 4999 | UE = V = E = X = nullptr; |
| 5000 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5001 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5002 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5003 | |
| 5004 | getCurFunction()->setHasBranchProtectedScope(); |
| 5005 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5006 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5007 | X, V, E, UE, IsXLHSInRHSPart, |
| 5008 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5009 | } |
| 5010 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5011 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5012 | Stmt *AStmt, |
| 5013 | SourceLocation StartLoc, |
| 5014 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5015 | if (!AStmt) |
| 5016 | return StmtError(); |
| 5017 | |
| 5018 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5019 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5020 | // OpenMP [2.16, Nesting of Regions] |
| 5021 | // If specified, a teams construct must be contained within a target |
| 5022 | // construct. That target construct must contain no statements or directives |
| 5023 | // outside of the teams construct. |
| 5024 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5025 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5026 | bool OMPTeamsFound = true; |
| 5027 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5028 | auto I = CS->body_begin(); |
| 5029 | while (I != CS->body_end()) { |
| 5030 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5031 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5032 | OMPTeamsFound = false; |
| 5033 | break; |
| 5034 | } |
| 5035 | ++I; |
| 5036 | } |
| 5037 | assert(I != CS->body_end() && "Not found statement"); |
| 5038 | S = *I; |
| 5039 | } |
| 5040 | if (!OMPTeamsFound) { |
| 5041 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5042 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5043 | diag::note_omp_nested_teams_construct_here); |
| 5044 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5045 | << isa<OMPExecutableDirective>(S); |
| 5046 | return StmtError(); |
| 5047 | } |
| 5048 | } |
| 5049 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5050 | getCurFunction()->setHasBranchProtectedScope(); |
| 5051 | |
| 5052 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5053 | } |
| 5054 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5055 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5056 | Stmt *AStmt, |
| 5057 | SourceLocation StartLoc, |
| 5058 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5059 | if (!AStmt) |
| 5060 | return StmtError(); |
| 5061 | |
| 5062 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5063 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5064 | getCurFunction()->setHasBranchProtectedScope(); |
| 5065 | |
| 5066 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5067 | AStmt); |
| 5068 | } |
| 5069 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5070 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5071 | Stmt *AStmt, SourceLocation StartLoc, |
| 5072 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5073 | if (!AStmt) |
| 5074 | return StmtError(); |
| 5075 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5076 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5077 | // 1.2.2 OpenMP Language Terminology |
| 5078 | // Structured block - An executable statement with a single entry at the |
| 5079 | // top and a single exit at the bottom. |
| 5080 | // The point of exit cannot be a branch out of the structured block. |
| 5081 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5082 | CS->getCapturedDecl()->setNothrow(); |
| 5083 | |
| 5084 | getCurFunction()->setHasBranchProtectedScope(); |
| 5085 | |
| 5086 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5087 | } |
| 5088 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5089 | StmtResult |
| 5090 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5091 | SourceLocation EndLoc, |
| 5092 | OpenMPDirectiveKind CancelRegion) { |
| 5093 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5094 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5095 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5096 | << getOpenMPDirectiveName(CancelRegion); |
| 5097 | return StmtError(); |
| 5098 | } |
| 5099 | if (DSAStack->isParentNowaitRegion()) { |
| 5100 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5101 | return StmtError(); |
| 5102 | } |
| 5103 | if (DSAStack->isParentOrderedRegion()) { |
| 5104 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5105 | return StmtError(); |
| 5106 | } |
| 5107 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5108 | CancelRegion); |
| 5109 | } |
| 5110 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5111 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5112 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5113 | SourceLocation EndLoc, |
| 5114 | OpenMPDirectiveKind CancelRegion) { |
| 5115 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5116 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5117 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5118 | << getOpenMPDirectiveName(CancelRegion); |
| 5119 | return StmtError(); |
| 5120 | } |
| 5121 | if (DSAStack->isParentNowaitRegion()) { |
| 5122 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5123 | return StmtError(); |
| 5124 | } |
| 5125 | if (DSAStack->isParentOrderedRegion()) { |
| 5126 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5127 | return StmtError(); |
| 5128 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5129 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5130 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5131 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5132 | } |
| 5133 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame^] | 5134 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5135 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5136 | SourceLocation EndLoc, |
| 5137 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5138 | if (!AStmt) |
| 5139 | return StmtError(); |
| 5140 | |
| 5141 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5142 | OMPLoopDirective::HelperExprs B; |
| 5143 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5144 | // define the nested loops number. |
| 5145 | unsigned NestedLoopCount = |
| 5146 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
| 5147 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5148 | VarsWithImplicitDSA, B); |
| 5149 | if (NestedLoopCount == 0) |
| 5150 | return StmtError(); |
| 5151 | |
| 5152 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5153 | "omp for loop exprs were not built"); |
| 5154 | |
| 5155 | getCurFunction()->setHasBranchProtectedScope(); |
| 5156 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5157 | NestedLoopCount, Clauses, AStmt, B); |
| 5158 | } |
| 5159 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5160 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5161 | SourceLocation StartLoc, |
| 5162 | SourceLocation LParenLoc, |
| 5163 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5164 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5165 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5166 | case OMPC_final: |
| 5167 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5168 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5169 | case OMPC_num_threads: |
| 5170 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5171 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5172 | case OMPC_safelen: |
| 5173 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5174 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5175 | case OMPC_simdlen: |
| 5176 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5177 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5178 | case OMPC_collapse: |
| 5179 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5180 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5181 | case OMPC_ordered: |
| 5182 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5183 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5184 | case OMPC_device: |
| 5185 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5186 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5187 | case OMPC_num_teams: |
| 5188 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5189 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5190 | case OMPC_thread_limit: |
| 5191 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5192 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5193 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5194 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5195 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5196 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5197 | case OMPC_private: |
| 5198 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5199 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5200 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5201 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5202 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5203 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5204 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5205 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5206 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5207 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5208 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5209 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5210 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5211 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5212 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5213 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5214 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5215 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5216 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5217 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5218 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5219 | case OMPC_map: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5220 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5221 | llvm_unreachable("Clause is not allowed."); |
| 5222 | } |
| 5223 | return Res; |
| 5224 | } |
| 5225 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5226 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5227 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5228 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5229 | SourceLocation NameModifierLoc, |
| 5230 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5231 | SourceLocation EndLoc) { |
| 5232 | Expr *ValExpr = Condition; |
| 5233 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5234 | !Condition->isInstantiationDependent() && |
| 5235 | !Condition->containsUnexpandedParameterPack()) { |
| 5236 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5237 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5238 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5239 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5240 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5241 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5244 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5245 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5246 | } |
| 5247 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5248 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5249 | SourceLocation StartLoc, |
| 5250 | SourceLocation LParenLoc, |
| 5251 | SourceLocation EndLoc) { |
| 5252 | Expr *ValExpr = Condition; |
| 5253 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5254 | !Condition->isInstantiationDependent() && |
| 5255 | !Condition->containsUnexpandedParameterPack()) { |
| 5256 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5257 | Condition->getExprLoc(), Condition); |
| 5258 | if (Val.isInvalid()) |
| 5259 | return nullptr; |
| 5260 | |
| 5261 | ValExpr = Val.get(); |
| 5262 | } |
| 5263 | |
| 5264 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5265 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5266 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5267 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5268 | if (!Op) |
| 5269 | return ExprError(); |
| 5270 | |
| 5271 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5272 | public: |
| 5273 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5274 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5275 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5276 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5277 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5278 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5279 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5280 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5281 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5282 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5283 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5284 | QualType T, |
| 5285 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5286 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5287 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5288 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5289 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5290 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5291 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5292 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5293 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5294 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5295 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5296 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5297 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5298 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5299 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5300 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5301 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5302 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5303 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5304 | llvm_unreachable("conversion functions are permitted"); |
| 5305 | } |
| 5306 | } ConvertDiagnoser; |
| 5307 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5308 | } |
| 5309 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5310 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
| 5311 | OpenMPClauseKind CKind) { |
| 5312 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 5313 | !ValExpr->isInstantiationDependent()) { |
| 5314 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 5315 | ExprResult Value = |
| 5316 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 5317 | if (Value.isInvalid()) |
| 5318 | return false; |
| 5319 | |
| 5320 | ValExpr = Value.get(); |
| 5321 | // The expression must evaluate to a non-negative integer value. |
| 5322 | llvm::APSInt Result; |
| 5323 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
| 5324 | Result.isSigned() && !Result.isStrictlyPositive()) { |
| 5325 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
| 5326 | << getOpenMPClauseName(CKind) << ValExpr->getSourceRange(); |
| 5327 | return false; |
| 5328 | } |
| 5329 | } |
| 5330 | return true; |
| 5331 | } |
| 5332 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5333 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5334 | SourceLocation StartLoc, |
| 5335 | SourceLocation LParenLoc, |
| 5336 | SourceLocation EndLoc) { |
| 5337 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5338 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5339 | // OpenMP [2.5, Restrictions] |
| 5340 | // The num_threads expression must evaluate to a positive integer value. |
| 5341 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads)) |
| 5342 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5343 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5344 | return new (Context) |
| 5345 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5346 | } |
| 5347 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5348 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 5349 | OpenMPClauseKind CKind) { |
| 5350 | if (!E) |
| 5351 | return ExprError(); |
| 5352 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5353 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5354 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5355 | llvm::APSInt Result; |
| 5356 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5357 | if (ICE.isInvalid()) |
| 5358 | return ExprError(); |
| 5359 | if (!Result.isStrictlyPositive()) { |
| 5360 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 5361 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 5362 | return ExprError(); |
| 5363 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5364 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5365 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5366 | << E->getSourceRange(); |
| 5367 | return ExprError(); |
| 5368 | } |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5369 | if (CKind == OMPC_collapse) |
| 5370 | DSAStack->setCollapseNumber(Result.getExtValue()); |
| 5371 | else if (CKind == OMPC_ordered) |
| 5372 | DSAStack->setCollapseNumber(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5373 | return ICE; |
| 5374 | } |
| 5375 | |
| 5376 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5377 | SourceLocation LParenLoc, |
| 5378 | SourceLocation EndLoc) { |
| 5379 | // OpenMP [2.8.1, simd construct, Description] |
| 5380 | // The parameter of the safelen clause must be a constant |
| 5381 | // positive integer expression. |
| 5382 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5383 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5384 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5385 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5386 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5387 | } |
| 5388 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5389 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5390 | SourceLocation LParenLoc, |
| 5391 | SourceLocation EndLoc) { |
| 5392 | // OpenMP [2.8.1, simd construct, Description] |
| 5393 | // The parameter of the simdlen clause must be a constant |
| 5394 | // positive integer expression. |
| 5395 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5396 | if (Simdlen.isInvalid()) |
| 5397 | return nullptr; |
| 5398 | return new (Context) |
| 5399 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5400 | } |
| 5401 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5402 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5403 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5404 | SourceLocation LParenLoc, |
| 5405 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5406 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5407 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5408 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5409 | // The parameter of the collapse clause must be a constant |
| 5410 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5411 | ExprResult NumForLoopsResult = |
| 5412 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5413 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5414 | return nullptr; |
| 5415 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5416 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5417 | } |
| 5418 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5419 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5420 | SourceLocation EndLoc, |
| 5421 | SourceLocation LParenLoc, |
| 5422 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5423 | // OpenMP [2.7.1, loop construct, Description] |
| 5424 | // OpenMP [2.8.1, simd construct, Description] |
| 5425 | // OpenMP [2.9.6, distribute construct, Description] |
| 5426 | // The parameter of the ordered clause must be a constant |
| 5427 | // positive integer expression if any. |
| 5428 | if (NumForLoops && LParenLoc.isValid()) { |
| 5429 | ExprResult NumForLoopsResult = |
| 5430 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5431 | if (NumForLoopsResult.isInvalid()) |
| 5432 | return nullptr; |
| 5433 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5434 | } else |
| 5435 | NumForLoops = nullptr; |
| 5436 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5437 | return new (Context) |
| 5438 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5439 | } |
| 5440 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5441 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5442 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5443 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5444 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5445 | switch (Kind) { |
| 5446 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5447 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5448 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5449 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5450 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5451 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5452 | Res = ActOnOpenMPProcBindClause( |
| 5453 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5454 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5455 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5456 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5457 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5458 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5459 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5460 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5461 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5462 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5463 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5464 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5465 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5466 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5467 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5468 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5469 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5470 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5471 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5472 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5473 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5474 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5475 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5476 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5477 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5478 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5479 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5480 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5481 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5482 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5483 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5484 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5485 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5486 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5487 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5488 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5489 | case OMPC_thread_limit: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5490 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5491 | llvm_unreachable("Clause is not allowed."); |
| 5492 | } |
| 5493 | return Res; |
| 5494 | } |
| 5495 | |
| 5496 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 5497 | SourceLocation KindKwLoc, |
| 5498 | SourceLocation StartLoc, |
| 5499 | SourceLocation LParenLoc, |
| 5500 | SourceLocation EndLoc) { |
| 5501 | if (Kind == OMPC_DEFAULT_unknown) { |
| 5502 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5503 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 5504 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 5505 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5506 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5507 | Values += "'"; |
| 5508 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 5509 | Values += "'"; |
| 5510 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5511 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5512 | Values += " or "; |
| 5513 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5514 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5515 | break; |
| 5516 | default: |
| 5517 | Values += Sep; |
| 5518 | break; |
| 5519 | } |
| 5520 | } |
| 5521 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5522 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5523 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5524 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5525 | switch (Kind) { |
| 5526 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5527 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5528 | break; |
| 5529 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5530 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5531 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5532 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5533 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5534 | break; |
| 5535 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5536 | return new (Context) |
| 5537 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5538 | } |
| 5539 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5540 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5541 | SourceLocation KindKwLoc, |
| 5542 | SourceLocation StartLoc, |
| 5543 | SourceLocation LParenLoc, |
| 5544 | SourceLocation EndLoc) { |
| 5545 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5546 | std::string Values; |
| 5547 | std::string Sep(", "); |
| 5548 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 5549 | Values += "'"; |
| 5550 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 5551 | Values += "'"; |
| 5552 | switch (i) { |
| 5553 | case OMPC_PROC_BIND_unknown - 2: |
| 5554 | Values += " or "; |
| 5555 | break; |
| 5556 | case OMPC_PROC_BIND_unknown - 1: |
| 5557 | break; |
| 5558 | default: |
| 5559 | Values += Sep; |
| 5560 | break; |
| 5561 | } |
| 5562 | } |
| 5563 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5564 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5565 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5566 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5567 | return new (Context) |
| 5568 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5569 | } |
| 5570 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5571 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 5572 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 5573 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5574 | SourceLocation ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5575 | SourceLocation EndLoc) { |
| 5576 | OMPClause *Res = nullptr; |
| 5577 | switch (Kind) { |
| 5578 | case OMPC_schedule: |
| 5579 | Res = ActOnOpenMPScheduleClause( |
| 5580 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5581 | LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5582 | break; |
| 5583 | case OMPC_if: |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5584 | Res = |
| 5585 | ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr, |
| 5586 | StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
| 5587 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5588 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5589 | case OMPC_num_threads: |
| 5590 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5591 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5592 | case OMPC_collapse: |
| 5593 | case OMPC_default: |
| 5594 | case OMPC_proc_bind: |
| 5595 | case OMPC_private: |
| 5596 | case OMPC_firstprivate: |
| 5597 | case OMPC_lastprivate: |
| 5598 | case OMPC_shared: |
| 5599 | case OMPC_reduction: |
| 5600 | case OMPC_linear: |
| 5601 | case OMPC_aligned: |
| 5602 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5603 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5604 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5605 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5606 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5607 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5608 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5609 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5610 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5611 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5612 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5613 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5614 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5615 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5616 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5617 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5618 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5619 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5620 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5621 | case OMPC_thread_limit: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5622 | case OMPC_unknown: |
| 5623 | llvm_unreachable("Clause is not allowed."); |
| 5624 | } |
| 5625 | return Res; |
| 5626 | } |
| 5627 | |
| 5628 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 5629 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 5630 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 5631 | SourceLocation EndLoc) { |
| 5632 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 5633 | std::string Values; |
| 5634 | std::string Sep(", "); |
| 5635 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 5636 | Values += "'"; |
| 5637 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 5638 | Values += "'"; |
| 5639 | switch (i) { |
| 5640 | case OMPC_SCHEDULE_unknown - 2: |
| 5641 | Values += " or "; |
| 5642 | break; |
| 5643 | case OMPC_SCHEDULE_unknown - 1: |
| 5644 | break; |
| 5645 | default: |
| 5646 | Values += Sep; |
| 5647 | break; |
| 5648 | } |
| 5649 | } |
| 5650 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 5651 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 5652 | return nullptr; |
| 5653 | } |
| 5654 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5655 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5656 | if (ChunkSize) { |
| 5657 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 5658 | !ChunkSize->isInstantiationDependent() && |
| 5659 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 5660 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 5661 | ExprResult Val = |
| 5662 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 5663 | if (Val.isInvalid()) |
| 5664 | return nullptr; |
| 5665 | |
| 5666 | ValExpr = Val.get(); |
| 5667 | |
| 5668 | // OpenMP [2.7.1, Restrictions] |
| 5669 | // chunk_size must be a loop invariant integer expression with a positive |
| 5670 | // value. |
| 5671 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5672 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 5673 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 5674 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 5675 | << "schedule" << ChunkSize->getSourceRange(); |
| 5676 | return nullptr; |
| 5677 | } |
| 5678 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 5679 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 5680 | ChunkSize->getType(), ".chunk."); |
| 5681 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 5682 | ChunkSize->getExprLoc(), |
| 5683 | /*RefersToCapture=*/true); |
| 5684 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5685 | } |
| 5686 | } |
| 5687 | } |
| 5688 | |
| 5689 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5690 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5691 | } |
| 5692 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5693 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 5694 | SourceLocation StartLoc, |
| 5695 | SourceLocation EndLoc) { |
| 5696 | OMPClause *Res = nullptr; |
| 5697 | switch (Kind) { |
| 5698 | case OMPC_ordered: |
| 5699 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 5700 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5701 | case OMPC_nowait: |
| 5702 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 5703 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5704 | case OMPC_untied: |
| 5705 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 5706 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5707 | case OMPC_mergeable: |
| 5708 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 5709 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5710 | case OMPC_read: |
| 5711 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 5712 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5713 | case OMPC_write: |
| 5714 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 5715 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5716 | case OMPC_update: |
| 5717 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 5718 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5719 | case OMPC_capture: |
| 5720 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 5721 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5722 | case OMPC_seq_cst: |
| 5723 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 5724 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5725 | case OMPC_threads: |
| 5726 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 5727 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5728 | case OMPC_simd: |
| 5729 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 5730 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5731 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5732 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5733 | case OMPC_num_threads: |
| 5734 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5735 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5736 | case OMPC_collapse: |
| 5737 | case OMPC_schedule: |
| 5738 | case OMPC_private: |
| 5739 | case OMPC_firstprivate: |
| 5740 | case OMPC_lastprivate: |
| 5741 | case OMPC_shared: |
| 5742 | case OMPC_reduction: |
| 5743 | case OMPC_linear: |
| 5744 | case OMPC_aligned: |
| 5745 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5746 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5747 | case OMPC_default: |
| 5748 | case OMPC_proc_bind: |
| 5749 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5750 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5751 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5752 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5753 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5754 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5755 | case OMPC_thread_limit: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5756 | case OMPC_unknown: |
| 5757 | llvm_unreachable("Clause is not allowed."); |
| 5758 | } |
| 5759 | return Res; |
| 5760 | } |
| 5761 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5762 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 5763 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5764 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5765 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 5766 | } |
| 5767 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5768 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 5769 | SourceLocation EndLoc) { |
| 5770 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 5771 | } |
| 5772 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5773 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 5774 | SourceLocation EndLoc) { |
| 5775 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 5776 | } |
| 5777 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5778 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 5779 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5780 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 5781 | } |
| 5782 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5783 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 5784 | SourceLocation EndLoc) { |
| 5785 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 5786 | } |
| 5787 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5788 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 5789 | SourceLocation EndLoc) { |
| 5790 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 5791 | } |
| 5792 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5793 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 5794 | SourceLocation EndLoc) { |
| 5795 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 5796 | } |
| 5797 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5798 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 5799 | SourceLocation EndLoc) { |
| 5800 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 5801 | } |
| 5802 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5803 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 5804 | SourceLocation EndLoc) { |
| 5805 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 5806 | } |
| 5807 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5808 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 5809 | SourceLocation EndLoc) { |
| 5810 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 5811 | } |
| 5812 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5813 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 5814 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 5815 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 5816 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5817 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5818 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 5819 | OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5820 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5821 | switch (Kind) { |
| 5822 | case OMPC_private: |
| 5823 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5824 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5825 | case OMPC_firstprivate: |
| 5826 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5827 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5828 | case OMPC_lastprivate: |
| 5829 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5830 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5831 | case OMPC_shared: |
| 5832 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5833 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5834 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5835 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 5836 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5837 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5838 | case OMPC_linear: |
| 5839 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5840 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5841 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5842 | case OMPC_aligned: |
| 5843 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 5844 | ColonLoc, EndLoc); |
| 5845 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5846 | case OMPC_copyin: |
| 5847 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5848 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5849 | case OMPC_copyprivate: |
| 5850 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5851 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5852 | case OMPC_flush: |
| 5853 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5854 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5855 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5856 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 5857 | StartLoc, LParenLoc, EndLoc); |
| 5858 | break; |
| 5859 | case OMPC_map: |
| 5860 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, DepLinMapLoc, ColonLoc, |
| 5861 | VarList, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5862 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5863 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5864 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5865 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5866 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5867 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5868 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5869 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5870 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5871 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5872 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5873 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5874 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5875 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5876 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5877 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5878 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5879 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5880 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5881 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5882 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5883 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5884 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5885 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5886 | case OMPC_thread_limit: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5887 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5888 | llvm_unreachable("Clause is not allowed."); |
| 5889 | } |
| 5890 | return Res; |
| 5891 | } |
| 5892 | |
| 5893 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 5894 | SourceLocation StartLoc, |
| 5895 | SourceLocation LParenLoc, |
| 5896 | SourceLocation EndLoc) { |
| 5897 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5898 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5899 | for (auto &RefExpr : VarList) { |
| 5900 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 5901 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5902 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5903 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5904 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5905 | continue; |
| 5906 | } |
| 5907 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5908 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5909 | // OpenMP [2.1, C/C++] |
| 5910 | // A list item is a variable name. |
| 5911 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5912 | // A variable that is part of another variable (as an array or |
| 5913 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5914 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5915 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5916 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5917 | continue; |
| 5918 | } |
| 5919 | Decl *D = DE->getDecl(); |
| 5920 | VarDecl *VD = cast<VarDecl>(D); |
| 5921 | |
| 5922 | QualType Type = VD->getType(); |
| 5923 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5924 | // It will be analyzed later. |
| 5925 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5926 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5927 | continue; |
| 5928 | } |
| 5929 | |
| 5930 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5931 | // A variable that appears in a private clause must not have an incomplete |
| 5932 | // type or a reference type. |
| 5933 | if (RequireCompleteType(ELoc, Type, |
| 5934 | diag::err_omp_private_incomplete_type)) { |
| 5935 | continue; |
| 5936 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5937 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5938 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5939 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5940 | // in a Construct] |
| 5941 | // Variables with the predetermined data-sharing attributes may not be |
| 5942 | // listed in data-sharing attributes clauses, except for the cases |
| 5943 | // listed below. For these exceptions only, listing a predetermined |
| 5944 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5945 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5946 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5947 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5948 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5949 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5950 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5951 | continue; |
| 5952 | } |
| 5953 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5954 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5955 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5956 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5957 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5958 | << getOpenMPClauseName(OMPC_private) << Type |
| 5959 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5960 | bool IsDecl = |
| 5961 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5962 | Diag(VD->getLocation(), |
| 5963 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5964 | << VD; |
| 5965 | continue; |
| 5966 | } |
| 5967 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5968 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 5969 | // A variable of class type (or array thereof) that appears in a private |
| 5970 | // clause requires an accessible, unambiguous default constructor for the |
| 5971 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5972 | // Generate helper private variable and initialize it with the default |
| 5973 | // value. The address of the original variable is replaced by the address of |
| 5974 | // the new private variable in CodeGen. This new variable is not added to |
| 5975 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 5976 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5977 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 5978 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 5979 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5980 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5981 | if (VDPrivate->isInvalidDecl()) |
| 5982 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5983 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5984 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5985 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5986 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5987 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5988 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5989 | } |
| 5990 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5991 | if (Vars.empty()) |
| 5992 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5993 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5994 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 5995 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5996 | } |
| 5997 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5998 | namespace { |
| 5999 | class DiagsUninitializedSeveretyRAII { |
| 6000 | private: |
| 6001 | DiagnosticsEngine &Diags; |
| 6002 | SourceLocation SavedLoc; |
| 6003 | bool IsIgnored; |
| 6004 | |
| 6005 | public: |
| 6006 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6007 | bool IsIgnored) |
| 6008 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6009 | if (!IsIgnored) { |
| 6010 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6011 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6012 | } |
| 6013 | } |
| 6014 | ~DiagsUninitializedSeveretyRAII() { |
| 6015 | if (!IsIgnored) |
| 6016 | Diags.popMappings(SavedLoc); |
| 6017 | } |
| 6018 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6019 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6020 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6021 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6022 | SourceLocation StartLoc, |
| 6023 | SourceLocation LParenLoc, |
| 6024 | SourceLocation EndLoc) { |
| 6025 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6026 | SmallVector<Expr *, 8> PrivateCopies; |
| 6027 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6028 | bool IsImplicitClause = |
| 6029 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6030 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6031 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6032 | for (auto &RefExpr : VarList) { |
| 6033 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6034 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6035 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6036 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6037 | PrivateCopies.push_back(nullptr); |
| 6038 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6039 | continue; |
| 6040 | } |
| 6041 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6042 | SourceLocation ELoc = |
| 6043 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6044 | // OpenMP [2.1, C/C++] |
| 6045 | // A list item is a variable name. |
| 6046 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6047 | // A variable that is part of another variable (as an array or |
| 6048 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6049 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6050 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6051 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6052 | continue; |
| 6053 | } |
| 6054 | Decl *D = DE->getDecl(); |
| 6055 | VarDecl *VD = cast<VarDecl>(D); |
| 6056 | |
| 6057 | QualType Type = VD->getType(); |
| 6058 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6059 | // It will be analyzed later. |
| 6060 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6061 | PrivateCopies.push_back(nullptr); |
| 6062 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6063 | continue; |
| 6064 | } |
| 6065 | |
| 6066 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6067 | // A variable that appears in a private clause must not have an incomplete |
| 6068 | // type or a reference type. |
| 6069 | if (RequireCompleteType(ELoc, Type, |
| 6070 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6071 | continue; |
| 6072 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6073 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6074 | |
| 6075 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6076 | // 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] | 6077 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6078 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6079 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6080 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6081 | // If an implicit firstprivate variable found it was checked already. |
| 6082 | if (!IsImplicitClause) { |
| 6083 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6084 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6085 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6086 | // A list item that specifies a given variable may not appear in more |
| 6087 | // than one clause on the same directive, except that a variable may be |
| 6088 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6089 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6090 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6091 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6092 | << getOpenMPClauseName(DVar.CKind) |
| 6093 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6094 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6095 | continue; |
| 6096 | } |
| 6097 | |
| 6098 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6099 | // in a Construct] |
| 6100 | // Variables with the predetermined data-sharing attributes may not be |
| 6101 | // listed in data-sharing attributes clauses, except for the cases |
| 6102 | // listed below. For these exceptions only, listing a predetermined |
| 6103 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6104 | // the variable's predetermined data-sharing attributes. |
| 6105 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6106 | // in a Construct, C/C++, p.2] |
| 6107 | // Variables with const-qualified type having no mutable member may be |
| 6108 | // listed in a firstprivate clause, even if they are static data members. |
| 6109 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6110 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6111 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6112 | << getOpenMPClauseName(DVar.CKind) |
| 6113 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6114 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6115 | continue; |
| 6116 | } |
| 6117 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6118 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6119 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6120 | // A list item that is private within a parallel region must not appear |
| 6121 | // in a firstprivate clause on a worksharing construct if any of the |
| 6122 | // worksharing regions arising from the worksharing construct ever bind |
| 6123 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6124 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6125 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6126 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6127 | if (DVar.CKind != OMPC_shared && |
| 6128 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6129 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6130 | Diag(ELoc, diag::err_omp_required_access) |
| 6131 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6132 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6133 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6134 | continue; |
| 6135 | } |
| 6136 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6137 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6138 | // A list item that appears in a reduction clause of a parallel construct |
| 6139 | // must not appear in a firstprivate clause on a worksharing or task |
| 6140 | // construct if any of the worksharing or task regions arising from the |
| 6141 | // worksharing or task construct ever bind to any of the parallel regions |
| 6142 | // arising from the parallel construct. |
| 6143 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6144 | // A list item that appears in a reduction clause in worksharing |
| 6145 | // construct must not appear in a firstprivate clause in a task construct |
| 6146 | // encountered during execution of any of the worksharing regions arising |
| 6147 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6148 | if (CurrDir == OMPD_task) { |
| 6149 | DVar = |
| 6150 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6151 | [](OpenMPDirectiveKind K) -> bool { |
| 6152 | return isOpenMPParallelDirective(K) || |
| 6153 | isOpenMPWorksharingDirective(K); |
| 6154 | }, |
| 6155 | false); |
| 6156 | if (DVar.CKind == OMPC_reduction && |
| 6157 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6158 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6159 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6160 | << getOpenMPDirectiveName(DVar.DKind); |
| 6161 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6162 | continue; |
| 6163 | } |
| 6164 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6165 | } |
| 6166 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6167 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6168 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6169 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6170 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6171 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6172 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6173 | bool IsDecl = |
| 6174 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6175 | Diag(VD->getLocation(), |
| 6176 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6177 | << VD; |
| 6178 | continue; |
| 6179 | } |
| 6180 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6181 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6182 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6183 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6184 | // Generate helper private variable and initialize it with the value of the |
| 6185 | // original variable. The address of the original variable is replaced by |
| 6186 | // the address of the new private variable in the CodeGen. This new variable |
| 6187 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 6188 | // original variable for proper diagnostics and variable capturing. |
| 6189 | Expr *VDInitRefExpr = nullptr; |
| 6190 | // For arrays generate initializer for single element and replace it by the |
| 6191 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6192 | if (Type->isArrayType()) { |
| 6193 | auto VDInit = |
| 6194 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 6195 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6196 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6197 | ElemType = ElemType.getUnqualifiedType(); |
| 6198 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 6199 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6200 | InitializedEntity Entity = |
| 6201 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6202 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 6203 | |
| 6204 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 6205 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 6206 | if (Result.isInvalid()) |
| 6207 | VDPrivate->setInvalidDecl(); |
| 6208 | else |
| 6209 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6210 | // Remove temp variable declaration. |
| 6211 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6212 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6213 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6214 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6215 | VDInitRefExpr = |
| 6216 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6217 | AddInitializerToDecl(VDPrivate, |
| 6218 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 6219 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6220 | } |
| 6221 | if (VDPrivate->isInvalidDecl()) { |
| 6222 | if (IsImplicitClause) { |
| 6223 | Diag(DE->getExprLoc(), |
| 6224 | diag::note_omp_task_predetermined_firstprivate_here); |
| 6225 | } |
| 6226 | continue; |
| 6227 | } |
| 6228 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6229 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6230 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6231 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 6232 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6233 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 6234 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6235 | } |
| 6236 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6237 | if (Vars.empty()) |
| 6238 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6239 | |
| 6240 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6241 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6242 | } |
| 6243 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6244 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6245 | SourceLocation StartLoc, |
| 6246 | SourceLocation LParenLoc, |
| 6247 | SourceLocation EndLoc) { |
| 6248 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6249 | SmallVector<Expr *, 8> SrcExprs; |
| 6250 | SmallVector<Expr *, 8> DstExprs; |
| 6251 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6252 | for (auto &RefExpr : VarList) { |
| 6253 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 6254 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6255 | // It will be analyzed later. |
| 6256 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6257 | SrcExprs.push_back(nullptr); |
| 6258 | DstExprs.push_back(nullptr); |
| 6259 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6260 | continue; |
| 6261 | } |
| 6262 | |
| 6263 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6264 | // OpenMP [2.1, C/C++] |
| 6265 | // A list item is a variable name. |
| 6266 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 6267 | // A variable that is part of another variable (as an array or structure |
| 6268 | // element) cannot appear in a lastprivate clause. |
| 6269 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 6270 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6271 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6272 | continue; |
| 6273 | } |
| 6274 | Decl *D = DE->getDecl(); |
| 6275 | VarDecl *VD = cast<VarDecl>(D); |
| 6276 | |
| 6277 | QualType Type = VD->getType(); |
| 6278 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6279 | // It will be analyzed later. |
| 6280 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6281 | SrcExprs.push_back(nullptr); |
| 6282 | DstExprs.push_back(nullptr); |
| 6283 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6284 | continue; |
| 6285 | } |
| 6286 | |
| 6287 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6288 | // A variable that appears in a lastprivate clause must not have an |
| 6289 | // incomplete type or a reference type. |
| 6290 | if (RequireCompleteType(ELoc, Type, |
| 6291 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6292 | continue; |
| 6293 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6294 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6295 | |
| 6296 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6297 | // in a Construct] |
| 6298 | // Variables with the predetermined data-sharing attributes may not be |
| 6299 | // listed in data-sharing attributes clauses, except for the cases |
| 6300 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6301 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6302 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6303 | DVar.CKind != OMPC_firstprivate && |
| 6304 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6305 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6306 | << getOpenMPClauseName(DVar.CKind) |
| 6307 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6308 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6309 | continue; |
| 6310 | } |
| 6311 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6312 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6313 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6314 | // A list item that is private within a parallel region, or that appears in |
| 6315 | // the reduction clause of a parallel construct, must not appear in a |
| 6316 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6317 | // worksharing regions ever binds to any of the corresponding parallel |
| 6318 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6319 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6320 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6321 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6322 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6323 | if (DVar.CKind != OMPC_shared) { |
| 6324 | Diag(ELoc, diag::err_omp_required_access) |
| 6325 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6326 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6327 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6328 | continue; |
| 6329 | } |
| 6330 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6331 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6332 | // A variable of class type (or array thereof) that appears in a |
| 6333 | // lastprivate clause requires an accessible, unambiguous default |
| 6334 | // constructor for the class type, unless the list item is also specified |
| 6335 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6336 | // A variable of class type (or array thereof) that appears in a |
| 6337 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6338 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6339 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6340 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6341 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6342 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6343 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6344 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6345 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6346 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6347 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6348 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6349 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6350 | // For arrays generate assignment operation for single element and replace |
| 6351 | // it by the original array element in CodeGen. |
| 6352 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6353 | PseudoDstExpr, PseudoSrcExpr); |
| 6354 | if (AssignmentOp.isInvalid()) |
| 6355 | continue; |
| 6356 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6357 | /*DiscardedValue=*/true); |
| 6358 | if (AssignmentOp.isInvalid()) |
| 6359 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6360 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6361 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6362 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6363 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6364 | SrcExprs.push_back(PseudoSrcExpr); |
| 6365 | DstExprs.push_back(PseudoDstExpr); |
| 6366 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6367 | } |
| 6368 | |
| 6369 | if (Vars.empty()) |
| 6370 | return nullptr; |
| 6371 | |
| 6372 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6373 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6374 | } |
| 6375 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6376 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 6377 | SourceLocation StartLoc, |
| 6378 | SourceLocation LParenLoc, |
| 6379 | SourceLocation EndLoc) { |
| 6380 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6381 | for (auto &RefExpr : VarList) { |
| 6382 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6383 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6384 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6385 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6386 | continue; |
| 6387 | } |
| 6388 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6389 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6390 | // OpenMP [2.1, C/C++] |
| 6391 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 6392 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 6393 | // A variable that is part of another variable (as an array or structure |
| 6394 | // element) cannot appear in a shared unless it is a static data member |
| 6395 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6396 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6397 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6398 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6399 | continue; |
| 6400 | } |
| 6401 | Decl *D = DE->getDecl(); |
| 6402 | VarDecl *VD = cast<VarDecl>(D); |
| 6403 | |
| 6404 | QualType Type = VD->getType(); |
| 6405 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6406 | // It will be analyzed later. |
| 6407 | Vars.push_back(DE); |
| 6408 | continue; |
| 6409 | } |
| 6410 | |
| 6411 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6412 | // in a Construct] |
| 6413 | // Variables with the predetermined data-sharing attributes may not be |
| 6414 | // listed in data-sharing attributes clauses, except for the cases |
| 6415 | // listed below. For these exceptions only, listing a predetermined |
| 6416 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6417 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6418 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6419 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 6420 | DVar.RefExpr) { |
| 6421 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6422 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6423 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6424 | continue; |
| 6425 | } |
| 6426 | |
| 6427 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 6428 | Vars.push_back(DE); |
| 6429 | } |
| 6430 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6431 | if (Vars.empty()) |
| 6432 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6433 | |
| 6434 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 6435 | } |
| 6436 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6437 | namespace { |
| 6438 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 6439 | DSAStackTy *Stack; |
| 6440 | |
| 6441 | public: |
| 6442 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 6443 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6444 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6445 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 6446 | return false; |
| 6447 | if (DVar.CKind != OMPC_unknown) |
| 6448 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6449 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6450 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6451 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6452 | return true; |
| 6453 | return false; |
| 6454 | } |
| 6455 | return false; |
| 6456 | } |
| 6457 | bool VisitStmt(Stmt *S) { |
| 6458 | for (auto Child : S->children()) { |
| 6459 | if (Child && Visit(Child)) |
| 6460 | return true; |
| 6461 | } |
| 6462 | return false; |
| 6463 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6464 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6465 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6466 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6467 | |
| 6468 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 6469 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 6470 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 6471 | CXXScopeSpec &ReductionIdScopeSpec, |
| 6472 | const DeclarationNameInfo &ReductionId) { |
| 6473 | // TODO: Allow scope specification search when 'declare reduction' is |
| 6474 | // supported. |
| 6475 | assert(ReductionIdScopeSpec.isEmpty() && |
| 6476 | "No support for scoped reduction identifiers yet."); |
| 6477 | |
| 6478 | auto DN = ReductionId.getName(); |
| 6479 | auto OOK = DN.getCXXOverloadedOperator(); |
| 6480 | BinaryOperatorKind BOK = BO_Comma; |
| 6481 | |
| 6482 | // OpenMP [2.14.3.6, reduction clause] |
| 6483 | // C |
| 6484 | // reduction-identifier is either an identifier or one of the following |
| 6485 | // operators: +, -, *, &, |, ^, && and || |
| 6486 | // C++ |
| 6487 | // reduction-identifier is either an id-expression or one of the following |
| 6488 | // operators: +, -, *, &, |, ^, && and || |
| 6489 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 6490 | switch (OOK) { |
| 6491 | case OO_Plus: |
| 6492 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6493 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6494 | break; |
| 6495 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6496 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6497 | break; |
| 6498 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6499 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6500 | break; |
| 6501 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6502 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6503 | break; |
| 6504 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6505 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6506 | break; |
| 6507 | case OO_AmpAmp: |
| 6508 | BOK = BO_LAnd; |
| 6509 | break; |
| 6510 | case OO_PipePipe: |
| 6511 | BOK = BO_LOr; |
| 6512 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6513 | case OO_New: |
| 6514 | case OO_Delete: |
| 6515 | case OO_Array_New: |
| 6516 | case OO_Array_Delete: |
| 6517 | case OO_Slash: |
| 6518 | case OO_Percent: |
| 6519 | case OO_Tilde: |
| 6520 | case OO_Exclaim: |
| 6521 | case OO_Equal: |
| 6522 | case OO_Less: |
| 6523 | case OO_Greater: |
| 6524 | case OO_LessEqual: |
| 6525 | case OO_GreaterEqual: |
| 6526 | case OO_PlusEqual: |
| 6527 | case OO_MinusEqual: |
| 6528 | case OO_StarEqual: |
| 6529 | case OO_SlashEqual: |
| 6530 | case OO_PercentEqual: |
| 6531 | case OO_CaretEqual: |
| 6532 | case OO_AmpEqual: |
| 6533 | case OO_PipeEqual: |
| 6534 | case OO_LessLess: |
| 6535 | case OO_GreaterGreater: |
| 6536 | case OO_LessLessEqual: |
| 6537 | case OO_GreaterGreaterEqual: |
| 6538 | case OO_EqualEqual: |
| 6539 | case OO_ExclaimEqual: |
| 6540 | case OO_PlusPlus: |
| 6541 | case OO_MinusMinus: |
| 6542 | case OO_Comma: |
| 6543 | case OO_ArrowStar: |
| 6544 | case OO_Arrow: |
| 6545 | case OO_Call: |
| 6546 | case OO_Subscript: |
| 6547 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 6548 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6549 | case NUM_OVERLOADED_OPERATORS: |
| 6550 | llvm_unreachable("Unexpected reduction identifier"); |
| 6551 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6552 | if (auto II = DN.getAsIdentifierInfo()) { |
| 6553 | if (II->isStr("max")) |
| 6554 | BOK = BO_GT; |
| 6555 | else if (II->isStr("min")) |
| 6556 | BOK = BO_LT; |
| 6557 | } |
| 6558 | break; |
| 6559 | } |
| 6560 | SourceRange ReductionIdRange; |
| 6561 | if (ReductionIdScopeSpec.isValid()) { |
| 6562 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 6563 | } |
| 6564 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 6565 | if (BOK == BO_Comma) { |
| 6566 | // Not allowed reduction identifier is found. |
| 6567 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 6568 | << ReductionIdRange; |
| 6569 | return nullptr; |
| 6570 | } |
| 6571 | |
| 6572 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6573 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6574 | SmallVector<Expr *, 8> LHSs; |
| 6575 | SmallVector<Expr *, 8> RHSs; |
| 6576 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6577 | for (auto RefExpr : VarList) { |
| 6578 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 6579 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6580 | // It will be analyzed later. |
| 6581 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6582 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6583 | LHSs.push_back(nullptr); |
| 6584 | RHSs.push_back(nullptr); |
| 6585 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6586 | continue; |
| 6587 | } |
| 6588 | |
| 6589 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6590 | RefExpr->isInstantiationDependent() || |
| 6591 | RefExpr->containsUnexpandedParameterPack()) { |
| 6592 | // It will be analyzed later. |
| 6593 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6594 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6595 | LHSs.push_back(nullptr); |
| 6596 | RHSs.push_back(nullptr); |
| 6597 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6598 | continue; |
| 6599 | } |
| 6600 | |
| 6601 | auto ELoc = RefExpr->getExprLoc(); |
| 6602 | auto ERange = RefExpr->getSourceRange(); |
| 6603 | // OpenMP [2.1, C/C++] |
| 6604 | // A list item is a variable or array section, subject to the restrictions |
| 6605 | // specified in Section 2.4 on page 42 and in each of the sections |
| 6606 | // describing clauses and directives for which a list appears. |
| 6607 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6608 | // A variable that is part of another variable (as an array or |
| 6609 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6610 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6611 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 6612 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 6613 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
| 6614 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6615 | continue; |
| 6616 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6617 | QualType Type; |
| 6618 | VarDecl *VD = nullptr; |
| 6619 | if (DE) { |
| 6620 | auto D = DE->getDecl(); |
| 6621 | VD = cast<VarDecl>(D); |
| 6622 | Type = VD->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6623 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6624 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6625 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 6626 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 6627 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 6628 | DE = dyn_cast<DeclRefExpr>(Base); |
| 6629 | if (DE) |
| 6630 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 6631 | if (!VD) { |
| 6632 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 6633 | << 0 << Base->getSourceRange(); |
| 6634 | continue; |
| 6635 | } |
| 6636 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6637 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 6638 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 6639 | Type = ATy->getElementType(); |
| 6640 | else |
| 6641 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6642 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 6643 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 6644 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 6645 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 6646 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 6647 | DE = dyn_cast<DeclRefExpr>(Base); |
| 6648 | if (DE) |
| 6649 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 6650 | if (!VD) { |
| 6651 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 6652 | << 1 << Base->getSourceRange(); |
| 6653 | continue; |
| 6654 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6655 | } |
| 6656 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6657 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6658 | // A variable that appears in a private clause must not have an incomplete |
| 6659 | // type or a reference type. |
| 6660 | if (RequireCompleteType(ELoc, Type, |
| 6661 | diag::err_omp_reduction_incomplete_type)) |
| 6662 | continue; |
| 6663 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6664 | // Arrays may not appear in a reduction clause. |
| 6665 | if (Type.getNonReferenceType()->isArrayType()) { |
| 6666 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6667 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6668 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6669 | VarDecl::DeclarationOnly; |
| 6670 | Diag(VD->getLocation(), |
| 6671 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6672 | << VD; |
| 6673 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6674 | continue; |
| 6675 | } |
| 6676 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6677 | // A list item that appears in a reduction clause must not be |
| 6678 | // const-qualified. |
| 6679 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6680 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6681 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6682 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6683 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6684 | VarDecl::DeclarationOnly; |
| 6685 | Diag(VD->getLocation(), |
| 6686 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6687 | << VD; |
| 6688 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6689 | continue; |
| 6690 | } |
| 6691 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 6692 | // If a list-item is a reference type then it must bind to the same object |
| 6693 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6694 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6695 | VarDecl *VDDef = VD->getDefinition(); |
| 6696 | if (Type->isReferenceType() && VDDef) { |
| 6697 | DSARefChecker Check(DSAStack); |
| 6698 | if (Check.Visit(VDDef->getInit())) { |
| 6699 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 6700 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 6701 | continue; |
| 6702 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6703 | } |
| 6704 | } |
| 6705 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6706 | // The type of a list item that appears in a reduction clause must be valid |
| 6707 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 6708 | // of the list item must be an allowed arithmetic data type: char, int, |
| 6709 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 6710 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 6711 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 6712 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 6713 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 6714 | !(Type->isScalarType() || |
| 6715 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 6716 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 6717 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6718 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6719 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6720 | VarDecl::DeclarationOnly; |
| 6721 | Diag(VD->getLocation(), |
| 6722 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6723 | << VD; |
| 6724 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6725 | continue; |
| 6726 | } |
| 6727 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 6728 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 6729 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6730 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6731 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6732 | VarDecl::DeclarationOnly; |
| 6733 | Diag(VD->getLocation(), |
| 6734 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6735 | << VD; |
| 6736 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6737 | continue; |
| 6738 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6739 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6740 | // in a Construct] |
| 6741 | // Variables with the predetermined data-sharing attributes may not be |
| 6742 | // listed in data-sharing attributes clauses, except for the cases |
| 6743 | // listed below. For these exceptions only, listing a predetermined |
| 6744 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6745 | // the variable's predetermined data-sharing attributes. |
| 6746 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 6747 | // Any number of reduction clauses can be specified on the directive, |
| 6748 | // but a list item can appear only once in the reduction clauses for that |
| 6749 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6750 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6751 | DVar = DSAStack->getTopDSA(VD, false); |
| 6752 | if (DVar.CKind == OMPC_reduction) { |
| 6753 | Diag(ELoc, diag::err_omp_once_referenced) |
| 6754 | << getOpenMPClauseName(OMPC_reduction); |
| 6755 | if (DVar.RefExpr) { |
| 6756 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6757 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6758 | } else if (DVar.CKind != OMPC_unknown) { |
| 6759 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6760 | << getOpenMPClauseName(DVar.CKind) |
| 6761 | << getOpenMPClauseName(OMPC_reduction); |
| 6762 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6763 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6764 | } |
| 6765 | |
| 6766 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 6767 | // A list item that appears in a reduction clause of a worksharing |
| 6768 | // construct must be shared in the parallel regions to which any of the |
| 6769 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6770 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6771 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6772 | !isOpenMPParallelDirective(CurrDir)) { |
| 6773 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6774 | if (DVar.CKind != OMPC_shared) { |
| 6775 | Diag(ELoc, diag::err_omp_required_access) |
| 6776 | << getOpenMPClauseName(OMPC_reduction) |
| 6777 | << getOpenMPClauseName(OMPC_shared); |
| 6778 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6779 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6780 | } |
| 6781 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6782 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6783 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6784 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 6785 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 6786 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6787 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 6788 | auto PrivateTy = Type; |
| 6789 | if (OASE) { |
| 6790 | // For array sections only: |
| 6791 | // Create pseudo array type for private copy. The size for this array will |
| 6792 | // be generated during codegen. |
| 6793 | // For array subscripts or single variables Private Ty is the same as Type |
| 6794 | // (type of the variable or single array element). |
| 6795 | PrivateTy = Context.getVariableArrayType( |
| 6796 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 6797 | Context.getSizeType(), VK_RValue), |
| 6798 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| 6799 | } |
| 6800 | // Private copy. |
| 6801 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 6802 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6803 | // Add initializer for private variable. |
| 6804 | Expr *Init = nullptr; |
| 6805 | switch (BOK) { |
| 6806 | case BO_Add: |
| 6807 | case BO_Xor: |
| 6808 | case BO_Or: |
| 6809 | case BO_LOr: |
| 6810 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 6811 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6812 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6813 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6814 | break; |
| 6815 | case BO_Mul: |
| 6816 | case BO_LAnd: |
| 6817 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6818 | // '*' and '&&' reduction ops - initializer is '1'. |
| 6819 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 6820 | } |
| 6821 | break; |
| 6822 | case BO_And: { |
| 6823 | // '&' reduction op - initializer is '~0'. |
| 6824 | QualType OrigType = Type; |
| 6825 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 6826 | Type = ComplexTy->getElementType(); |
| 6827 | } |
| 6828 | if (Type->isRealFloatingType()) { |
| 6829 | llvm::APFloat InitValue = |
| 6830 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 6831 | /*isIEEE=*/true); |
| 6832 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6833 | Type, ELoc); |
| 6834 | } else if (Type->isScalarType()) { |
| 6835 | auto Size = Context.getTypeSize(Type); |
| 6836 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 6837 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 6838 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6839 | } |
| 6840 | if (Init && OrigType->isAnyComplexType()) { |
| 6841 | // Init = 0xFFFF + 0xFFFFi; |
| 6842 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 6843 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 6844 | } |
| 6845 | Type = OrigType; |
| 6846 | break; |
| 6847 | } |
| 6848 | case BO_LT: |
| 6849 | case BO_GT: { |
| 6850 | // 'min' reduction op - initializer is 'Largest representable number in |
| 6851 | // the reduction list item type'. |
| 6852 | // 'max' reduction op - initializer is 'Least representable number in |
| 6853 | // the reduction list item type'. |
| 6854 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 6855 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 6856 | auto Size = Context.getTypeSize(Type); |
| 6857 | QualType IntTy = |
| 6858 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 6859 | llvm::APInt InitValue = |
| 6860 | (BOK != BO_LT) |
| 6861 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 6862 | : llvm::APInt::getMinValue(Size) |
| 6863 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 6864 | : llvm::APInt::getMaxValue(Size); |
| 6865 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6866 | if (Type->isPointerType()) { |
| 6867 | // Cast to pointer type. |
| 6868 | auto CastExpr = BuildCStyleCastExpr( |
| 6869 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 6870 | SourceLocation(), Init); |
| 6871 | if (CastExpr.isInvalid()) |
| 6872 | continue; |
| 6873 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6874 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6875 | } else if (Type->isRealFloatingType()) { |
| 6876 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 6877 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 6878 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6879 | Type, ELoc); |
| 6880 | } |
| 6881 | break; |
| 6882 | } |
| 6883 | case BO_PtrMemD: |
| 6884 | case BO_PtrMemI: |
| 6885 | case BO_MulAssign: |
| 6886 | case BO_Div: |
| 6887 | case BO_Rem: |
| 6888 | case BO_Sub: |
| 6889 | case BO_Shl: |
| 6890 | case BO_Shr: |
| 6891 | case BO_LE: |
| 6892 | case BO_GE: |
| 6893 | case BO_EQ: |
| 6894 | case BO_NE: |
| 6895 | case BO_AndAssign: |
| 6896 | case BO_XorAssign: |
| 6897 | case BO_OrAssign: |
| 6898 | case BO_Assign: |
| 6899 | case BO_AddAssign: |
| 6900 | case BO_SubAssign: |
| 6901 | case BO_DivAssign: |
| 6902 | case BO_RemAssign: |
| 6903 | case BO_ShlAssign: |
| 6904 | case BO_ShrAssign: |
| 6905 | case BO_Comma: |
| 6906 | llvm_unreachable("Unexpected reduction operation"); |
| 6907 | } |
| 6908 | if (Init) { |
| 6909 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 6910 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6911 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6912 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6913 | if (!RHSVD->hasInit()) { |
| 6914 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 6915 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6916 | if (VD) { |
| 6917 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6918 | VarDecl::DeclarationOnly; |
| 6919 | Diag(VD->getLocation(), |
| 6920 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6921 | << VD; |
| 6922 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6923 | continue; |
| 6924 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6925 | // Store initializer for single element in private copy. Will be used during |
| 6926 | // codegen. |
| 6927 | PrivateVD->setInit(RHSVD->getInit()); |
| 6928 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6929 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 6930 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6931 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6932 | ExprResult ReductionOp = |
| 6933 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 6934 | LHSDRE, RHSDRE); |
| 6935 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 6936 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6937 | ReductionOp = |
| 6938 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6939 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 6940 | } else { |
| 6941 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 6942 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 6943 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 6944 | ReductionOp = |
| 6945 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6946 | BO_Assign, LHSDRE, ConditionalOp); |
| 6947 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6948 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6949 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6950 | if (ReductionOp.isInvalid()) |
| 6951 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6952 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6953 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6954 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6955 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6956 | LHSs.push_back(LHSDRE); |
| 6957 | RHSs.push_back(RHSDRE); |
| 6958 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6959 | } |
| 6960 | |
| 6961 | if (Vars.empty()) |
| 6962 | return nullptr; |
| 6963 | |
| 6964 | return OMPReductionClause::Create( |
| 6965 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6966 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 6967 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6968 | } |
| 6969 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6970 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 6971 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 6972 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 6973 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6974 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6975 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6976 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6977 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 6978 | LinKind == OMPC_LINEAR_unknown) { |
| 6979 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 6980 | LinKind = OMPC_LINEAR_val; |
| 6981 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6982 | for (auto &RefExpr : VarList) { |
| 6983 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 6984 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6985 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6986 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6987 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6988 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6989 | continue; |
| 6990 | } |
| 6991 | |
| 6992 | // OpenMP [2.14.3.7, linear clause] |
| 6993 | // A list item that appears in a linear clause is subject to the private |
| 6994 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 6995 | // noted. In addition, the value of the new list item on each iteration |
| 6996 | // of the associated loop(s) corresponds to the value of the original |
| 6997 | // list item before entering the construct plus the logical number of |
| 6998 | // the iteration times linear-step. |
| 6999 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7000 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7001 | // OpenMP [2.1, C/C++] |
| 7002 | // A list item is a variable name. |
| 7003 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7004 | // A variable that is part of another variable (as an array or |
| 7005 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7006 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7007 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7008 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7009 | continue; |
| 7010 | } |
| 7011 | |
| 7012 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7013 | |
| 7014 | // OpenMP [2.14.3.7, linear clause] |
| 7015 | // A list-item cannot appear in more than one linear clause. |
| 7016 | // A list-item that appears in a linear clause cannot appear in any |
| 7017 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7018 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7019 | if (DVar.RefExpr) { |
| 7020 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7021 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7022 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7023 | continue; |
| 7024 | } |
| 7025 | |
| 7026 | QualType QType = VD->getType(); |
| 7027 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7028 | // It will be analyzed later. |
| 7029 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7030 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7031 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7032 | continue; |
| 7033 | } |
| 7034 | |
| 7035 | // A variable must not have an incomplete type or a reference type. |
| 7036 | if (RequireCompleteType(ELoc, QType, |
| 7037 | diag::err_omp_linear_incomplete_type)) { |
| 7038 | continue; |
| 7039 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7040 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7041 | !QType->isReferenceType()) { |
| 7042 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7043 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7044 | continue; |
| 7045 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7046 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7047 | |
| 7048 | // A list item must not be const-qualified. |
| 7049 | if (QType.isConstant(Context)) { |
| 7050 | Diag(ELoc, diag::err_omp_const_variable) |
| 7051 | << getOpenMPClauseName(OMPC_linear); |
| 7052 | bool IsDecl = |
| 7053 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7054 | Diag(VD->getLocation(), |
| 7055 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7056 | << VD; |
| 7057 | continue; |
| 7058 | } |
| 7059 | |
| 7060 | // A list item must be of integral or pointer type. |
| 7061 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7062 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7063 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7064 | !Ty->isPointerType())) { |
| 7065 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 7066 | bool IsDecl = |
| 7067 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7068 | Diag(VD->getLocation(), |
| 7069 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7070 | << VD; |
| 7071 | continue; |
| 7072 | } |
| 7073 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7074 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7075 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7076 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7077 | auto *PrivateRef = buildDeclRefExpr( |
| 7078 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7079 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7080 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7081 | Expr *InitExpr; |
| 7082 | if (LinKind == OMPC_LINEAR_uval) |
| 7083 | InitExpr = VD->getInit(); |
| 7084 | else |
| 7085 | InitExpr = DE; |
| 7086 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7087 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7088 | auto InitRef = buildDeclRefExpr( |
| 7089 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7090 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7091 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7092 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7093 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7097 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7098 | |
| 7099 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7100 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7101 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7102 | !Step->isInstantiationDependent() && |
| 7103 | !Step->containsUnexpandedParameterPack()) { |
| 7104 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7105 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7106 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7107 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7108 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7109 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7110 | // Build var to save the step value. |
| 7111 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7112 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7113 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7114 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7115 | ExprResult CalcStep = |
| 7116 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7117 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7118 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7119 | // Warn about zero linear step (it would be probably better specified as |
| 7120 | // making corresponding variables 'const'). |
| 7121 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7122 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7123 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7124 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7125 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7126 | if (!IsConstant && CalcStep.isUsable()) { |
| 7127 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7128 | // (This is not used if the number of iterations may be kfold-ed). |
| 7129 | CalcStepExpr = CalcStep.get(); |
| 7130 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7131 | } |
| 7132 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7133 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7134 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7135 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7136 | } |
| 7137 | |
| 7138 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7139 | Expr *NumIterations, Sema &SemaRef, |
| 7140 | Scope *S) { |
| 7141 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7142 | SmallVector<Expr *, 8> Updates; |
| 7143 | SmallVector<Expr *, 8> Finals; |
| 7144 | Expr *Step = Clause.getStep(); |
| 7145 | Expr *CalcStep = Clause.getCalcStep(); |
| 7146 | // OpenMP [2.14.3.7, linear clause] |
| 7147 | // If linear-step is not specified it is assumed to be 1. |
| 7148 | if (Step == nullptr) |
| 7149 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7150 | else if (CalcStep) |
| 7151 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7152 | bool HasErrors = false; |
| 7153 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7154 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7155 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7156 | for (auto &RefExpr : Clause.varlists()) { |
| 7157 | Expr *InitExpr = *CurInit; |
| 7158 | |
| 7159 | // Build privatized reference to the current linear var. |
| 7160 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7161 | Expr *CapturedRef; |
| 7162 | if (LinKind == OMPC_LINEAR_uval) |
| 7163 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 7164 | else |
| 7165 | CapturedRef = |
| 7166 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 7167 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 7168 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7169 | |
| 7170 | // Build update: Var = InitExpr + IV * Step |
| 7171 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7172 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7173 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7174 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 7175 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7176 | |
| 7177 | // Build final: Var = InitExpr + NumIterations * Step |
| 7178 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7179 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7180 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7181 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 7182 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7183 | if (!Update.isUsable() || !Final.isUsable()) { |
| 7184 | Updates.push_back(nullptr); |
| 7185 | Finals.push_back(nullptr); |
| 7186 | HasErrors = true; |
| 7187 | } else { |
| 7188 | Updates.push_back(Update.get()); |
| 7189 | Finals.push_back(Final.get()); |
| 7190 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7191 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7192 | } |
| 7193 | Clause.setUpdates(Updates); |
| 7194 | Clause.setFinals(Finals); |
| 7195 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7196 | } |
| 7197 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7198 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 7199 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 7200 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 7201 | |
| 7202 | SmallVector<Expr *, 8> Vars; |
| 7203 | for (auto &RefExpr : VarList) { |
| 7204 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 7205 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7206 | // It will be analyzed later. |
| 7207 | Vars.push_back(RefExpr); |
| 7208 | continue; |
| 7209 | } |
| 7210 | |
| 7211 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7212 | // OpenMP [2.1, C/C++] |
| 7213 | // A list item is a variable name. |
| 7214 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7215 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7216 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7217 | continue; |
| 7218 | } |
| 7219 | |
| 7220 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7221 | |
| 7222 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7223 | // The type of list items appearing in the aligned clause must be |
| 7224 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7225 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7226 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7227 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7228 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 7229 | !Ty->isPointerType())) { |
| 7230 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 7231 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 7232 | bool IsDecl = |
| 7233 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7234 | Diag(VD->getLocation(), |
| 7235 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7236 | << VD; |
| 7237 | continue; |
| 7238 | } |
| 7239 | |
| 7240 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7241 | // A list-item cannot appear in more than one aligned clause. |
| 7242 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 7243 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 7244 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 7245 | << getOpenMPClauseName(OMPC_aligned); |
| 7246 | continue; |
| 7247 | } |
| 7248 | |
| 7249 | Vars.push_back(DE); |
| 7250 | } |
| 7251 | |
| 7252 | // OpenMP [2.8.1, simd construct, Description] |
| 7253 | // The parameter of the aligned clause, alignment, must be a constant |
| 7254 | // positive integer expression. |
| 7255 | // If no optional parameter is specified, implementation-defined default |
| 7256 | // alignments for SIMD instructions on the target platforms are assumed. |
| 7257 | if (Alignment != nullptr) { |
| 7258 | ExprResult AlignResult = |
| 7259 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 7260 | if (AlignResult.isInvalid()) |
| 7261 | return nullptr; |
| 7262 | Alignment = AlignResult.get(); |
| 7263 | } |
| 7264 | if (Vars.empty()) |
| 7265 | return nullptr; |
| 7266 | |
| 7267 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 7268 | EndLoc, Vars, Alignment); |
| 7269 | } |
| 7270 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7271 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 7272 | SourceLocation StartLoc, |
| 7273 | SourceLocation LParenLoc, |
| 7274 | SourceLocation EndLoc) { |
| 7275 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7276 | SmallVector<Expr *, 8> SrcExprs; |
| 7277 | SmallVector<Expr *, 8> DstExprs; |
| 7278 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7279 | for (auto &RefExpr : VarList) { |
| 7280 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 7281 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7282 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7283 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7284 | SrcExprs.push_back(nullptr); |
| 7285 | DstExprs.push_back(nullptr); |
| 7286 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7287 | continue; |
| 7288 | } |
| 7289 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7290 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7291 | // OpenMP [2.1, C/C++] |
| 7292 | // A list item is a variable name. |
| 7293 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7294 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7295 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7296 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7297 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7298 | continue; |
| 7299 | } |
| 7300 | |
| 7301 | Decl *D = DE->getDecl(); |
| 7302 | VarDecl *VD = cast<VarDecl>(D); |
| 7303 | |
| 7304 | QualType Type = VD->getType(); |
| 7305 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7306 | // It will be analyzed later. |
| 7307 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7308 | SrcExprs.push_back(nullptr); |
| 7309 | DstExprs.push_back(nullptr); |
| 7310 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7311 | continue; |
| 7312 | } |
| 7313 | |
| 7314 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 7315 | // A list item that appears in a copyin clause must be threadprivate. |
| 7316 | if (!DSAStack->isThreadPrivate(VD)) { |
| 7317 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7318 | << getOpenMPClauseName(OMPC_copyin) |
| 7319 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7320 | continue; |
| 7321 | } |
| 7322 | |
| 7323 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7324 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7325 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7326 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7327 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7328 | auto *SrcVD = |
| 7329 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 7330 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7331 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7332 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 7333 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7334 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 7335 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7336 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7337 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7338 | // For arrays generate assignment operation for single element and replace |
| 7339 | // it by the original array element in CodeGen. |
| 7340 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7341 | PseudoDstExpr, PseudoSrcExpr); |
| 7342 | if (AssignmentOp.isInvalid()) |
| 7343 | continue; |
| 7344 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7345 | /*DiscardedValue=*/true); |
| 7346 | if (AssignmentOp.isInvalid()) |
| 7347 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7348 | |
| 7349 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 7350 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7351 | SrcExprs.push_back(PseudoSrcExpr); |
| 7352 | DstExprs.push_back(PseudoDstExpr); |
| 7353 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7354 | } |
| 7355 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7356 | if (Vars.empty()) |
| 7357 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7358 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7359 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7360 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7361 | } |
| 7362 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7363 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7364 | SourceLocation StartLoc, |
| 7365 | SourceLocation LParenLoc, |
| 7366 | SourceLocation EndLoc) { |
| 7367 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7368 | SmallVector<Expr *, 8> SrcExprs; |
| 7369 | SmallVector<Expr *, 8> DstExprs; |
| 7370 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7371 | for (auto &RefExpr : VarList) { |
| 7372 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7373 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7374 | // It will be analyzed later. |
| 7375 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7376 | SrcExprs.push_back(nullptr); |
| 7377 | DstExprs.push_back(nullptr); |
| 7378 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7379 | continue; |
| 7380 | } |
| 7381 | |
| 7382 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7383 | // OpenMP [2.1, C/C++] |
| 7384 | // A list item is a variable name. |
| 7385 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7386 | // A list item that appears in a copyin clause must be threadprivate. |
| 7387 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7388 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7389 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7390 | continue; |
| 7391 | } |
| 7392 | |
| 7393 | Decl *D = DE->getDecl(); |
| 7394 | VarDecl *VD = cast<VarDecl>(D); |
| 7395 | |
| 7396 | QualType Type = VD->getType(); |
| 7397 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7398 | // It will be analyzed later. |
| 7399 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7400 | SrcExprs.push_back(nullptr); |
| 7401 | DstExprs.push_back(nullptr); |
| 7402 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7403 | continue; |
| 7404 | } |
| 7405 | |
| 7406 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 7407 | // A list item that appears in a copyprivate clause may not appear in a |
| 7408 | // private or firstprivate clause on the single construct. |
| 7409 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7410 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7411 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 7412 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7413 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7414 | << getOpenMPClauseName(DVar.CKind) |
| 7415 | << getOpenMPClauseName(OMPC_copyprivate); |
| 7416 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7417 | continue; |
| 7418 | } |
| 7419 | |
| 7420 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 7421 | // All list items that appear in a copyprivate clause must be either |
| 7422 | // threadprivate or private in the enclosing context. |
| 7423 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7424 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7425 | if (DVar.CKind == OMPC_shared) { |
| 7426 | Diag(ELoc, diag::err_omp_required_access) |
| 7427 | << getOpenMPClauseName(OMPC_copyprivate) |
| 7428 | << "threadprivate or private in the enclosing context"; |
| 7429 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7430 | continue; |
| 7431 | } |
| 7432 | } |
| 7433 | } |
| 7434 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7435 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7436 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7437 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7438 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 7439 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7440 | bool IsDecl = |
| 7441 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7442 | Diag(VD->getLocation(), |
| 7443 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7444 | << VD; |
| 7445 | continue; |
| 7446 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7447 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7448 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7449 | // A variable of class type (or array thereof) that appears in a |
| 7450 | // copyin clause requires an accessible, unambiguous copy assignment |
| 7451 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7452 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 7453 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7454 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7455 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 7456 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7457 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7458 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7459 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7460 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 7461 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7462 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7463 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7464 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7465 | PseudoDstExpr, PseudoSrcExpr); |
| 7466 | if (AssignmentOp.isInvalid()) |
| 7467 | continue; |
| 7468 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7469 | /*DiscardedValue=*/true); |
| 7470 | if (AssignmentOp.isInvalid()) |
| 7471 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7472 | |
| 7473 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 7474 | // implicitly private. |
| 7475 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7476 | SrcExprs.push_back(PseudoSrcExpr); |
| 7477 | DstExprs.push_back(PseudoDstExpr); |
| 7478 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7479 | } |
| 7480 | |
| 7481 | if (Vars.empty()) |
| 7482 | return nullptr; |
| 7483 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7484 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 7485 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7486 | } |
| 7487 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7488 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 7489 | SourceLocation StartLoc, |
| 7490 | SourceLocation LParenLoc, |
| 7491 | SourceLocation EndLoc) { |
| 7492 | if (VarList.empty()) |
| 7493 | return nullptr; |
| 7494 | |
| 7495 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 7496 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7497 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7498 | OMPClause * |
| 7499 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 7500 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 7501 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 7502 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7503 | if (DepKind == OMPC_DEPEND_unknown) { |
| 7504 | std::string Values; |
| 7505 | std::string Sep(", "); |
| 7506 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 7507 | Values += "'"; |
| 7508 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 7509 | Values += "'"; |
| 7510 | switch (i) { |
| 7511 | case OMPC_DEPEND_unknown - 2: |
| 7512 | Values += " or "; |
| 7513 | break; |
| 7514 | case OMPC_DEPEND_unknown - 1: |
| 7515 | break; |
| 7516 | default: |
| 7517 | Values += Sep; |
| 7518 | break; |
| 7519 | } |
| 7520 | } |
| 7521 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 7522 | << Values << getOpenMPClauseName(OMPC_depend); |
| 7523 | return nullptr; |
| 7524 | } |
| 7525 | SmallVector<Expr *, 8> Vars; |
| 7526 | for (auto &RefExpr : VarList) { |
| 7527 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7528 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7529 | // It will be analyzed later. |
| 7530 | Vars.push_back(RefExpr); |
| 7531 | continue; |
| 7532 | } |
| 7533 | |
| 7534 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7535 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 7536 | // A variable that is part of another variable (such as a field of a |
| 7537 | // structure) but is not an array element or an array section cannot appear |
| 7538 | // in a depend clause. |
| 7539 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7540 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7541 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7542 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7543 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 7544 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7545 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7546 | !ASE->getBase()->getType()->isArrayType())) { |
| 7547 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7548 | << RefExpr->getSourceRange(); |
| 7549 | continue; |
| 7550 | } |
| 7551 | |
| 7552 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 7553 | } |
| 7554 | |
| 7555 | if (Vars.empty()) |
| 7556 | return nullptr; |
| 7557 | |
| 7558 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 7559 | DepLoc, ColonLoc, Vars); |
| 7560 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7561 | |
| 7562 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 7563 | SourceLocation LParenLoc, |
| 7564 | SourceLocation EndLoc) { |
| 7565 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7566 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7567 | // OpenMP [2.9.1, Restrictions] |
| 7568 | // The device expression must evaluate to a non-negative integer value. |
| 7569 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device)) |
| 7570 | return nullptr; |
| 7571 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7572 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7573 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7574 | |
| 7575 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 7576 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 7577 | if (!RD || RD->isInvalidDecl()) |
| 7578 | return true; |
| 7579 | |
| 7580 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 7581 | if (RD->isDynamicClass()) { |
| 7582 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7583 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 7584 | return false; |
| 7585 | } |
| 7586 | auto *DC = RD; |
| 7587 | bool IsCorrect = true; |
| 7588 | for (auto *I : DC->decls()) { |
| 7589 | if (I) { |
| 7590 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 7591 | if (MD->isStatic()) { |
| 7592 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7593 | SemaRef.Diag(MD->getLocation(), |
| 7594 | diag::note_omp_static_member_in_target); |
| 7595 | IsCorrect = false; |
| 7596 | } |
| 7597 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 7598 | if (VD->isStaticDataMember()) { |
| 7599 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7600 | SemaRef.Diag(VD->getLocation(), |
| 7601 | diag::note_omp_static_member_in_target); |
| 7602 | IsCorrect = false; |
| 7603 | } |
| 7604 | } |
| 7605 | } |
| 7606 | } |
| 7607 | |
| 7608 | for (auto &I : RD->bases()) { |
| 7609 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 7610 | I.getType()->getAsCXXRecordDecl())) |
| 7611 | IsCorrect = false; |
| 7612 | } |
| 7613 | return IsCorrect; |
| 7614 | } |
| 7615 | |
| 7616 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 7617 | DSAStackTy *Stack, QualType QTy) { |
| 7618 | NamedDecl *ND; |
| 7619 | if (QTy->isIncompleteType(&ND)) { |
| 7620 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 7621 | return false; |
| 7622 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 7623 | if (!RD->isInvalidDecl() && |
| 7624 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 7625 | return false; |
| 7626 | } |
| 7627 | return true; |
| 7628 | } |
| 7629 | |
| 7630 | OMPClause *Sema::ActOnOpenMPMapClause( |
| 7631 | OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, |
| 7632 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 7633 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7634 | SmallVector<Expr *, 4> Vars; |
| 7635 | |
| 7636 | for (auto &RE : VarList) { |
| 7637 | assert(RE && "Null expr in omp map"); |
| 7638 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 7639 | // It will be analyzed later. |
| 7640 | Vars.push_back(RE); |
| 7641 | continue; |
| 7642 | } |
| 7643 | SourceLocation ELoc = RE->getExprLoc(); |
| 7644 | |
| 7645 | // OpenMP [2.14.5, Restrictions] |
| 7646 | // A variable that is part of another variable (such as field of a |
| 7647 | // structure) but is not an array element or an array section cannot appear |
| 7648 | // in a map clause. |
| 7649 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 7650 | |
| 7651 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 7652 | VE->isInstantiationDependent() || |
| 7653 | VE->containsUnexpandedParameterPack()) { |
| 7654 | // It will be analyzed later. |
| 7655 | Vars.push_back(RE); |
| 7656 | continue; |
| 7657 | } |
| 7658 | |
| 7659 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
| 7660 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7661 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7662 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7663 | |
| 7664 | if (!RE->IgnoreParenImpCasts()->isLValue() || |
| 7665 | (!OASE && !ASE && !DE) || |
| 7666 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 7667 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7668 | !ASE->getBase()->getType()->isArrayType())) { |
| 7669 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7670 | << RE->getSourceRange(); |
| 7671 | continue; |
| 7672 | } |
| 7673 | |
| 7674 | Decl *D = nullptr; |
| 7675 | if (DE) { |
| 7676 | D = DE->getDecl(); |
| 7677 | } else if (ASE) { |
| 7678 | auto *B = ASE->getBase()->IgnoreParenCasts(); |
| 7679 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 7680 | } else if (OASE) { |
| 7681 | auto *B = OASE->getBase(); |
| 7682 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 7683 | } |
| 7684 | assert(D && "Null decl on map clause."); |
| 7685 | auto *VD = cast<VarDecl>(D); |
| 7686 | |
| 7687 | // OpenMP [2.14.5, Restrictions, p.8] |
| 7688 | // threadprivate variables cannot appear in a map clause. |
| 7689 | if (DSAStack->isThreadPrivate(VD)) { |
| 7690 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 7691 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 7692 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7693 | continue; |
| 7694 | } |
| 7695 | |
| 7696 | // OpenMP [2.14.5, Restrictions, p.2] |
| 7697 | // At most one list item can be an array item derived from a given variable |
| 7698 | // in map clauses of the same construct. |
| 7699 | // OpenMP [2.14.5, Restrictions, p.3] |
| 7700 | // List items of map clauses in the same construct must not share original |
| 7701 | // storage. |
| 7702 | // OpenMP [2.14.5, Restrictions, C/C++, p.2] |
| 7703 | // A variable for which the type is pointer, reference to array, or |
| 7704 | // reference to pointer and an array section derived from that variable |
| 7705 | // must not appear as list items of map clauses of the same construct. |
| 7706 | DSAStackTy::MapInfo MI = DSAStack->IsMappedInCurrentRegion(VD); |
| 7707 | if (MI.RefExpr) { |
| 7708 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 7709 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 7710 | << MI.RefExpr->getSourceRange(); |
| 7711 | continue; |
| 7712 | } |
| 7713 | |
| 7714 | // OpenMP [2.14.5, Restrictions, C/C++, p.3,4] |
| 7715 | // A variable for which the type is pointer, reference to array, or |
| 7716 | // reference to pointer must not appear as a list item if the enclosing |
| 7717 | // device data environment already contains an array section derived from |
| 7718 | // that variable. |
| 7719 | // An array section derived from a variable for which the type is pointer, |
| 7720 | // reference to array, or reference to pointer must not appear as a list |
| 7721 | // item if the enclosing device data environment already contains that |
| 7722 | // variable. |
| 7723 | QualType Type = VD->getType(); |
| 7724 | MI = DSAStack->getMapInfoForVar(VD); |
| 7725 | if (MI.RefExpr && (isa<DeclRefExpr>(MI.RefExpr->IgnoreParenLValueCasts()) != |
| 7726 | isa<DeclRefExpr>(VE)) && |
| 7727 | (Type->isPointerType() || Type->isReferenceType())) { |
| 7728 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 7729 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 7730 | << MI.RefExpr->getSourceRange(); |
| 7731 | continue; |
| 7732 | } |
| 7733 | |
| 7734 | // OpenMP [2.14.5, Restrictions, C/C++, p.7] |
| 7735 | // A list item must have a mappable type. |
| 7736 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 7737 | DSAStack, Type)) |
| 7738 | continue; |
| 7739 | |
| 7740 | Vars.push_back(RE); |
| 7741 | MI.RefExpr = RE; |
| 7742 | DSAStack->addMapInfoForVar(VD, MI); |
| 7743 | } |
| 7744 | if (Vars.empty()) |
| 7745 | return nullptr; |
| 7746 | |
| 7747 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7748 | MapTypeModifier, MapType, MapLoc); |
| 7749 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7750 | |
| 7751 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 7752 | SourceLocation StartLoc, |
| 7753 | SourceLocation LParenLoc, |
| 7754 | SourceLocation EndLoc) { |
| 7755 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7756 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7757 | // OpenMP [teams Constrcut, Restrictions] |
| 7758 | // The num_teams expression must evaluate to a positive integer value. |
| 7759 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams)) |
| 7760 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7761 | |
| 7762 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7763 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7764 | |
| 7765 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 7766 | SourceLocation StartLoc, |
| 7767 | SourceLocation LParenLoc, |
| 7768 | SourceLocation EndLoc) { |
| 7769 | Expr *ValExpr = ThreadLimit; |
| 7770 | |
| 7771 | // OpenMP [teams Constrcut, Restrictions] |
| 7772 | // The thread_limit expression must evaluate to a positive integer value. |
| 7773 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit)) |
| 7774 | return nullptr; |
| 7775 | |
| 7776 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 7777 | EndLoc); |
| 7778 | } |