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 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 225 | /// \brief Return the directive associated with the provided scope. |
| 226 | OpenMPDirectiveKind getDirectiveForScope(const Scope *S) const; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 227 | |
| 228 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 229 | void setDefaultDSANone(SourceLocation Loc) { |
| 230 | Stack.back().DefaultAttr = DSA_none; |
| 231 | Stack.back().DefaultAttrLoc = Loc; |
| 232 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 233 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 234 | void setDefaultDSAShared(SourceLocation Loc) { |
| 235 | Stack.back().DefaultAttr = DSA_shared; |
| 236 | Stack.back().DefaultAttrLoc = Loc; |
| 237 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 238 | |
| 239 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 240 | return Stack.back().DefaultAttr; |
| 241 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 242 | SourceLocation getDefaultDSALocation() const { |
| 243 | return Stack.back().DefaultAttrLoc; |
| 244 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 245 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 246 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 247 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 248 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 249 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 250 | } |
| 251 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 252 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 253 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 254 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 255 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 256 | } |
| 257 | /// \brief Returns true, if parent region is ordered (has associated |
| 258 | /// 'ordered' clause), false - otherwise. |
| 259 | bool isParentOrderedRegion() const { |
| 260 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 261 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 262 | return false; |
| 263 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 264 | /// \brief Returns optional parameter for the ordered region. |
| 265 | Expr *getParentOrderedRegionParam() const { |
| 266 | if (Stack.size() > 2) |
| 267 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 268 | return nullptr; |
| 269 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 270 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 271 | void setNowaitRegion(bool IsNowait = true) { |
| 272 | Stack.back().NowaitRegion = IsNowait; |
| 273 | } |
| 274 | /// \brief Returns true, if parent region is nowait (has associated |
| 275 | /// 'nowait' clause), false - otherwise. |
| 276 | bool isParentNowaitRegion() const { |
| 277 | if (Stack.size() > 2) |
| 278 | return Stack[Stack.size() - 2].NowaitRegion; |
| 279 | return false; |
| 280 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 281 | /// \brief Marks parent region as cancel region. |
| 282 | void setParentCancelRegion(bool Cancel = true) { |
| 283 | if (Stack.size() > 2) |
| 284 | Stack[Stack.size() - 2].CancelRegion = |
| 285 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 286 | } |
| 287 | /// \brief Return true if current region has inner cancel construct. |
| 288 | bool isCancelRegion() const { |
| 289 | return Stack.back().CancelRegion; |
| 290 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 291 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 292 | /// \brief Set collapse value for the region. |
| 293 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 294 | /// \brief Return collapse value for region. |
| 295 | unsigned getCollapseNumber() const { |
| 296 | return Stack.back().CollapseNumber; |
| 297 | } |
| 298 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 299 | /// \brief Marks current target region as one with closely nested teams |
| 300 | /// region. |
| 301 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 302 | if (Stack.size() > 2) |
| 303 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 304 | } |
| 305 | /// \brief Returns true, if current region has closely nested teams region. |
| 306 | bool hasInnerTeamsRegion() const { |
| 307 | return getInnerTeamsRegionLoc().isValid(); |
| 308 | } |
| 309 | /// \brief Returns location of the nested teams region (if any). |
| 310 | SourceLocation getInnerTeamsRegionLoc() const { |
| 311 | if (Stack.size() > 1) |
| 312 | return Stack.back().InnerTeamsRegionLoc; |
| 313 | return SourceLocation(); |
| 314 | } |
| 315 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 316 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 317 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 318 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 319 | |
| 320 | MapInfo getMapInfoForVar(VarDecl *VD) { |
| 321 | MapInfo VarMI = {0}; |
| 322 | for (auto Cnt = Stack.size() - 1; Cnt > 0; --Cnt) { |
| 323 | if (Stack[Cnt].MappedDecls.count(VD)) { |
| 324 | VarMI = Stack[Cnt].MappedDecls[VD]; |
| 325 | break; |
| 326 | } |
| 327 | } |
| 328 | return VarMI; |
| 329 | } |
| 330 | |
| 331 | void addMapInfoForVar(VarDecl *VD, MapInfo MI) { |
| 332 | if (Stack.size() > 1) { |
| 333 | Stack.back().MappedDecls[VD] = MI; |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | MapInfo IsMappedInCurrentRegion(VarDecl *VD) { |
| 338 | assert(Stack.size() > 1 && "Target level is 0"); |
| 339 | MapInfo VarMI = {0}; |
| 340 | if (Stack.size() > 1 && Stack.back().MappedDecls.count(VD)) { |
| 341 | VarMI = Stack.back().MappedDecls[VD]; |
| 342 | } |
| 343 | return VarMI; |
| 344 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 345 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 346 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 347 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 348 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 349 | isOpenMPTaskLoopDirective(DKind); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 350 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 351 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 352 | |
| 353 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 354 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 355 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 356 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 357 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 358 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 359 | // in a region but not in construct] |
| 360 | // File-scope or namespace-scope variables referenced in called routines |
| 361 | // in the region are shared unless they appear in a threadprivate |
| 362 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 363 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 364 | DVar.CKind = OMPC_shared; |
| 365 | |
| 366 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 367 | // in a region but not in construct] |
| 368 | // Variables with static storage duration that are declared in called |
| 369 | // routines in the region are shared. |
| 370 | if (D->hasGlobalStorage()) |
| 371 | DVar.CKind = OMPC_shared; |
| 372 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 373 | return DVar; |
| 374 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 375 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 376 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 377 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 378 | // in a Construct, C/C++, predetermined, p.1] |
| 379 | // Variables with automatic storage duration that are declared in a scope |
| 380 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 381 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 382 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 383 | DVar.CKind = OMPC_private; |
| 384 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 387 | // Explicitly specified attributes and local variables with predetermined |
| 388 | // attributes. |
| 389 | if (Iter->SharingMap.count(D)) { |
| 390 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 391 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 392 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 393 | return DVar; |
| 394 | } |
| 395 | |
| 396 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 397 | // in a Construct, C/C++, implicitly determined, p.1] |
| 398 | // In a parallel or task construct, the data-sharing attributes of these |
| 399 | // variables are determined by the default clause, if present. |
| 400 | switch (Iter->DefaultAttr) { |
| 401 | case DSA_shared: |
| 402 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 403 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 404 | return DVar; |
| 405 | case DSA_none: |
| 406 | return DVar; |
| 407 | case DSA_unspecified: |
| 408 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 409 | // in a Construct, implicitly determined, p.2] |
| 410 | // In a parallel construct, if no default clause is present, these |
| 411 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 412 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 413 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 414 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 415 | DVar.CKind = OMPC_shared; |
| 416 | return DVar; |
| 417 | } |
| 418 | |
| 419 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 420 | // in a Construct, implicitly determined, p.4] |
| 421 | // In a task construct, if no default clause is present, a variable that in |
| 422 | // the enclosing context is determined to be shared by all implicit tasks |
| 423 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 424 | if (DVar.DKind == OMPD_task) { |
| 425 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 426 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 427 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 428 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 429 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 430 | // in a Construct, implicitly determined, p.6] |
| 431 | // In a task construct, if no default clause is present, a variable |
| 432 | // whose data-sharing attribute is not determined by the rules above is |
| 433 | // firstprivate. |
| 434 | DVarTemp = getDSA(I, D); |
| 435 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 436 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 437 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 438 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 439 | return DVar; |
| 440 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 441 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 442 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 443 | } |
| 444 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 446 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 447 | return DVar; |
| 448 | } |
| 449 | } |
| 450 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 451 | // in a Construct, implicitly determined, p.3] |
| 452 | // For constructs other than task, if no default clause is present, these |
| 453 | // variables inherit their data-sharing attributes from the enclosing |
| 454 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 455 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 458 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 459 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 460 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 461 | auto It = Stack.back().AlignedMap.find(D); |
| 462 | if (It == Stack.back().AlignedMap.end()) { |
| 463 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 464 | Stack.back().AlignedMap[D] = NewDE; |
| 465 | return nullptr; |
| 466 | } else { |
| 467 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 468 | return It->second; |
| 469 | } |
| 470 | return nullptr; |
| 471 | } |
| 472 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 473 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 474 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 475 | D = D->getCanonicalDecl(); |
| 476 | Stack.back().LCVSet.insert(D); |
| 477 | } |
| 478 | |
| 479 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 480 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 481 | D = D->getCanonicalDecl(); |
| 482 | return Stack.back().LCVSet.count(D) > 0; |
| 483 | } |
| 484 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 485 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 486 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 487 | if (A == OMPC_threadprivate) { |
| 488 | Stack[0].SharingMap[D].Attributes = A; |
| 489 | Stack[0].SharingMap[D].RefExpr = E; |
| 490 | } else { |
| 491 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 492 | Stack.back().SharingMap[D].Attributes = A; |
| 493 | Stack.back().SharingMap[D].RefExpr = E; |
| 494 | } |
| 495 | } |
| 496 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 497 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 498 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 499 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 500 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 501 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 502 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 503 | ++I; |
| 504 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 505 | if (I == E) |
| 506 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 507 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 508 | Scope *CurScope = getCurScope(); |
| 509 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 510 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 511 | } |
| 512 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 513 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 514 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 517 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 518 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 519 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 520 | DeclContext *DC = SemaRef.CurContext; |
| 521 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 522 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 523 | VarDecl *Decl = |
| 524 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 525 | if (Attrs) { |
| 526 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 527 | I != E; ++I) |
| 528 | Decl->addAttr(*I); |
| 529 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 530 | Decl->setImplicit(); |
| 531 | return Decl; |
| 532 | } |
| 533 | |
| 534 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 535 | SourceLocation Loc, |
| 536 | bool RefersToCapture = false) { |
| 537 | D->setReferenced(); |
| 538 | D->markUsed(S.Context); |
| 539 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 540 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 541 | VK_LValue); |
| 542 | } |
| 543 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 544 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 545 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 546 | DSAVarData DVar; |
| 547 | |
| 548 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 549 | // in a Construct, C/C++, predetermined, p.1] |
| 550 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 551 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 552 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 553 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 554 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 555 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 556 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 557 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 558 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 559 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 560 | } |
| 561 | if (Stack[0].SharingMap.count(D)) { |
| 562 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 563 | DVar.CKind = OMPC_threadprivate; |
| 564 | return DVar; |
| 565 | } |
| 566 | |
| 567 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 568 | // in a Construct, C/C++, predetermined, p.1] |
| 569 | // Variables with automatic storage duration that are declared in a scope |
| 570 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 571 | OpenMPDirectiveKind Kind = |
| 572 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 573 | auto StartI = std::next(Stack.rbegin()); |
| 574 | auto EndI = std::prev(Stack.rend()); |
| 575 | if (FromParent && StartI != EndI) { |
| 576 | StartI = std::next(StartI); |
| 577 | } |
| 578 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 579 | if (isOpenMPLocal(D, StartI) && |
| 580 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 581 | D->getStorageClass() == SC_None)) || |
| 582 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 583 | DVar.CKind = OMPC_private; |
| 584 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 585 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 586 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 587 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 588 | // in a Construct, C/C++, predetermined, p.4] |
| 589 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 590 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 591 | // in a Construct, C/C++, predetermined, p.7] |
| 592 | // Variables with static storage duration that are declared in a scope |
| 593 | // inside the construct are shared. |
Kelvin Li | 4eea8c6 | 2015-09-15 18:56:58 +0000 | [diff] [blame] | 594 | if (D->isStaticDataMember()) { |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 595 | DSAVarData DVarTemp = |
| 596 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 597 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 598 | return DVar; |
| 599 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 600 | DVar.CKind = OMPC_shared; |
| 601 | return DVar; |
| 602 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 606 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 607 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 608 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 609 | // in a Construct, C/C++, predetermined, p.6] |
| 610 | // Variables with const qualified type having no mutable member are |
| 611 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 612 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 613 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 614 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 615 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 616 | // Variables with const-qualified type having no mutable member may be |
| 617 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 618 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 619 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 620 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 621 | return DVar; |
| 622 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 623 | DVar.CKind = OMPC_shared; |
| 624 | return DVar; |
| 625 | } |
| 626 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 627 | // Explicitly specified attributes and local variables with predetermined |
| 628 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 629 | auto I = std::prev(StartI); |
| 630 | if (I->SharingMap.count(D)) { |
| 631 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 632 | DVar.CKind = I->SharingMap[D].Attributes; |
| 633 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | return DVar; |
| 637 | } |
| 638 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 639 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 640 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 641 | auto StartI = Stack.rbegin(); |
| 642 | auto EndI = std::prev(Stack.rend()); |
| 643 | if (FromParent && StartI != EndI) { |
| 644 | StartI = std::next(StartI); |
| 645 | } |
| 646 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 649 | template <class ClausesPredicate, class DirectivesPredicate> |
| 650 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 651 | DirectivesPredicate DPred, |
| 652 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 653 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 654 | auto StartI = std::next(Stack.rbegin()); |
| 655 | auto EndI = std::prev(Stack.rend()); |
| 656 | if (FromParent && StartI != EndI) { |
| 657 | StartI = std::next(StartI); |
| 658 | } |
| 659 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 660 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 661 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 662 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 663 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 664 | return DVar; |
| 665 | } |
| 666 | return DSAVarData(); |
| 667 | } |
| 668 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 669 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 670 | DSAStackTy::DSAVarData |
| 671 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 672 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 673 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 674 | auto StartI = std::next(Stack.rbegin()); |
| 675 | auto EndI = std::prev(Stack.rend()); |
| 676 | if (FromParent && StartI != EndI) { |
| 677 | StartI = std::next(StartI); |
| 678 | } |
| 679 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 680 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 681 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 682 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 683 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 684 | return DVar; |
| 685 | return DSAVarData(); |
| 686 | } |
| 687 | return DSAVarData(); |
| 688 | } |
| 689 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 690 | bool DSAStackTy::hasExplicitDSA( |
| 691 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 692 | unsigned Level) { |
| 693 | if (CPred(ClauseKindMode)) |
| 694 | return true; |
| 695 | if (isClauseParsingMode()) |
| 696 | ++Level; |
| 697 | D = D->getCanonicalDecl(); |
| 698 | auto StartI = Stack.rbegin(); |
| 699 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 700 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 701 | return false; |
| 702 | std::advance(StartI, Level); |
| 703 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 704 | CPred(StartI->SharingMap[D].Attributes); |
| 705 | } |
| 706 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 707 | bool DSAStackTy::hasExplicitDirective( |
| 708 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 709 | unsigned Level) { |
| 710 | if (isClauseParsingMode()) |
| 711 | ++Level; |
| 712 | auto StartI = Stack.rbegin(); |
| 713 | auto EndI = std::prev(Stack.rend()); |
| 714 | if (std::distance(StartI, EndI) <= (int)Level) |
| 715 | return false; |
| 716 | std::advance(StartI, Level); |
| 717 | return DPred(StartI->Directive); |
| 718 | } |
| 719 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 720 | template <class NamedDirectivesPredicate> |
| 721 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 722 | auto StartI = std::next(Stack.rbegin()); |
| 723 | auto EndI = std::prev(Stack.rend()); |
| 724 | if (FromParent && StartI != EndI) { |
| 725 | StartI = std::next(StartI); |
| 726 | } |
| 727 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 728 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 729 | return true; |
| 730 | } |
| 731 | return false; |
| 732 | } |
| 733 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 734 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 735 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 736 | if (I->CurScope == S) |
| 737 | return I->Directive; |
| 738 | return OMPD_unknown; |
| 739 | } |
| 740 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 741 | void Sema::InitDataSharingAttributesStack() { |
| 742 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 743 | } |
| 744 | |
| 745 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 746 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 747 | bool Sema::IsOpenMPCapturedByRef(VarDecl *VD, |
| 748 | const CapturedRegionScopeInfo *RSI) { |
| 749 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 750 | |
| 751 | auto &Ctx = getASTContext(); |
| 752 | bool IsByRef = true; |
| 753 | |
| 754 | // Find the directive that is associated with the provided scope. |
| 755 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
| 756 | auto Ty = VD->getType(); |
| 757 | |
| 758 | if (isOpenMPTargetDirective(DKind)) { |
| 759 | // This table summarizes how a given variable should be passed to the device |
| 760 | // given its type and the clauses where it appears. This table is based on |
| 761 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 762 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 763 | // |
| 764 | // ========================================================================= |
| 765 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 766 | // | |(tofrom:scalar)| | pvt | | | | |
| 767 | // ========================================================================= |
| 768 | // | scl | | | | - | | bycopy| |
| 769 | // | scl | | - | x | - | - | bycopy| |
| 770 | // | scl | | x | - | - | - | null | |
| 771 | // | scl | x | | | - | | byref | |
| 772 | // | scl | x | - | x | - | - | bycopy| |
| 773 | // | scl | x | x | - | - | - | null | |
| 774 | // | scl | | - | - | - | x | byref | |
| 775 | // | scl | x | - | - | - | x | byref | |
| 776 | // |
| 777 | // | agg | n.a. | | | - | | byref | |
| 778 | // | agg | n.a. | - | x | - | - | byref | |
| 779 | // | agg | n.a. | x | - | - | - | null | |
| 780 | // | agg | n.a. | - | - | - | x | byref | |
| 781 | // | agg | n.a. | - | - | - | x[] | byref | |
| 782 | // |
| 783 | // | ptr | n.a. | | | - | | bycopy| |
| 784 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 785 | // | ptr | n.a. | x | - | - | - | null | |
| 786 | // | ptr | n.a. | - | - | - | x | byref | |
| 787 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 788 | // | ptr | n.a. | - | - | x | | bycopy| |
| 789 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 790 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 791 | // ========================================================================= |
| 792 | // Legend: |
| 793 | // scl - scalar |
| 794 | // ptr - pointer |
| 795 | // agg - aggregate |
| 796 | // x - applies |
| 797 | // - - invalid in this combination |
| 798 | // [] - mapped with an array section |
| 799 | // byref - should be mapped by reference |
| 800 | // byval - should be mapped by value |
| 801 | // null - initialize a local variable to null on the device |
| 802 | // |
| 803 | // Observations: |
| 804 | // - All scalar declarations that show up in a map clause have to be passed |
| 805 | // by reference, because they may have been mapped in the enclosing data |
| 806 | // environment. |
| 807 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 808 | // passed by reference, regardless the result in the table above. |
| 809 | // - For pointers mapped by value that have either an implicit map or an |
| 810 | // array section, the runtime library may pass the NULL value to the |
| 811 | // device instead of the value passed to it by the compiler. |
| 812 | |
| 813 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 814 | // values requires having the map, private, and firstprivate clauses SEMA |
| 815 | // and parsing in place, which we don't yet. |
| 816 | |
| 817 | if (Ty->isReferenceType()) |
| 818 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 819 | IsByRef = !Ty->isScalarType(); |
| 820 | } |
| 821 | |
| 822 | // When passing data by value, we need to make sure it fits the uintptr size |
| 823 | // and alignment, because the runtime library only deals with uintptr types. |
| 824 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 825 | // instead. |
| 826 | if (!IsByRef && |
| 827 | (Ctx.getTypeSizeInChars(Ty) > |
| 828 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
| 829 | Ctx.getDeclAlign(VD) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
| 830 | IsByRef = true; |
| 831 | |
| 832 | return IsByRef; |
| 833 | } |
| 834 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 835 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 836 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 837 | VD = VD->getCanonicalDecl(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 838 | |
| 839 | // If we are attempting to capture a global variable in a directive with |
| 840 | // 'target' we return true so that this global is also mapped to the device. |
| 841 | // |
| 842 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 843 | // then it should not be captured. Therefore, an extra check has to be |
| 844 | // inserted here once support for 'declare target' is added. |
| 845 | // |
| 846 | if (!VD->hasLocalStorage()) { |
| 847 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 848 | !DSAStack->isClauseParsingMode()) { |
| 849 | return true; |
| 850 | } |
| 851 | if (DSAStack->getCurScope() && |
| 852 | DSAStack->hasDirective( |
| 853 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 854 | SourceLocation Loc) -> bool { |
| 855 | return isOpenMPTargetDirective(K); |
| 856 | }, |
| 857 | false)) { |
| 858 | return true; |
| 859 | } |
| 860 | } |
| 861 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 862 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 863 | (!DSAStack->isClauseParsingMode() || |
| 864 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 865 | if (DSAStack->isLoopControlVariable(VD) || |
| 866 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 867 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 868 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 869 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 870 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 871 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 872 | return true; |
| 873 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 874 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 875 | return DVarPrivate.CKind != OMPC_unknown; |
| 876 | } |
| 877 | return false; |
| 878 | } |
| 879 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 880 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 881 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 882 | return DSAStack->hasExplicitDSA( |
| 883 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 884 | } |
| 885 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 886 | bool Sema::isOpenMPTargetCapturedVar(VarDecl *VD, unsigned Level) { |
| 887 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 888 | // Return true if the current level is no longer enclosed in a target region. |
| 889 | |
| 890 | return !VD->hasLocalStorage() && |
| 891 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 892 | } |
| 893 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 894 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 895 | |
| 896 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 897 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 898 | Scope *CurScope, SourceLocation Loc) { |
| 899 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 900 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 901 | } |
| 902 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 903 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 904 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 907 | void Sema::EndOpenMPClause() { |
| 908 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 911 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 912 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 913 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 914 | // clause requires an accessible, unambiguous default constructor for the |
| 915 | // class type, unless the list item is also specified in a firstprivate |
| 916 | // clause. |
| 917 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 918 | for (auto *C : D->clauses()) { |
| 919 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 920 | SmallVector<Expr *, 8> PrivateCopies; |
| 921 | for (auto *DE : Clause->varlists()) { |
| 922 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 923 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 924 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 925 | } |
| 926 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 927 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 928 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 929 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 930 | // Generate helper private variable and initialize it with the |
| 931 | // default value. The address of the original variable is replaced |
| 932 | // by the address of the new private variable in CodeGen. This new |
| 933 | // variable is not added to IdResolver, so the code in the OpenMP |
| 934 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 935 | auto *VDPrivate = buildVarDecl( |
| 936 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 937 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 938 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 939 | if (VDPrivate->isInvalidDecl()) |
| 940 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 941 | PrivateCopies.push_back(buildDeclRefExpr( |
| 942 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 943 | } else { |
| 944 | // The variable is also a firstprivate, so initialization sequence |
| 945 | // for private copy is generated already. |
| 946 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 947 | } |
| 948 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 949 | // Set initializers to private copies if no errors were found. |
| 950 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 951 | Clause->setPrivateCopies(PrivateCopies); |
| 952 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | } |
| 956 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 957 | DSAStack->pop(); |
| 958 | DiscardCleanupsInEvaluationContext(); |
| 959 | PopExpressionEvaluationContext(); |
| 960 | } |
| 961 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 962 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 963 | Expr *NumIterations, Sema &SemaRef, |
| 964 | Scope *S); |
| 965 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 966 | namespace { |
| 967 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 968 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 969 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 970 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 971 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 972 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 973 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 974 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 975 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 976 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 977 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 978 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 979 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 980 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 981 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 982 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 983 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 984 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 985 | |
| 986 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 987 | CXXScopeSpec &ScopeSpec, |
| 988 | const DeclarationNameInfo &Id) { |
| 989 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 990 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 991 | |
| 992 | if (Lookup.isAmbiguous()) |
| 993 | return ExprError(); |
| 994 | |
| 995 | VarDecl *VD; |
| 996 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 997 | if (TypoCorrection Corrected = CorrectTypo( |
| 998 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 999 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1000 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1001 | PDiag(Lookup.empty() |
| 1002 | ? diag::err_undeclared_var_use_suggest |
| 1003 | : diag::err_omp_expected_var_arg_suggest) |
| 1004 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1005 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1006 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1007 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1008 | : diag::err_omp_expected_var_arg) |
| 1009 | << Id.getName(); |
| 1010 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1011 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1012 | } else { |
| 1013 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1014 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1015 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1016 | return ExprError(); |
| 1017 | } |
| 1018 | } |
| 1019 | Lookup.suppressDiagnostics(); |
| 1020 | |
| 1021 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1022 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1023 | if (!VD->hasGlobalStorage()) { |
| 1024 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1025 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1026 | bool IsDecl = |
| 1027 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1028 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1029 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1030 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1031 | return ExprError(); |
| 1032 | } |
| 1033 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1034 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1035 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1036 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1037 | // A threadprivate directive for file-scope variables must appear outside |
| 1038 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1039 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1040 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1041 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1042 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1043 | bool IsDecl = |
| 1044 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1045 | Diag(VD->getLocation(), |
| 1046 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1047 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1048 | return ExprError(); |
| 1049 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1050 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1051 | // A threadprivate directive for static class member variables must appear |
| 1052 | // in the class definition, in the same scope in which the member |
| 1053 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1054 | if (CanonicalVD->isStaticDataMember() && |
| 1055 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1056 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1057 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1058 | bool IsDecl = |
| 1059 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1060 | Diag(VD->getLocation(), |
| 1061 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1062 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1063 | return ExprError(); |
| 1064 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1065 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1066 | // A threadprivate directive for namespace-scope variables must appear |
| 1067 | // outside any definition or declaration other than the namespace |
| 1068 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1069 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1070 | (!getCurLexicalContext()->isFileContext() || |
| 1071 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1072 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1073 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1074 | bool IsDecl = |
| 1075 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1076 | Diag(VD->getLocation(), |
| 1077 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1078 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1079 | return ExprError(); |
| 1080 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1081 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1082 | // A threadprivate directive for static block-scope variables must appear |
| 1083 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1084 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1085 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1086 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1087 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1088 | bool IsDecl = |
| 1089 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1090 | Diag(VD->getLocation(), |
| 1091 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1092 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1093 | return ExprError(); |
| 1094 | } |
| 1095 | |
| 1096 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1097 | // A threadprivate directive must lexically precede all references to any |
| 1098 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1099 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1100 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1101 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1102 | return ExprError(); |
| 1103 | } |
| 1104 | |
| 1105 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1106 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1107 | return DE; |
| 1108 | } |
| 1109 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1110 | Sema::DeclGroupPtrTy |
| 1111 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1112 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1113 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1114 | CurContext->addDecl(D); |
| 1115 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1116 | } |
| 1117 | return DeclGroupPtrTy(); |
| 1118 | } |
| 1119 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1120 | namespace { |
| 1121 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1122 | Sema &SemaRef; |
| 1123 | |
| 1124 | public: |
| 1125 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1126 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1127 | if (VD->hasLocalStorage()) { |
| 1128 | SemaRef.Diag(E->getLocStart(), |
| 1129 | diag::err_omp_local_var_in_threadprivate_init) |
| 1130 | << E->getSourceRange(); |
| 1131 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1132 | << VD << VD->getSourceRange(); |
| 1133 | return true; |
| 1134 | } |
| 1135 | } |
| 1136 | return false; |
| 1137 | } |
| 1138 | bool VisitStmt(const Stmt *S) { |
| 1139 | for (auto Child : S->children()) { |
| 1140 | if (Child && Visit(Child)) |
| 1141 | return true; |
| 1142 | } |
| 1143 | return false; |
| 1144 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1145 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1146 | }; |
| 1147 | } // namespace |
| 1148 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1149 | OMPThreadPrivateDecl * |
| 1150 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1151 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1152 | for (auto &RefExpr : VarList) { |
| 1153 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1154 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1155 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1156 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1157 | QualType QType = VD->getType(); |
| 1158 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1159 | // It will be analyzed later. |
| 1160 | Vars.push_back(DE); |
| 1161 | continue; |
| 1162 | } |
| 1163 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1164 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1165 | // A threadprivate variable must not have an incomplete type. |
| 1166 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1167 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1168 | continue; |
| 1169 | } |
| 1170 | |
| 1171 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1172 | // A threadprivate variable must not have a reference type. |
| 1173 | if (VD->getType()->isReferenceType()) { |
| 1174 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1175 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1176 | bool IsDecl = |
| 1177 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1178 | Diag(VD->getLocation(), |
| 1179 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1180 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1181 | continue; |
| 1182 | } |
| 1183 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1184 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1185 | // the corresponding diagnostic. |
| 1186 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1187 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1188 | getLangOpts().OpenMPUseTLS && |
| 1189 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1190 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1191 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1192 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1193 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1194 | bool IsDecl = |
| 1195 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1196 | Diag(VD->getLocation(), |
| 1197 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1198 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1199 | continue; |
| 1200 | } |
| 1201 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1202 | // Check if initial value of threadprivate variable reference variable with |
| 1203 | // local storage (it is not supported by runtime). |
| 1204 | if (auto Init = VD->getAnyInitializer()) { |
| 1205 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1206 | if (Checker.Visit(Init)) |
| 1207 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1210 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1211 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1212 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1213 | Context, SourceRange(Loc, Loc))); |
| 1214 | if (auto *ML = Context.getASTMutationListener()) |
| 1215 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1216 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1217 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1218 | if (!Vars.empty()) { |
| 1219 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1220 | Vars); |
| 1221 | D->setAccess(AS_public); |
| 1222 | } |
| 1223 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1224 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1225 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1226 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1227 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1228 | bool IsLoopIterVar = false) { |
| 1229 | if (DVar.RefExpr) { |
| 1230 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1231 | << getOpenMPClauseName(DVar.CKind); |
| 1232 | return; |
| 1233 | } |
| 1234 | enum { |
| 1235 | PDSA_StaticMemberShared, |
| 1236 | PDSA_StaticLocalVarShared, |
| 1237 | PDSA_LoopIterVarPrivate, |
| 1238 | PDSA_LoopIterVarLinear, |
| 1239 | PDSA_LoopIterVarLastprivate, |
| 1240 | PDSA_ConstVarShared, |
| 1241 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1242 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1243 | PDSA_LocalVarPrivate, |
| 1244 | PDSA_Implicit |
| 1245 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1246 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1247 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1248 | if (IsLoopIterVar) { |
| 1249 | if (DVar.CKind == OMPC_private) |
| 1250 | Reason = PDSA_LoopIterVarPrivate; |
| 1251 | else if (DVar.CKind == OMPC_lastprivate) |
| 1252 | Reason = PDSA_LoopIterVarLastprivate; |
| 1253 | else |
| 1254 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1255 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1256 | Reason = PDSA_TaskVarFirstprivate; |
| 1257 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1258 | } else if (VD->isStaticLocal()) |
| 1259 | Reason = PDSA_StaticLocalVarShared; |
| 1260 | else if (VD->isStaticDataMember()) |
| 1261 | Reason = PDSA_StaticMemberShared; |
| 1262 | else if (VD->isFileVarDecl()) |
| 1263 | Reason = PDSA_GlobalVarShared; |
| 1264 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1265 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1266 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1267 | ReportHint = true; |
| 1268 | Reason = PDSA_LocalVarPrivate; |
| 1269 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1270 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1271 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1272 | << Reason << ReportHint |
| 1273 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1274 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1275 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1276 | << getOpenMPClauseName(DVar.CKind); |
| 1277 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1280 | namespace { |
| 1281 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1282 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1283 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1284 | bool ErrorFound; |
| 1285 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1286 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1287 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1288 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1289 | public: |
| 1290 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1291 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1292 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1293 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1294 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1295 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1296 | auto DVar = Stack->getTopDSA(VD, false); |
| 1297 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1298 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1299 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1300 | auto ELoc = E->getExprLoc(); |
| 1301 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1302 | // The default(none) clause requires that each variable that is referenced |
| 1303 | // in the construct, and does not have a predetermined data-sharing |
| 1304 | // attribute, must have its data-sharing attribute explicitly determined |
| 1305 | // by being listed in a data-sharing attribute clause. |
| 1306 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1307 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1308 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1309 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1314 | // A list item that appears in a reduction clause of the innermost |
| 1315 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1316 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1317 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1318 | [](OpenMPDirectiveKind K) -> bool { |
| 1319 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1320 | isOpenMPWorksharingDirective(K) || |
| 1321 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1322 | }, |
| 1323 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1324 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1325 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1326 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1327 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1328 | return; |
| 1329 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1330 | |
| 1331 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1332 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1333 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1334 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1338 | for (auto *C : S->clauses()) { |
| 1339 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1340 | // for task directives. |
| 1341 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1342 | for (auto *CC : C->children()) { |
| 1343 | if (CC) |
| 1344 | Visit(CC); |
| 1345 | } |
| 1346 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1347 | } |
| 1348 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1349 | for (auto *C : S->children()) { |
| 1350 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1351 | Visit(C); |
| 1352 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1353 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1354 | |
| 1355 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1356 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1357 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1358 | return VarsWithInheritedDSA; |
| 1359 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1360 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1361 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1362 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1363 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1364 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1365 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1366 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1367 | switch (DKind) { |
| 1368 | case OMPD_parallel: { |
| 1369 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1370 | QualType KmpInt32PtrTy = |
| 1371 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1372 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1373 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1374 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1375 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1376 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1377 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1378 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | } |
| 1381 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1382 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1383 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1384 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1385 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1386 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1387 | break; |
| 1388 | } |
| 1389 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1390 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1391 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1392 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1393 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1394 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1395 | break; |
| 1396 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1397 | case OMPD_for_simd: { |
| 1398 | Sema::CapturedParamNameType Params[] = { |
| 1399 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1400 | }; |
| 1401 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1402 | Params); |
| 1403 | break; |
| 1404 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1405 | case OMPD_sections: { |
| 1406 | Sema::CapturedParamNameType Params[] = { |
| 1407 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1408 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1409 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1410 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1411 | break; |
| 1412 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1413 | case OMPD_section: { |
| 1414 | Sema::CapturedParamNameType Params[] = { |
| 1415 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1416 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1417 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1418 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1419 | break; |
| 1420 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1421 | case OMPD_single: { |
| 1422 | Sema::CapturedParamNameType Params[] = { |
| 1423 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1424 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1425 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1426 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1429 | case OMPD_master: { |
| 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 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1437 | case OMPD_critical: { |
| 1438 | Sema::CapturedParamNameType Params[] = { |
| 1439 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1440 | }; |
| 1441 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1442 | Params); |
| 1443 | break; |
| 1444 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1445 | case OMPD_parallel_for: { |
| 1446 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1447 | QualType KmpInt32PtrTy = |
| 1448 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1449 | Sema::CapturedParamNameType Params[] = { |
| 1450 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1451 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1452 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1453 | }; |
| 1454 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1455 | Params); |
| 1456 | break; |
| 1457 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1458 | case OMPD_parallel_for_simd: { |
| 1459 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1460 | QualType KmpInt32PtrTy = |
| 1461 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1462 | Sema::CapturedParamNameType Params[] = { |
| 1463 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1464 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1465 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1466 | }; |
| 1467 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1468 | Params); |
| 1469 | break; |
| 1470 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1471 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1472 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1473 | QualType KmpInt32PtrTy = |
| 1474 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1475 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1476 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1477 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1478 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1479 | }; |
| 1480 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1481 | Params); |
| 1482 | break; |
| 1483 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1484 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1485 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1486 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1487 | FunctionProtoType::ExtProtoInfo EPI; |
| 1488 | EPI.Variadic = true; |
| 1489 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1490 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1491 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1492 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1493 | std::make_pair(".privates.", |
| 1494 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1495 | std::make_pair( |
| 1496 | ".copy_fn.", |
| 1497 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1498 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1499 | }; |
| 1500 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1501 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1502 | // Mark this captured region as inlined, because we don't use outlined |
| 1503 | // function directly. |
| 1504 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1505 | AlwaysInlineAttr::CreateImplicit( |
| 1506 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1507 | break; |
| 1508 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1509 | case OMPD_ordered: { |
| 1510 | Sema::CapturedParamNameType Params[] = { |
| 1511 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1512 | }; |
| 1513 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1514 | Params); |
| 1515 | break; |
| 1516 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1517 | case OMPD_atomic: { |
| 1518 | Sema::CapturedParamNameType Params[] = { |
| 1519 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1520 | }; |
| 1521 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1522 | Params); |
| 1523 | break; |
| 1524 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1525 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1526 | case OMPD_target: { |
| 1527 | Sema::CapturedParamNameType Params[] = { |
| 1528 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1529 | }; |
| 1530 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1531 | Params); |
| 1532 | break; |
| 1533 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1534 | case OMPD_teams: { |
| 1535 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1536 | QualType KmpInt32PtrTy = |
| 1537 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1538 | Sema::CapturedParamNameType Params[] = { |
| 1539 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1540 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1541 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1542 | }; |
| 1543 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1544 | Params); |
| 1545 | break; |
| 1546 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1547 | case OMPD_taskgroup: { |
| 1548 | Sema::CapturedParamNameType Params[] = { |
| 1549 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1550 | }; |
| 1551 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1552 | Params); |
| 1553 | break; |
| 1554 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1555 | case OMPD_taskloop: { |
| 1556 | Sema::CapturedParamNameType Params[] = { |
| 1557 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1558 | }; |
| 1559 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1560 | Params); |
| 1561 | break; |
| 1562 | } |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1563 | case OMPD_taskloop_simd: { |
| 1564 | Sema::CapturedParamNameType Params[] = { |
| 1565 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1566 | }; |
| 1567 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1568 | Params); |
| 1569 | break; |
| 1570 | } |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1571 | case OMPD_distribute: { |
| 1572 | Sema::CapturedParamNameType Params[] = { |
| 1573 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1574 | }; |
| 1575 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1576 | Params); |
| 1577 | break; |
| 1578 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1579 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1580 | case OMPD_taskyield: |
| 1581 | case OMPD_barrier: |
| 1582 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1583 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1584 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1585 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1586 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1587 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1588 | llvm_unreachable("Unknown OpenMP directive"); |
| 1589 | } |
| 1590 | } |
| 1591 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1592 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1593 | ArrayRef<OMPClause *> Clauses) { |
| 1594 | if (!S.isUsable()) { |
| 1595 | ActOnCapturedRegionError(); |
| 1596 | return StmtError(); |
| 1597 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1598 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1599 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1600 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1601 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1602 | (getLangOpts().OpenMPUseTLS && |
| 1603 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1604 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1605 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1606 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1607 | for (auto *VarRef : Clause->children()) { |
| 1608 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1609 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1610 | } |
| 1611 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1612 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1613 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1614 | Clause->getClauseKind() == OMPC_schedule) { |
| 1615 | // Mark all variables in private list clauses as used in inner region. |
| 1616 | // Required for proper codegen of combined directives. |
| 1617 | // TODO: add processing for other clauses. |
| 1618 | if (auto *E = cast_or_null<Expr>( |
| 1619 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1620 | MarkDeclarationsReferencedInExpr(E); |
| 1621 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1622 | } |
| 1623 | } |
| 1624 | return ActOnCapturedRegionEnd(S.get()); |
| 1625 | } |
| 1626 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1627 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1628 | OpenMPDirectiveKind CurrentRegion, |
| 1629 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1630 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1631 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1632 | // Allowed nesting of constructs |
| 1633 | // +------------------+-----------------+------------------------------------+ |
| 1634 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1635 | // +------------------+-----------------+------------------------------------+ |
| 1636 | // | parallel | parallel | * | |
| 1637 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1638 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1639 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1640 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1641 | // | parallel | simd | * | |
| 1642 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1643 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1644 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1645 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1646 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1647 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1648 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1649 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1650 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1651 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1652 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1653 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1654 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1655 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1656 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1657 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1658 | // | parallel | cancellation | | |
| 1659 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1660 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1661 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1662 | // | parallel | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1663 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1664 | // +------------------+-----------------+------------------------------------+ |
| 1665 | // | for | parallel | * | |
| 1666 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1667 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1668 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1669 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1670 | // | for | simd | * | |
| 1671 | // | for | sections | + | |
| 1672 | // | for | section | + | |
| 1673 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1674 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1675 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1676 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1677 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1678 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1679 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1680 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1681 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1682 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1683 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1684 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1685 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1686 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1687 | // | for | cancellation | | |
| 1688 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1689 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1690 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1691 | // | for | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1692 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1693 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1694 | // | master | parallel | * | |
| 1695 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1696 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1697 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1698 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1699 | // | master | simd | * | |
| 1700 | // | master | sections | + | |
| 1701 | // | master | section | + | |
| 1702 | // | master | single | + | |
| 1703 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1704 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1705 | // | master |parallel sections| * | |
| 1706 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1707 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1708 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1709 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1710 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1711 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1712 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1713 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1714 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1715 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1716 | // | master | cancellation | | |
| 1717 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1718 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1719 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1720 | // | master | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1721 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1722 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1723 | // | critical | parallel | * | |
| 1724 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1725 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1726 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1727 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1728 | // | critical | simd | * | |
| 1729 | // | critical | sections | + | |
| 1730 | // | critical | section | + | |
| 1731 | // | critical | single | + | |
| 1732 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1733 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1734 | // | critical |parallel sections| * | |
| 1735 | // | critical | task | * | |
| 1736 | // | critical | taskyield | * | |
| 1737 | // | critical | barrier | + | |
| 1738 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1739 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1740 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1741 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1742 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1743 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1744 | // | critical | cancellation | | |
| 1745 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1746 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1747 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1748 | // | critical | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1749 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1750 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1751 | // | simd | parallel | | |
| 1752 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1753 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1754 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1755 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1756 | // | simd | simd | | |
| 1757 | // | simd | sections | | |
| 1758 | // | simd | section | | |
| 1759 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1760 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1761 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1762 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1763 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1764 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1765 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1766 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1767 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1768 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1769 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1770 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1771 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1772 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1773 | // | simd | cancellation | | |
| 1774 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1775 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1776 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1777 | // | simd | taskloop simd | | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1778 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1779 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1780 | // | for simd | parallel | | |
| 1781 | // | for simd | for | | |
| 1782 | // | for simd | for simd | | |
| 1783 | // | for simd | master | | |
| 1784 | // | for simd | critical | | |
| 1785 | // | for simd | simd | | |
| 1786 | // | for simd | sections | | |
| 1787 | // | for simd | section | | |
| 1788 | // | for simd | single | | |
| 1789 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1790 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1791 | // | for simd |parallel sections| | |
| 1792 | // | for simd | task | | |
| 1793 | // | for simd | taskyield | | |
| 1794 | // | for simd | barrier | | |
| 1795 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1796 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1797 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1798 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1799 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1800 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1801 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1802 | // | for simd | cancellation | | |
| 1803 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1804 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1805 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1806 | // | for simd | taskloop simd | | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1807 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1808 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1809 | // | parallel for simd| parallel | | |
| 1810 | // | parallel for simd| for | | |
| 1811 | // | parallel for simd| for simd | | |
| 1812 | // | parallel for simd| master | | |
| 1813 | // | parallel for simd| critical | | |
| 1814 | // | parallel for simd| simd | | |
| 1815 | // | parallel for simd| sections | | |
| 1816 | // | parallel for simd| section | | |
| 1817 | // | parallel for simd| single | | |
| 1818 | // | parallel for simd| parallel for | | |
| 1819 | // | parallel for simd|parallel for simd| | |
| 1820 | // | parallel for simd|parallel sections| | |
| 1821 | // | parallel for simd| task | | |
| 1822 | // | parallel for simd| taskyield | | |
| 1823 | // | parallel for simd| barrier | | |
| 1824 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1825 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1826 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1827 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1828 | // | parallel for simd| atomic | | |
| 1829 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1830 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1831 | // | parallel for simd| cancellation | | |
| 1832 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1833 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1834 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1835 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1836 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1837 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1838 | // | sections | parallel | * | |
| 1839 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1840 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1841 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1842 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1843 | // | sections | simd | * | |
| 1844 | // | sections | sections | + | |
| 1845 | // | sections | section | * | |
| 1846 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1847 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1848 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1849 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1850 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1851 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1852 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1853 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1854 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1855 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1856 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1857 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1858 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1859 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1860 | // | sections | cancellation | | |
| 1861 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1862 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1863 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1864 | // | sections | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1865 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1866 | // +------------------+-----------------+------------------------------------+ |
| 1867 | // | section | parallel | * | |
| 1868 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1869 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1870 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1871 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1872 | // | section | simd | * | |
| 1873 | // | section | sections | + | |
| 1874 | // | section | section | + | |
| 1875 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1876 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1877 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1878 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1879 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1880 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1881 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1882 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1883 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1884 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1885 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1886 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1887 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1888 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1889 | // | section | cancellation | | |
| 1890 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1891 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1892 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1893 | // | section | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1894 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1895 | // +------------------+-----------------+------------------------------------+ |
| 1896 | // | single | parallel | * | |
| 1897 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1898 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1899 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1900 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1901 | // | single | simd | * | |
| 1902 | // | single | sections | + | |
| 1903 | // | single | section | + | |
| 1904 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1905 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1906 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1907 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1908 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1909 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1910 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1911 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1912 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1913 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1914 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1915 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1916 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1917 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1918 | // | single | cancellation | | |
| 1919 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1920 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1921 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1922 | // | single | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1923 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1924 | // +------------------+-----------------+------------------------------------+ |
| 1925 | // | parallel for | parallel | * | |
| 1926 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1927 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1928 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1929 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1930 | // | parallel for | simd | * | |
| 1931 | // | parallel for | sections | + | |
| 1932 | // | parallel for | section | + | |
| 1933 | // | parallel for | single | + | |
| 1934 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1935 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1936 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1937 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1938 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1939 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1940 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1941 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1942 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1943 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1944 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1945 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1946 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1947 | // | parallel for | cancellation | | |
| 1948 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1949 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1950 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1951 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1952 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1953 | // +------------------+-----------------+------------------------------------+ |
| 1954 | // | parallel sections| parallel | * | |
| 1955 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1956 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1957 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1958 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1959 | // | parallel sections| simd | * | |
| 1960 | // | parallel sections| sections | + | |
| 1961 | // | parallel sections| section | * | |
| 1962 | // | parallel sections| single | + | |
| 1963 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1964 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1965 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1966 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1967 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1968 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1969 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1970 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1971 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1972 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1973 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1974 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1975 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1976 | // | parallel sections| cancellation | | |
| 1977 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1978 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1979 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1980 | // | parallel sections| taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 1981 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1982 | // +------------------+-----------------+------------------------------------+ |
| 1983 | // | task | parallel | * | |
| 1984 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1985 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1986 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1987 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1988 | // | task | simd | * | |
| 1989 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1990 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1991 | // | task | single | + | |
| 1992 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1993 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1994 | // | task |parallel sections| * | |
| 1995 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1996 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1997 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1998 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1999 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2000 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2001 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2002 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2003 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2004 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2005 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2006 | // | | point | ! | |
| 2007 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2008 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2009 | // | task | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2010 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2011 | // +------------------+-----------------+------------------------------------+ |
| 2012 | // | ordered | parallel | * | |
| 2013 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2014 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2015 | // | ordered | master | * | |
| 2016 | // | ordered | critical | * | |
| 2017 | // | ordered | simd | * | |
| 2018 | // | ordered | sections | + | |
| 2019 | // | ordered | section | + | |
| 2020 | // | ordered | single | + | |
| 2021 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2022 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2023 | // | ordered |parallel sections| * | |
| 2024 | // | ordered | task | * | |
| 2025 | // | ordered | taskyield | * | |
| 2026 | // | ordered | barrier | + | |
| 2027 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2028 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2029 | // | ordered | flush | * | |
| 2030 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2031 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2032 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2033 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2034 | // | ordered | cancellation | | |
| 2035 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2036 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2037 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2038 | // | ordered | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2039 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2040 | // +------------------+-----------------+------------------------------------+ |
| 2041 | // | atomic | parallel | | |
| 2042 | // | atomic | for | | |
| 2043 | // | atomic | for simd | | |
| 2044 | // | atomic | master | | |
| 2045 | // | atomic | critical | | |
| 2046 | // | atomic | simd | | |
| 2047 | // | atomic | sections | | |
| 2048 | // | atomic | section | | |
| 2049 | // | atomic | single | | |
| 2050 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2051 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2052 | // | atomic |parallel sections| | |
| 2053 | // | atomic | task | | |
| 2054 | // | atomic | taskyield | | |
| 2055 | // | atomic | barrier | | |
| 2056 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2057 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2058 | // | atomic | flush | | |
| 2059 | // | atomic | ordered | | |
| 2060 | // | atomic | atomic | | |
| 2061 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2062 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2063 | // | atomic | cancellation | | |
| 2064 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2065 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2066 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2067 | // | atomic | taskloop simd | | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2068 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2069 | // +------------------+-----------------+------------------------------------+ |
| 2070 | // | target | parallel | * | |
| 2071 | // | target | for | * | |
| 2072 | // | target | for simd | * | |
| 2073 | // | target | master | * | |
| 2074 | // | target | critical | * | |
| 2075 | // | target | simd | * | |
| 2076 | // | target | sections | * | |
| 2077 | // | target | section | * | |
| 2078 | // | target | single | * | |
| 2079 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2080 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2081 | // | target |parallel sections| * | |
| 2082 | // | target | task | * | |
| 2083 | // | target | taskyield | * | |
| 2084 | // | target | barrier | * | |
| 2085 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2086 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2087 | // | target | flush | * | |
| 2088 | // | target | ordered | * | |
| 2089 | // | target | atomic | * | |
| 2090 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2091 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2092 | // | target | cancellation | | |
| 2093 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2094 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2095 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2096 | // | target | taskloop simd | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2097 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2098 | // +------------------+-----------------+------------------------------------+ |
| 2099 | // | teams | parallel | * | |
| 2100 | // | teams | for | + | |
| 2101 | // | teams | for simd | + | |
| 2102 | // | teams | master | + | |
| 2103 | // | teams | critical | + | |
| 2104 | // | teams | simd | + | |
| 2105 | // | teams | sections | + | |
| 2106 | // | teams | section | + | |
| 2107 | // | teams | single | + | |
| 2108 | // | teams | parallel for | * | |
| 2109 | // | teams |parallel for simd| * | |
| 2110 | // | teams |parallel sections| * | |
| 2111 | // | teams | task | + | |
| 2112 | // | teams | taskyield | + | |
| 2113 | // | teams | barrier | + | |
| 2114 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2115 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2116 | // | teams | flush | + | |
| 2117 | // | teams | ordered | + | |
| 2118 | // | teams | atomic | + | |
| 2119 | // | teams | target | + | |
| 2120 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2121 | // | teams | cancellation | | |
| 2122 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2123 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2124 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2125 | // | teams | taskloop simd | + | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2126 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2127 | // +------------------+-----------------+------------------------------------+ |
| 2128 | // | taskloop | parallel | * | |
| 2129 | // | taskloop | for | + | |
| 2130 | // | taskloop | for simd | + | |
| 2131 | // | taskloop | master | + | |
| 2132 | // | taskloop | critical | * | |
| 2133 | // | taskloop | simd | * | |
| 2134 | // | taskloop | sections | + | |
| 2135 | // | taskloop | section | + | |
| 2136 | // | taskloop | single | + | |
| 2137 | // | taskloop | parallel for | * | |
| 2138 | // | taskloop |parallel for simd| * | |
| 2139 | // | taskloop |parallel sections| * | |
| 2140 | // | taskloop | task | * | |
| 2141 | // | taskloop | taskyield | * | |
| 2142 | // | taskloop | barrier | + | |
| 2143 | // | taskloop | taskwait | * | |
| 2144 | // | taskloop | taskgroup | * | |
| 2145 | // | taskloop | flush | * | |
| 2146 | // | taskloop | ordered | + | |
| 2147 | // | taskloop | atomic | * | |
| 2148 | // | taskloop | target | * | |
| 2149 | // | taskloop | teams | + | |
| 2150 | // | taskloop | cancellation | | |
| 2151 | // | | point | | |
| 2152 | // | taskloop | cancel | | |
| 2153 | // | taskloop | taskloop | * | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2154 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2155 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2156 | // | taskloop simd | parallel | | |
| 2157 | // | taskloop simd | for | | |
| 2158 | // | taskloop simd | for simd | | |
| 2159 | // | taskloop simd | master | | |
| 2160 | // | taskloop simd | critical | | |
| 2161 | // | taskloop simd | simd | | |
| 2162 | // | taskloop simd | sections | | |
| 2163 | // | taskloop simd | section | | |
| 2164 | // | taskloop simd | single | | |
| 2165 | // | taskloop simd | parallel for | | |
| 2166 | // | taskloop simd |parallel for simd| | |
| 2167 | // | taskloop simd |parallel sections| | |
| 2168 | // | taskloop simd | task | | |
| 2169 | // | taskloop simd | taskyield | | |
| 2170 | // | taskloop simd | barrier | | |
| 2171 | // | taskloop simd | taskwait | | |
| 2172 | // | taskloop simd | taskgroup | | |
| 2173 | // | taskloop simd | flush | | |
| 2174 | // | taskloop simd | ordered | + (with simd clause) | |
| 2175 | // | taskloop simd | atomic | | |
| 2176 | // | taskloop simd | target | | |
| 2177 | // | taskloop simd | teams | | |
| 2178 | // | taskloop simd | cancellation | | |
| 2179 | // | | point | | |
| 2180 | // | taskloop simd | cancel | | |
| 2181 | // | taskloop simd | taskloop | | |
| 2182 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2183 | // | taskloop simd | distribute | | |
| 2184 | // +------------------+-----------------+------------------------------------+ |
| 2185 | // | distribute | parallel | * | |
| 2186 | // | distribute | for | * | |
| 2187 | // | distribute | for simd | * | |
| 2188 | // | distribute | master | * | |
| 2189 | // | distribute | critical | * | |
| 2190 | // | distribute | simd | * | |
| 2191 | // | distribute | sections | * | |
| 2192 | // | distribute | section | * | |
| 2193 | // | distribute | single | * | |
| 2194 | // | distribute | parallel for | * | |
| 2195 | // | distribute |parallel for simd| * | |
| 2196 | // | distribute |parallel sections| * | |
| 2197 | // | distribute | task | * | |
| 2198 | // | distribute | taskyield | * | |
| 2199 | // | distribute | barrier | * | |
| 2200 | // | distribute | taskwait | * | |
| 2201 | // | distribute | taskgroup | * | |
| 2202 | // | distribute | flush | * | |
| 2203 | // | distribute | ordered | + | |
| 2204 | // | distribute | atomic | * | |
| 2205 | // | distribute | target | | |
| 2206 | // | distribute | teams | | |
| 2207 | // | distribute | cancellation | + | |
| 2208 | // | | point | | |
| 2209 | // | distribute | cancel | + | |
| 2210 | // | distribute | taskloop | * | |
| 2211 | // | distribute | taskloop simd | * | |
| 2212 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2213 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2214 | if (Stack->getCurScope()) { |
| 2215 | auto ParentRegion = Stack->getParentDirective(); |
| 2216 | bool NestingProhibited = false; |
| 2217 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2218 | enum { |
| 2219 | NoRecommend, |
| 2220 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2221 | ShouldBeInOrderedRegion, |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2222 | ShouldBeInTargetRegion, |
| 2223 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2224 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2225 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2226 | // OpenMP [2.16, Nesting of Regions] |
| 2227 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2228 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2229 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2230 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2231 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2232 | return true; |
| 2233 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2234 | if (ParentRegion == OMPD_atomic) { |
| 2235 | // OpenMP [2.16, Nesting of Regions] |
| 2236 | // OpenMP constructs may not be nested inside an atomic region. |
| 2237 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2238 | return true; |
| 2239 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2240 | if (CurrentRegion == OMPD_section) { |
| 2241 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2242 | // Orphaned section directives are prohibited. That is, the section |
| 2243 | // directives must appear within the sections construct and must not be |
| 2244 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2245 | if (ParentRegion != OMPD_sections && |
| 2246 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2247 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2248 | << (ParentRegion != OMPD_unknown) |
| 2249 | << getOpenMPDirectiveName(ParentRegion); |
| 2250 | return true; |
| 2251 | } |
| 2252 | return false; |
| 2253 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2254 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2255 | // called from OpenMP regions with the required preconditions). |
| 2256 | if (ParentRegion == OMPD_unknown) |
| 2257 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2258 | if (CurrentRegion == OMPD_cancellation_point || |
| 2259 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2260 | // OpenMP [2.16, Nesting of Regions] |
| 2261 | // A cancellation point construct for which construct-type-clause is |
| 2262 | // taskgroup must be nested inside a task construct. A cancellation |
| 2263 | // point construct for which construct-type-clause is not taskgroup must |
| 2264 | // be closely nested inside an OpenMP construct that matches the type |
| 2265 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2266 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2267 | // nested inside a task construct. A cancel construct for which |
| 2268 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2269 | // OpenMP construct that matches the type specified in |
| 2270 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2271 | NestingProhibited = |
| 2272 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2273 | (CancelRegion == OMPD_for && |
| 2274 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2275 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2276 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2277 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2278 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2279 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2280 | // OpenMP [2.16, Nesting of Regions] |
| 2281 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2282 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2283 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2284 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2285 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2286 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2287 | // OpenMP [2.16, Nesting of Regions] |
| 2288 | // A critical region may not be nested (closely or otherwise) inside a |
| 2289 | // critical region with the same name. Note that this restriction is not |
| 2290 | // sufficient to prevent deadlock. |
| 2291 | SourceLocation PreviousCriticalLoc; |
| 2292 | bool DeadLock = |
| 2293 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2294 | OpenMPDirectiveKind K, |
| 2295 | const DeclarationNameInfo &DNI, |
| 2296 | SourceLocation Loc) |
| 2297 | ->bool { |
| 2298 | if (K == OMPD_critical && |
| 2299 | DNI.getName() == CurrentName.getName()) { |
| 2300 | PreviousCriticalLoc = Loc; |
| 2301 | return true; |
| 2302 | } else |
| 2303 | return false; |
| 2304 | }, |
| 2305 | false /* skip top directive */); |
| 2306 | if (DeadLock) { |
| 2307 | SemaRef.Diag(StartLoc, |
| 2308 | diag::err_omp_prohibited_region_critical_same_name) |
| 2309 | << CurrentName.getName(); |
| 2310 | if (PreviousCriticalLoc.isValid()) |
| 2311 | SemaRef.Diag(PreviousCriticalLoc, |
| 2312 | diag::note_omp_previous_critical_region); |
| 2313 | return true; |
| 2314 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2315 | } else if (CurrentRegion == OMPD_barrier) { |
| 2316 | // OpenMP [2.16, Nesting of Regions] |
| 2317 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2318 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2319 | NestingProhibited = |
| 2320 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2321 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2322 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2323 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2324 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2325 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2326 | // OpenMP [2.16, Nesting of Regions] |
| 2327 | // A worksharing region may not be closely nested inside a worksharing, |
| 2328 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2329 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2330 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2331 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2332 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2333 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2334 | Recommend = ShouldBeInParallelRegion; |
| 2335 | } else if (CurrentRegion == OMPD_ordered) { |
| 2336 | // OpenMP [2.16, Nesting of Regions] |
| 2337 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2338 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2339 | // An ordered region must be closely nested inside a loop region (or |
| 2340 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2341 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2342 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2343 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2344 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2345 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2346 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2347 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2348 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2349 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2350 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2351 | // OpenMP [2.16, Nesting of Regions] |
| 2352 | // If specified, a teams construct must be contained within a target |
| 2353 | // construct. |
| 2354 | NestingProhibited = ParentRegion != OMPD_target; |
| 2355 | Recommend = ShouldBeInTargetRegion; |
| 2356 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2357 | } |
| 2358 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2359 | // OpenMP [2.16, Nesting of Regions] |
| 2360 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2361 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2362 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2363 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2364 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2365 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2366 | } |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2367 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2368 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2369 | // The region associated with the distribute construct must be strictly |
| 2370 | // nested inside a teams region |
| 2371 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2372 | Recommend = ShouldBeInTeamsRegion; |
| 2373 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2374 | if (NestingProhibited) { |
| 2375 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2376 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2377 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2378 | return true; |
| 2379 | } |
| 2380 | } |
| 2381 | return false; |
| 2382 | } |
| 2383 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2384 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2385 | ArrayRef<OMPClause *> Clauses, |
| 2386 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2387 | bool ErrorFound = false; |
| 2388 | unsigned NamedModifiersNumber = 0; |
| 2389 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2390 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2391 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2392 | for (const auto *C : Clauses) { |
| 2393 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2394 | // At most one if clause without a directive-name-modifier can appear on |
| 2395 | // the directive. |
| 2396 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2397 | if (FoundNameModifiers[CurNM]) { |
| 2398 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2399 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2400 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2401 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2402 | } else if (CurNM != OMPD_unknown) { |
| 2403 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2404 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2405 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2406 | FoundNameModifiers[CurNM] = IC; |
| 2407 | if (CurNM == OMPD_unknown) |
| 2408 | continue; |
| 2409 | // Check if the specified name modifier is allowed for the current |
| 2410 | // directive. |
| 2411 | // At most one if clause with the particular directive-name-modifier can |
| 2412 | // appear on the directive. |
| 2413 | bool MatchFound = false; |
| 2414 | for (auto NM : AllowedNameModifiers) { |
| 2415 | if (CurNM == NM) { |
| 2416 | MatchFound = true; |
| 2417 | break; |
| 2418 | } |
| 2419 | } |
| 2420 | if (!MatchFound) { |
| 2421 | S.Diag(IC->getNameModifierLoc(), |
| 2422 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2423 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2424 | ErrorFound = true; |
| 2425 | } |
| 2426 | } |
| 2427 | } |
| 2428 | // If any if clause on the directive includes a directive-name-modifier then |
| 2429 | // all if clauses on the directive must include a directive-name-modifier. |
| 2430 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2431 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2432 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2433 | diag::err_omp_no_more_if_clause); |
| 2434 | } else { |
| 2435 | std::string Values; |
| 2436 | std::string Sep(", "); |
| 2437 | unsigned AllowedCnt = 0; |
| 2438 | unsigned TotalAllowedNum = |
| 2439 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2440 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2441 | ++Cnt) { |
| 2442 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2443 | if (!FoundNameModifiers[NM]) { |
| 2444 | Values += "'"; |
| 2445 | Values += getOpenMPDirectiveName(NM); |
| 2446 | Values += "'"; |
| 2447 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2448 | Values += " or "; |
| 2449 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2450 | Values += Sep; |
| 2451 | ++AllowedCnt; |
| 2452 | } |
| 2453 | } |
| 2454 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2455 | diag::err_omp_unnamed_if_clause) |
| 2456 | << (TotalAllowedNum > 1) << Values; |
| 2457 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2458 | for (auto Loc : NameModifierLoc) { |
| 2459 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2460 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2461 | ErrorFound = true; |
| 2462 | } |
| 2463 | return ErrorFound; |
| 2464 | } |
| 2465 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2466 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2467 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2468 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2469 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2470 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2471 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2472 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2473 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2474 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2475 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2476 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2477 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2478 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2479 | if (AStmt) { |
| 2480 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2481 | |
| 2482 | // Check default data sharing attributes for referenced variables. |
| 2483 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2484 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2485 | if (DSAChecker.isErrorFound()) |
| 2486 | return StmtError(); |
| 2487 | // Generate list of implicitly defined firstprivate variables. |
| 2488 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2489 | |
| 2490 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2491 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2492 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2493 | SourceLocation(), SourceLocation())) { |
| 2494 | ClausesWithImplicit.push_back(Implicit); |
| 2495 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2496 | DSAChecker.getImplicitFirstprivate().size(); |
| 2497 | } else |
| 2498 | ErrorFound = true; |
| 2499 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2500 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2501 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2502 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2503 | switch (Kind) { |
| 2504 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2505 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2506 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2507 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2508 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2509 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2510 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2511 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2512 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2513 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2514 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2515 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2516 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2517 | case OMPD_for_simd: |
| 2518 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2519 | EndLoc, VarsWithInheritedDSA); |
| 2520 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2521 | case OMPD_sections: |
| 2522 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2523 | EndLoc); |
| 2524 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2525 | case OMPD_section: |
| 2526 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2527 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2528 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2529 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2530 | case OMPD_single: |
| 2531 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2532 | EndLoc); |
| 2533 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2534 | case OMPD_master: |
| 2535 | assert(ClausesWithImplicit.empty() && |
| 2536 | "No clauses are allowed for 'omp master' directive"); |
| 2537 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2538 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2539 | case OMPD_critical: |
| 2540 | assert(ClausesWithImplicit.empty() && |
| 2541 | "No clauses are allowed for 'omp critical' directive"); |
| 2542 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2543 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2544 | case OMPD_parallel_for: |
| 2545 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2546 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2547 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2548 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2549 | case OMPD_parallel_for_simd: |
| 2550 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2551 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2552 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2553 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2554 | case OMPD_parallel_sections: |
| 2555 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2556 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2557 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2558 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2559 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2560 | Res = |
| 2561 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2562 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2563 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2564 | case OMPD_taskyield: |
| 2565 | assert(ClausesWithImplicit.empty() && |
| 2566 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2567 | assert(AStmt == nullptr && |
| 2568 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2569 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2570 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2571 | case OMPD_barrier: |
| 2572 | assert(ClausesWithImplicit.empty() && |
| 2573 | "No clauses are allowed for 'omp barrier' directive"); |
| 2574 | assert(AStmt == nullptr && |
| 2575 | "No associated statement allowed for 'omp barrier' directive"); |
| 2576 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2577 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2578 | case OMPD_taskwait: |
| 2579 | assert(ClausesWithImplicit.empty() && |
| 2580 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2581 | assert(AStmt == nullptr && |
| 2582 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2583 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2584 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2585 | case OMPD_taskgroup: |
| 2586 | assert(ClausesWithImplicit.empty() && |
| 2587 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2588 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2589 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2590 | case OMPD_flush: |
| 2591 | assert(AStmt == nullptr && |
| 2592 | "No associated statement allowed for 'omp flush' directive"); |
| 2593 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2594 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2595 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2596 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2597 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2598 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2599 | case OMPD_atomic: |
| 2600 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2601 | EndLoc); |
| 2602 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2603 | case OMPD_teams: |
| 2604 | Res = |
| 2605 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2606 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2607 | case OMPD_target: |
| 2608 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2609 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2610 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2611 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2612 | case OMPD_cancellation_point: |
| 2613 | assert(ClausesWithImplicit.empty() && |
| 2614 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2615 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2616 | "cancellation point' directive"); |
| 2617 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2618 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2619 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2620 | assert(AStmt == nullptr && |
| 2621 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2622 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2623 | CancelRegion); |
| 2624 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2625 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2626 | case OMPD_target_data: |
| 2627 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2628 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2629 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2630 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2631 | case OMPD_taskloop: |
| 2632 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2633 | EndLoc, VarsWithInheritedDSA); |
| 2634 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2635 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2636 | case OMPD_taskloop_simd: |
| 2637 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2638 | EndLoc, VarsWithInheritedDSA); |
| 2639 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2640 | break; |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 2641 | case OMPD_distribute: |
| 2642 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2643 | EndLoc, VarsWithInheritedDSA); |
| 2644 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2645 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2646 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2647 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2648 | llvm_unreachable("Unknown OpenMP directive"); |
| 2649 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2650 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2651 | for (auto P : VarsWithInheritedDSA) { |
| 2652 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2653 | << P.first << P.second->getSourceRange(); |
| 2654 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2655 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2656 | |
| 2657 | if (!AllowedNameModifiers.empty()) |
| 2658 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2659 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2660 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2661 | if (ErrorFound) |
| 2662 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2663 | return Res; |
| 2664 | } |
| 2665 | |
| 2666 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2667 | Stmt *AStmt, |
| 2668 | SourceLocation StartLoc, |
| 2669 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2670 | if (!AStmt) |
| 2671 | return StmtError(); |
| 2672 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2673 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2674 | // 1.2.2 OpenMP Language Terminology |
| 2675 | // Structured block - An executable statement with a single entry at the |
| 2676 | // top and a single exit at the bottom. |
| 2677 | // The point of exit cannot be a branch out of the structured block. |
| 2678 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2679 | CS->getCapturedDecl()->setNothrow(); |
| 2680 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2681 | getCurFunction()->setHasBranchProtectedScope(); |
| 2682 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2683 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2684 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2685 | } |
| 2686 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2687 | namespace { |
| 2688 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2689 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2690 | /// for IR generation. |
| 2691 | class OpenMPIterationSpaceChecker { |
| 2692 | /// \brief Reference to Sema. |
| 2693 | Sema &SemaRef; |
| 2694 | /// \brief A location for diagnostics (when there is no some better location). |
| 2695 | SourceLocation DefaultLoc; |
| 2696 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2697 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2698 | /// \brief A source location for referring to loop init later. |
| 2699 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2700 | /// \brief A source location for referring to condition later. |
| 2701 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2702 | /// \brief A source location for referring to increment later. |
| 2703 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2704 | /// \brief Loop variable. |
| 2705 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2706 | /// \brief Reference to loop variable. |
| 2707 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2708 | /// \brief Lower bound (initializer for the var). |
| 2709 | Expr *LB; |
| 2710 | /// \brief Upper bound. |
| 2711 | Expr *UB; |
| 2712 | /// \brief Loop step (increment). |
| 2713 | Expr *Step; |
| 2714 | /// \brief This flag is true when condition is one of: |
| 2715 | /// Var < UB |
| 2716 | /// Var <= UB |
| 2717 | /// UB > Var |
| 2718 | /// UB >= Var |
| 2719 | bool TestIsLessOp; |
| 2720 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2721 | bool TestIsStrictOp; |
| 2722 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2723 | bool SubtractStep; |
| 2724 | |
| 2725 | public: |
| 2726 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2727 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2728 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2729 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2730 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2731 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2732 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2733 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2734 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2735 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2736 | /// for less/greater and for strict/non-strict comparison. |
| 2737 | bool CheckCond(Expr *S); |
| 2738 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2739 | /// does not conform, otherwise save loop step (#Step). |
| 2740 | bool CheckInc(Expr *S); |
| 2741 | /// \brief Return the loop counter variable. |
| 2742 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2743 | /// \brief Return the reference expression to loop counter variable. |
| 2744 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2745 | /// \brief Source range of the loop init. |
| 2746 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2747 | /// \brief Source range of the loop condition. |
| 2748 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2749 | /// \brief Source range of the loop increment. |
| 2750 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2751 | /// \brief True if the step should be subtracted. |
| 2752 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2753 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2754 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2755 | /// \brief Build the precondition expression for the loops. |
| 2756 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2757 | /// \brief Build reference expression to the counter be used for codegen. |
| 2758 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2759 | /// \brief Build reference expression to the private counter be used for |
| 2760 | /// codegen. |
| 2761 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2762 | /// \brief Build initization of the counter be used for codegen. |
| 2763 | Expr *BuildCounterInit() const; |
| 2764 | /// \brief Build step of the counter be used for codegen. |
| 2765 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2766 | /// \brief Return true if any expression is dependent. |
| 2767 | bool Dependent() const; |
| 2768 | |
| 2769 | private: |
| 2770 | /// \brief Check the right-hand side of an assignment in the increment |
| 2771 | /// expression. |
| 2772 | bool CheckIncRHS(Expr *RHS); |
| 2773 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2774 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2775 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2776 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2777 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2778 | /// \brief Helper to set loop increment. |
| 2779 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2780 | }; |
| 2781 | |
| 2782 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2783 | if (!Var) { |
| 2784 | assert(!LB && !UB && !Step); |
| 2785 | return false; |
| 2786 | } |
| 2787 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2788 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2789 | } |
| 2790 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2791 | template <typename T> |
| 2792 | static T *getExprAsWritten(T *E) { |
| 2793 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2794 | E = ExprTemp->getSubExpr(); |
| 2795 | |
| 2796 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2797 | E = MTE->GetTemporaryExpr(); |
| 2798 | |
| 2799 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2800 | E = Binder->getSubExpr(); |
| 2801 | |
| 2802 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2803 | E = ICE->getSubExprAsWritten(); |
| 2804 | return E->IgnoreParens(); |
| 2805 | } |
| 2806 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2807 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2808 | DeclRefExpr *NewVarRefExpr, |
| 2809 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2810 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2811 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2812 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2813 | if (!NewVar || !NewLB) |
| 2814 | return true; |
| 2815 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2816 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2817 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2818 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2819 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2820 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2821 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2822 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2823 | LB = NewLB; |
| 2824 | return false; |
| 2825 | } |
| 2826 | |
| 2827 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2828 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2829 | // State consistency checking to ensure correct usage. |
| 2830 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2831 | !TestIsLessOp && !TestIsStrictOp); |
| 2832 | if (!NewUB) |
| 2833 | return true; |
| 2834 | UB = NewUB; |
| 2835 | TestIsLessOp = LessOp; |
| 2836 | TestIsStrictOp = StrictOp; |
| 2837 | ConditionSrcRange = SR; |
| 2838 | ConditionLoc = SL; |
| 2839 | return false; |
| 2840 | } |
| 2841 | |
| 2842 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2843 | // State consistency checking to ensure correct usage. |
| 2844 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2845 | if (!NewStep) |
| 2846 | return true; |
| 2847 | if (!NewStep->isValueDependent()) { |
| 2848 | // Check that the step is integer expression. |
| 2849 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2850 | ExprResult Val = |
| 2851 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2852 | if (Val.isInvalid()) |
| 2853 | return true; |
| 2854 | NewStep = Val.get(); |
| 2855 | |
| 2856 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2857 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2858 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2859 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2860 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2861 | // the loop. |
| 2862 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2863 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2864 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2865 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2866 | // the loop. |
| 2867 | llvm::APSInt Result; |
| 2868 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2869 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2870 | bool IsConstNeg = |
| 2871 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2872 | bool IsConstPos = |
| 2873 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2874 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2875 | if (UB && (IsConstZero || |
| 2876 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2877 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2878 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2879 | diag::err_omp_loop_incr_not_compatible) |
| 2880 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2881 | SemaRef.Diag(ConditionLoc, |
| 2882 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2883 | << TestIsLessOp << ConditionSrcRange; |
| 2884 | return true; |
| 2885 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2886 | if (TestIsLessOp == Subtract) { |
| 2887 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2888 | NewStep).get(); |
| 2889 | Subtract = !Subtract; |
| 2890 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | Step = NewStep; |
| 2894 | SubtractStep = Subtract; |
| 2895 | return false; |
| 2896 | } |
| 2897 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2898 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2899 | // Check init-expr for canonical loop form and save loop counter |
| 2900 | // variable - #Var and its initialization value - #LB. |
| 2901 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2902 | // var = lb |
| 2903 | // integer-type var = lb |
| 2904 | // random-access-iterator-type var = lb |
| 2905 | // pointer-type var = lb |
| 2906 | // |
| 2907 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2908 | if (EmitDiags) { |
| 2909 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2910 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2911 | return true; |
| 2912 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2913 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2914 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2915 | S = E->IgnoreParens(); |
| 2916 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2917 | if (BO->getOpcode() == BO_Assign) |
| 2918 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2919 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2920 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2921 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2922 | if (DS->isSingleDecl()) { |
| 2923 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2924 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2925 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2926 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2927 | SemaRef.Diag(S->getLocStart(), |
| 2928 | diag::ext_omp_loop_not_canonical_init) |
| 2929 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2930 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2931 | } |
| 2932 | } |
| 2933 | } |
| 2934 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2935 | if (CE->getOperator() == OO_Equal) |
| 2936 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2937 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2938 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2939 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2940 | if (EmitDiags) { |
| 2941 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2942 | << S->getSourceRange(); |
| 2943 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2944 | return true; |
| 2945 | } |
| 2946 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2947 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2948 | /// variable (which may be the loop variable) if possible. |
| 2949 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2950 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2951 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2952 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2953 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2954 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2955 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2956 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2957 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2958 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2959 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2960 | if (!DRE) |
| 2961 | return nullptr; |
| 2962 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2963 | } |
| 2964 | |
| 2965 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2966 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2967 | // less/greater and for strict/non-strict comparison. |
| 2968 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2969 | // var relational-op b |
| 2970 | // b relational-op var |
| 2971 | // |
| 2972 | if (!S) { |
| 2973 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2974 | return true; |
| 2975 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2976 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2977 | SourceLocation CondLoc = S->getLocStart(); |
| 2978 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2979 | if (BO->isRelationalOp()) { |
| 2980 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2981 | return SetUB(BO->getRHS(), |
| 2982 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2983 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2984 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2985 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2986 | return SetUB(BO->getLHS(), |
| 2987 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2988 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2989 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2990 | } |
| 2991 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2992 | if (CE->getNumArgs() == 2) { |
| 2993 | auto Op = CE->getOperator(); |
| 2994 | switch (Op) { |
| 2995 | case OO_Greater: |
| 2996 | case OO_GreaterEqual: |
| 2997 | case OO_Less: |
| 2998 | case OO_LessEqual: |
| 2999 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3000 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3001 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3002 | CE->getOperatorLoc()); |
| 3003 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 3004 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3005 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3006 | CE->getOperatorLoc()); |
| 3007 | break; |
| 3008 | default: |
| 3009 | break; |
| 3010 | } |
| 3011 | } |
| 3012 | } |
| 3013 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 3014 | << S->getSourceRange() << Var; |
| 3015 | return true; |
| 3016 | } |
| 3017 | |
| 3018 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3019 | // RHS of canonical loop form increment can be: |
| 3020 | // var + incr |
| 3021 | // incr + var |
| 3022 | // var - incr |
| 3023 | // |
| 3024 | RHS = RHS->IgnoreParenImpCasts(); |
| 3025 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3026 | if (BO->isAdditiveOp()) { |
| 3027 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3028 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3029 | return SetStep(BO->getRHS(), !IsAdd); |
| 3030 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3031 | return SetStep(BO->getLHS(), false); |
| 3032 | } |
| 3033 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3034 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3035 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3036 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3037 | return SetStep(CE->getArg(1), !IsAdd); |
| 3038 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3039 | return SetStep(CE->getArg(0), false); |
| 3040 | } |
| 3041 | } |
| 3042 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3043 | << RHS->getSourceRange() << Var; |
| 3044 | return true; |
| 3045 | } |
| 3046 | |
| 3047 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3048 | // Check incr-expr for canonical loop form and return true if it |
| 3049 | // does not conform. |
| 3050 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3051 | // ++var |
| 3052 | // var++ |
| 3053 | // --var |
| 3054 | // var-- |
| 3055 | // var += incr |
| 3056 | // var -= incr |
| 3057 | // var = var + incr |
| 3058 | // var = incr + var |
| 3059 | // var = var - incr |
| 3060 | // |
| 3061 | if (!S) { |
| 3062 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3063 | return true; |
| 3064 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3065 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3066 | S = S->IgnoreParens(); |
| 3067 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3068 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3069 | return SetStep( |
| 3070 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3071 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3072 | false); |
| 3073 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3074 | switch (BO->getOpcode()) { |
| 3075 | case BO_AddAssign: |
| 3076 | case BO_SubAssign: |
| 3077 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3078 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3079 | break; |
| 3080 | case BO_Assign: |
| 3081 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3082 | return CheckIncRHS(BO->getRHS()); |
| 3083 | break; |
| 3084 | default: |
| 3085 | break; |
| 3086 | } |
| 3087 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3088 | switch (CE->getOperator()) { |
| 3089 | case OO_PlusPlus: |
| 3090 | case OO_MinusMinus: |
| 3091 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3092 | return SetStep( |
| 3093 | SemaRef.ActOnIntegerConstant( |
| 3094 | CE->getLocStart(), |
| 3095 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3096 | false); |
| 3097 | break; |
| 3098 | case OO_PlusEqual: |
| 3099 | case OO_MinusEqual: |
| 3100 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3101 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3102 | break; |
| 3103 | case OO_Equal: |
| 3104 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3105 | return CheckIncRHS(CE->getArg(1)); |
| 3106 | break; |
| 3107 | default: |
| 3108 | break; |
| 3109 | } |
| 3110 | } |
| 3111 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3112 | << S->getSourceRange() << Var; |
| 3113 | return true; |
| 3114 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3115 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3116 | namespace { |
| 3117 | // Transform variables declared in GNU statement expressions to new ones to |
| 3118 | // avoid crash on codegen. |
| 3119 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3120 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3121 | |
| 3122 | public: |
| 3123 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3124 | |
| 3125 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3126 | if (auto *VD = cast<VarDecl>(D)) |
| 3127 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3128 | !isa<ImplicitParamDecl>(D)) { |
| 3129 | auto *NewVD = VarDecl::Create( |
| 3130 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3131 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3132 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3133 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3134 | NewVD->setInit(VD->getInit()); |
| 3135 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3136 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3137 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3138 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3139 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3140 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3141 | NewVD->setPreviousDeclInSameBlockScope( |
| 3142 | VD->isPreviousDeclInSameBlockScope()); |
| 3143 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3144 | if (VD->hasAttrs()) |
| 3145 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3146 | transformedLocalDecl(VD, NewVD); |
| 3147 | return NewVD; |
| 3148 | } |
| 3149 | return BaseTransform::TransformDefinition(Loc, D); |
| 3150 | } |
| 3151 | |
| 3152 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3153 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3154 | if (E->getDecl() != NewD) { |
| 3155 | NewD->setReferenced(); |
| 3156 | NewD->markUsed(SemaRef.Context); |
| 3157 | return DeclRefExpr::Create( |
| 3158 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3159 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3160 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3161 | } |
| 3162 | return BaseTransform::TransformDeclRefExpr(E); |
| 3163 | } |
| 3164 | }; |
| 3165 | } |
| 3166 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3167 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3168 | Expr * |
| 3169 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3170 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3171 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3172 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3173 | auto VarType = Var->getType().getNonReferenceType(); |
| 3174 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3175 | SemaRef.getLangOpts().CPlusPlus) { |
| 3176 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3177 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3178 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3179 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3180 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3181 | if (!Upper || !Lower) |
| 3182 | return nullptr; |
| 3183 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3184 | Sema::AA_Converting, |
| 3185 | /*AllowExplicit=*/true) |
| 3186 | .get(); |
| 3187 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3188 | Sema::AA_Converting, |
| 3189 | /*AllowExplicit=*/true) |
| 3190 | .get(); |
| 3191 | if (!Upper || !Lower) |
| 3192 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3193 | |
| 3194 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3195 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3196 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3197 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3198 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3199 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3200 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3201 | return nullptr; |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | if (!Diff.isUsable()) |
| 3206 | return nullptr; |
| 3207 | |
| 3208 | // Upper - Lower [- 1] |
| 3209 | if (TestIsStrictOp) |
| 3210 | Diff = SemaRef.BuildBinOp( |
| 3211 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3212 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3213 | if (!Diff.isUsable()) |
| 3214 | return nullptr; |
| 3215 | |
| 3216 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3217 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3218 | if (NewStep.isInvalid()) |
| 3219 | return nullptr; |
| 3220 | NewStep = SemaRef.PerformImplicitConversion( |
| 3221 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3222 | /*AllowExplicit=*/true); |
| 3223 | if (NewStep.isInvalid()) |
| 3224 | return nullptr; |
| 3225 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3226 | if (!Diff.isUsable()) |
| 3227 | return nullptr; |
| 3228 | |
| 3229 | // Parentheses (for dumping/debugging purposes only). |
| 3230 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3231 | if (!Diff.isUsable()) |
| 3232 | return nullptr; |
| 3233 | |
| 3234 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3235 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3236 | if (NewStep.isInvalid()) |
| 3237 | return nullptr; |
| 3238 | NewStep = SemaRef.PerformImplicitConversion( |
| 3239 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3240 | /*AllowExplicit=*/true); |
| 3241 | if (NewStep.isInvalid()) |
| 3242 | return nullptr; |
| 3243 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3244 | if (!Diff.isUsable()) |
| 3245 | return nullptr; |
| 3246 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3247 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3248 | QualType Type = Diff.get()->getType(); |
| 3249 | auto &C = SemaRef.Context; |
| 3250 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3251 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3252 | if (!Type->isIntegerType() || UseVarType) { |
| 3253 | unsigned NewSize = |
| 3254 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3255 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3256 | : Type->hasSignedIntegerRepresentation(); |
| 3257 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3258 | Diff = SemaRef.PerformImplicitConversion( |
| 3259 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3260 | if (!Diff.isUsable()) |
| 3261 | return nullptr; |
| 3262 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3263 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3264 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3265 | if (NewSize != C.getTypeSize(Type)) { |
| 3266 | if (NewSize < C.getTypeSize(Type)) { |
| 3267 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3268 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3269 | << InitSrcRange << ConditionSrcRange; |
| 3270 | } |
| 3271 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3272 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3273 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3274 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3275 | Sema::AA_Converting, true); |
| 3276 | if (!Diff.isUsable()) |
| 3277 | return nullptr; |
| 3278 | } |
| 3279 | } |
| 3280 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3281 | return Diff.get(); |
| 3282 | } |
| 3283 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3284 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3285 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3286 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3287 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3288 | TransformToNewDefs Transform(SemaRef); |
| 3289 | |
| 3290 | auto NewLB = Transform.TransformExpr(LB); |
| 3291 | auto NewUB = Transform.TransformExpr(UB); |
| 3292 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3293 | return Cond; |
| 3294 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3295 | Sema::AA_Converting, |
| 3296 | /*AllowExplicit=*/true); |
| 3297 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3298 | Sema::AA_Converting, |
| 3299 | /*AllowExplicit=*/true); |
| 3300 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3301 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3302 | auto CondExpr = SemaRef.BuildBinOp( |
| 3303 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3304 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3305 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3306 | if (CondExpr.isUsable()) { |
| 3307 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3308 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3309 | /*AllowExplicit=*/true); |
| 3310 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3311 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3312 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3313 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3314 | } |
| 3315 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3316 | /// \brief Build reference expression to the counter be used for codegen. |
| 3317 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3318 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3319 | DefaultLoc); |
| 3320 | } |
| 3321 | |
| 3322 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3323 | if (Var && !Var->isInvalidDecl()) { |
| 3324 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3325 | auto *PrivateVar = |
| 3326 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3327 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3328 | if (PrivateVar->isInvalidDecl()) |
| 3329 | return nullptr; |
| 3330 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3331 | } |
| 3332 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | /// \brief Build initization of the counter be used for codegen. |
| 3336 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3337 | |
| 3338 | /// \brief Build step of the counter be used for codegen. |
| 3339 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3340 | |
| 3341 | /// \brief Iteration space of a single for loop. |
| 3342 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3343 | /// \brief Condition of the loop. |
| 3344 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3345 | /// \brief This expression calculates the number of iterations in the loop. |
| 3346 | /// It is always possible to calculate it before starting the loop. |
| 3347 | Expr *NumIterations; |
| 3348 | /// \brief The loop counter variable. |
| 3349 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3350 | /// \brief Private loop counter variable. |
| 3351 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3352 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3353 | Expr *CounterInit; |
| 3354 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3355 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3356 | Expr *CounterStep; |
| 3357 | /// \brief Should step be subtracted? |
| 3358 | bool Subtract; |
| 3359 | /// \brief Source range of the loop init. |
| 3360 | SourceRange InitSrcRange; |
| 3361 | /// \brief Source range of the loop condition. |
| 3362 | SourceRange CondSrcRange; |
| 3363 | /// \brief Source range of the loop increment. |
| 3364 | SourceRange IncSrcRange; |
| 3365 | }; |
| 3366 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3367 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3368 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3369 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3370 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3371 | assert(Init && "Expected loop in canonical form."); |
| 3372 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 3373 | if (CollapseIteration > 0 && |
| 3374 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3375 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 3376 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3377 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 3378 | } |
| 3379 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 3380 | } |
| 3381 | } |
| 3382 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3383 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3384 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3385 | static bool CheckOpenMPIterationSpace( |
| 3386 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3387 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3388 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3389 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3390 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3391 | // OpenMP [2.6, Canonical Loop Form] |
| 3392 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3393 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3394 | if (!For) { |
| 3395 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3396 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3397 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3398 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3399 | if (NestedLoopCount > 1) { |
| 3400 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3401 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3402 | diag::note_omp_collapse_ordered_expr) |
| 3403 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3404 | << OrderedLoopCountExpr->getSourceRange(); |
| 3405 | else if (CollapseLoopCountExpr) |
| 3406 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3407 | diag::note_omp_collapse_ordered_expr) |
| 3408 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3409 | else |
| 3410 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3411 | diag::note_omp_collapse_ordered_expr) |
| 3412 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3413 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3414 | return true; |
| 3415 | } |
| 3416 | assert(For->getBody()); |
| 3417 | |
| 3418 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3419 | |
| 3420 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3421 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3422 | if (ISC.CheckInit(Init)) { |
| 3423 | return true; |
| 3424 | } |
| 3425 | |
| 3426 | bool HasErrors = false; |
| 3427 | |
| 3428 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3429 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3430 | |
| 3431 | // OpenMP [2.6, Canonical Loop Form] |
| 3432 | // Var is one of the following: |
| 3433 | // A variable of signed or unsigned integer type. |
| 3434 | // For C++, a variable of a random access iterator type. |
| 3435 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3436 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3437 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3438 | !VarType->isPointerType() && |
| 3439 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3440 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3441 | << SemaRef.getLangOpts().CPlusPlus; |
| 3442 | HasErrors = true; |
| 3443 | } |
| 3444 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3445 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3446 | // Construct |
| 3447 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3448 | // parallel for construct is (are) private. |
| 3449 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3450 | // with just one associated for-loop is linear with a constant-linear-step |
| 3451 | // that is the increment of the associated for-loop. |
| 3452 | // Exclude loop var from the list of variables with implicitly defined data |
| 3453 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3454 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3455 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3456 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3457 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3458 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3459 | // with just one associated for-loop may be listed in a linear clause with a |
| 3460 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3461 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3462 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3463 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3464 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3465 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3466 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3467 | auto PredeterminedCKind = |
| 3468 | isOpenMPSimdDirective(DKind) |
| 3469 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3470 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3471 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3472 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 3473 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 3474 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3475 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3476 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate && |
| 3477 | DVar.CKind != OMPC_threadprivate)) && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3478 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 3479 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3480 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3481 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3482 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3483 | if (DVar.RefExpr == nullptr) |
| 3484 | DVar.CKind = PredeterminedCKind; |
| 3485 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3486 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3487 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3488 | // Make the loop iteration variable private (for worksharing constructs), |
| 3489 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3490 | // lastprivate (for simd directives with several collapsed or ordered |
| 3491 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3492 | if (DVar.CKind == OMPC_unknown) |
| 3493 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3494 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3495 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3496 | } |
| 3497 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3498 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3499 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3500 | // Check test-expr. |
| 3501 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3502 | |
| 3503 | // Check incr-expr. |
| 3504 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3505 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3506 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3507 | return HasErrors; |
| 3508 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3509 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3510 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3511 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3512 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 3513 | isOpenMPTaskLoopDirective(DKind) || |
| 3514 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3515 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3516 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3517 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3518 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3519 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3520 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3521 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3522 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3523 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3524 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3525 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3526 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3527 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3528 | ResultIterSpace.CounterInit == nullptr || |
| 3529 | ResultIterSpace.CounterStep == nullptr); |
| 3530 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3531 | return HasErrors; |
| 3532 | } |
| 3533 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3534 | /// \brief Build 'VarRef = Start. |
| 3535 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3536 | ExprResult VarRef, ExprResult Start) { |
| 3537 | TransformToNewDefs Transform(SemaRef); |
| 3538 | // Build 'VarRef = Start. |
| 3539 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3540 | if (NewStart.isInvalid()) |
| 3541 | return ExprError(); |
| 3542 | NewStart = SemaRef.PerformImplicitConversion( |
| 3543 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3544 | Sema::AA_Converting, |
| 3545 | /*AllowExplicit=*/true); |
| 3546 | if (NewStart.isInvalid()) |
| 3547 | return ExprError(); |
| 3548 | NewStart = SemaRef.PerformImplicitConversion( |
| 3549 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3550 | /*AllowExplicit=*/true); |
| 3551 | if (!NewStart.isUsable()) |
| 3552 | return ExprError(); |
| 3553 | |
| 3554 | auto Init = |
| 3555 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3556 | return Init; |
| 3557 | } |
| 3558 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3559 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3560 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3561 | SourceLocation Loc, ExprResult VarRef, |
| 3562 | ExprResult Start, ExprResult Iter, |
| 3563 | ExprResult Step, bool Subtract) { |
| 3564 | // Add parentheses (for debugging purposes only). |
| 3565 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3566 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3567 | !Step.isUsable()) |
| 3568 | return ExprError(); |
| 3569 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3570 | TransformToNewDefs Transform(SemaRef); |
| 3571 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3572 | if (NewStep.isInvalid()) |
| 3573 | return ExprError(); |
| 3574 | NewStep = SemaRef.PerformImplicitConversion( |
| 3575 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3576 | Sema::AA_Converting, |
| 3577 | /*AllowExplicit=*/true); |
| 3578 | if (NewStep.isInvalid()) |
| 3579 | return ExprError(); |
| 3580 | ExprResult Update = |
| 3581 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3582 | if (!Update.isUsable()) |
| 3583 | return ExprError(); |
| 3584 | |
| 3585 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3586 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3587 | if (NewStart.isInvalid()) |
| 3588 | return ExprError(); |
| 3589 | NewStart = SemaRef.PerformImplicitConversion( |
| 3590 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3591 | Sema::AA_Converting, |
| 3592 | /*AllowExplicit=*/true); |
| 3593 | if (NewStart.isInvalid()) |
| 3594 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3595 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3596 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3597 | if (!Update.isUsable()) |
| 3598 | return ExprError(); |
| 3599 | |
| 3600 | Update = SemaRef.PerformImplicitConversion( |
| 3601 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3602 | if (!Update.isUsable()) |
| 3603 | return ExprError(); |
| 3604 | |
| 3605 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3606 | return Update; |
| 3607 | } |
| 3608 | |
| 3609 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3610 | /// bits. |
| 3611 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3612 | Sema &SemaRef) { |
| 3613 | if (E == nullptr) |
| 3614 | return ExprError(); |
| 3615 | auto &C = SemaRef.Context; |
| 3616 | QualType OldType = E->getType(); |
| 3617 | unsigned HasBits = C.getTypeSize(OldType); |
| 3618 | if (HasBits >= Bits) |
| 3619 | return ExprResult(E); |
| 3620 | // OK to convert to signed, because new type has more bits than old. |
| 3621 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3622 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3623 | true); |
| 3624 | } |
| 3625 | |
| 3626 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3627 | /// into \a Bits bits. |
| 3628 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3629 | if (E == nullptr) |
| 3630 | return false; |
| 3631 | llvm::APSInt Result; |
| 3632 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3633 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3634 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
| 3637 | /// \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] | 3638 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3639 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3640 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3641 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3642 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3643 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3644 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3645 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3646 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3647 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3648 | // Found 'collapse' clause - calculate collapse number. |
| 3649 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3650 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3651 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3652 | } |
| 3653 | if (OrderedLoopCountExpr) { |
| 3654 | // Found 'ordered' clause - calculate collapse number. |
| 3655 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3656 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3657 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3658 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3659 | diag::err_omp_wrong_ordered_loop_count) |
| 3660 | << OrderedLoopCountExpr->getSourceRange(); |
| 3661 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3662 | diag::note_collapse_loop_count) |
| 3663 | << CollapseLoopCountExpr->getSourceRange(); |
| 3664 | } |
| 3665 | NestedLoopCount = Result.getLimitedValue(); |
| 3666 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3667 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3668 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3669 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3670 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3671 | IterSpaces.resize(NestedLoopCount); |
| 3672 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3673 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3674 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3675 | NestedLoopCount, CollapseLoopCountExpr, |
| 3676 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3677 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3678 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3679 | // 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] | 3680 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3681 | // All loops associated with the construct must be perfectly nested; that |
| 3682 | // is, there must be no intervening code nor any OpenMP directive between |
| 3683 | // any two loops. |
| 3684 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3685 | } |
| 3686 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3687 | Built.clear(/* size */ NestedLoopCount); |
| 3688 | |
| 3689 | if (SemaRef.CurContext->isDependentContext()) |
| 3690 | return NestedLoopCount; |
| 3691 | |
| 3692 | // An example of what is generated for the following code: |
| 3693 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3694 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3695 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3696 | // for (k = 0; k < NK; ++k) |
| 3697 | // for (j = J0; j < NJ; j+=2) { |
| 3698 | // <loop body> |
| 3699 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3700 | // |
| 3701 | // We generate the code below. |
| 3702 | // Note: the loop body may be outlined in CodeGen. |
| 3703 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3704 | // iterations and operator+= to calculate counter value. |
| 3705 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3706 | // or i64 is currently supported). |
| 3707 | // |
| 3708 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3709 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3710 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3711 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3712 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3713 | // <loop body (using local i and j)> |
| 3714 | // } |
| 3715 | // i = NI; // assign final values of counters |
| 3716 | // j = NJ; |
| 3717 | // |
| 3718 | |
| 3719 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3720 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3721 | // Precondition tests if there is at least one iteration (all conditions are |
| 3722 | // true). |
| 3723 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3724 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3725 | ExprResult LastIteration32 = WidenIterationCount( |
| 3726 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3727 | N0->IgnoreImpCasts(), N0->getType(), |
| 3728 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3729 | .get(), |
| 3730 | SemaRef); |
| 3731 | ExprResult LastIteration64 = WidenIterationCount( |
| 3732 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3733 | N0->IgnoreImpCasts(), N0->getType(), |
| 3734 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3735 | .get(), |
| 3736 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3737 | |
| 3738 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3739 | return NestedLoopCount; |
| 3740 | |
| 3741 | auto &C = SemaRef.Context; |
| 3742 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3743 | |
| 3744 | Scope *CurScope = DSA.getCurScope(); |
| 3745 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3746 | if (PreCond.isUsable()) { |
| 3747 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3748 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3749 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3750 | auto N = IterSpaces[Cnt].NumIterations; |
| 3751 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3752 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3753 | LastIteration32 = SemaRef.BuildBinOp( |
| 3754 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3755 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3756 | Sema::AA_Converting, |
| 3757 | /*AllowExplicit=*/true) |
| 3758 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3759 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3760 | LastIteration64 = SemaRef.BuildBinOp( |
| 3761 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3762 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3763 | Sema::AA_Converting, |
| 3764 | /*AllowExplicit=*/true) |
| 3765 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | // Choose either the 32-bit or 64-bit version. |
| 3769 | ExprResult LastIteration = LastIteration64; |
| 3770 | if (LastIteration32.isUsable() && |
| 3771 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3772 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3773 | FitsInto( |
| 3774 | 32 /* Bits */, |
| 3775 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3776 | LastIteration64.get(), SemaRef))) |
| 3777 | LastIteration = LastIteration32; |
| 3778 | |
| 3779 | if (!LastIteration.isUsable()) |
| 3780 | return 0; |
| 3781 | |
| 3782 | // Save the number of iterations. |
| 3783 | ExprResult NumIterations = LastIteration; |
| 3784 | { |
| 3785 | LastIteration = SemaRef.BuildBinOp( |
| 3786 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3787 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3788 | if (!LastIteration.isUsable()) |
| 3789 | return 0; |
| 3790 | } |
| 3791 | |
| 3792 | // Calculate the last iteration number beforehand instead of doing this on |
| 3793 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3794 | llvm::APSInt Result; |
| 3795 | bool IsConstant = |
| 3796 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3797 | ExprResult CalcLastIteration; |
| 3798 | if (!IsConstant) { |
| 3799 | SourceLocation SaveLoc; |
| 3800 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3801 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3802 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3803 | ExprResult SaveRef = buildDeclRefExpr( |
| 3804 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3805 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3806 | SaveRef.get(), LastIteration.get()); |
| 3807 | LastIteration = SaveRef; |
| 3808 | |
| 3809 | // Prepare SaveRef + 1. |
| 3810 | NumIterations = SemaRef.BuildBinOp( |
| 3811 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3812 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3813 | if (!NumIterations.isUsable()) |
| 3814 | return 0; |
| 3815 | } |
| 3816 | |
| 3817 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3818 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3819 | QualType VType = LastIteration.get()->getType(); |
| 3820 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3821 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 3822 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3823 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3824 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3825 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3826 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3827 | SemaRef.AddInitializerToDecl( |
| 3828 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3829 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3830 | |
| 3831 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3832 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3833 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3834 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3835 | /*DirectInit*/ false, |
| 3836 | /*TypeMayContainAuto*/ false); |
| 3837 | |
| 3838 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3839 | // This will be used to implement clause 'lastprivate'. |
| 3840 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3841 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3842 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3843 | SemaRef.AddInitializerToDecl( |
| 3844 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3845 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3846 | |
| 3847 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3848 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3849 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3850 | SemaRef.AddInitializerToDecl( |
| 3851 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3852 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3853 | |
| 3854 | // Build expression: UB = min(UB, LastIteration) |
| 3855 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3856 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3857 | UB.get(), LastIteration.get()); |
| 3858 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3859 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3860 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3861 | CondOp.get()); |
| 3862 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3863 | } |
| 3864 | |
| 3865 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3866 | ExprResult IV; |
| 3867 | ExprResult Init; |
| 3868 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3869 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3870 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3871 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 3872 | isOpenMPTaskLoopDirective(DKind) || |
| 3873 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3874 | ? LB.get() |
| 3875 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3876 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3877 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3878 | } |
| 3879 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3880 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3881 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3882 | ExprResult Cond = |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 3883 | (isOpenMPWorksharingDirective(DKind) || |
| 3884 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3885 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3886 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3887 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3888 | |
| 3889 | // Loop increment (IV = IV + 1) |
| 3890 | SourceLocation IncLoc; |
| 3891 | ExprResult Inc = |
| 3892 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3893 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3894 | if (!Inc.isUsable()) |
| 3895 | return 0; |
| 3896 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3897 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3898 | if (!Inc.isUsable()) |
| 3899 | return 0; |
| 3900 | |
| 3901 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3902 | // Used for directives with static scheduling. |
| 3903 | ExprResult NextLB, NextUB; |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 3904 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3905 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3906 | // LB + ST |
| 3907 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3908 | if (!NextLB.isUsable()) |
| 3909 | return 0; |
| 3910 | // LB = LB + ST |
| 3911 | NextLB = |
| 3912 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3913 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3914 | if (!NextLB.isUsable()) |
| 3915 | return 0; |
| 3916 | // UB + ST |
| 3917 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3918 | if (!NextUB.isUsable()) |
| 3919 | return 0; |
| 3920 | // UB = UB + ST |
| 3921 | NextUB = |
| 3922 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3923 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3924 | if (!NextUB.isUsable()) |
| 3925 | return 0; |
| 3926 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3927 | |
| 3928 | // Build updates and final values of the loop counters. |
| 3929 | bool HasErrors = false; |
| 3930 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3931 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3932 | Built.Updates.resize(NestedLoopCount); |
| 3933 | Built.Finals.resize(NestedLoopCount); |
| 3934 | { |
| 3935 | ExprResult Div; |
| 3936 | // Go from inner nested loop to outer. |
| 3937 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3938 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3939 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3940 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3941 | // where Div is product of previous iterations' IS.NumIters. |
| 3942 | ExprResult Iter; |
| 3943 | if (Div.isUsable()) { |
| 3944 | Iter = |
| 3945 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3946 | } else { |
| 3947 | Iter = IV; |
| 3948 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3949 | "unusable div expected on first iteration only"); |
| 3950 | } |
| 3951 | |
| 3952 | if (Cnt != 0 && Iter.isUsable()) |
| 3953 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3954 | IS.NumIterations); |
| 3955 | if (!Iter.isUsable()) { |
| 3956 | HasErrors = true; |
| 3957 | break; |
| 3958 | } |
| 3959 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3960 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3961 | auto *CounterVar = buildDeclRefExpr( |
| 3962 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3963 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3964 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3965 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3966 | IS.CounterInit); |
| 3967 | if (!Init.isUsable()) { |
| 3968 | HasErrors = true; |
| 3969 | break; |
| 3970 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3971 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3972 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3973 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3974 | if (!Update.isUsable()) { |
| 3975 | HasErrors = true; |
| 3976 | break; |
| 3977 | } |
| 3978 | |
| 3979 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3980 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3981 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3982 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3983 | if (!Final.isUsable()) { |
| 3984 | HasErrors = true; |
| 3985 | break; |
| 3986 | } |
| 3987 | |
| 3988 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3989 | if (Cnt != 0) { |
| 3990 | if (Div.isUnset()) |
| 3991 | Div = IS.NumIterations; |
| 3992 | else |
| 3993 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3994 | IS.NumIterations); |
| 3995 | |
| 3996 | // Add parentheses (for debugging purposes only). |
| 3997 | if (Div.isUsable()) |
| 3998 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3999 | if (!Div.isUsable()) { |
| 4000 | HasErrors = true; |
| 4001 | break; |
| 4002 | } |
| 4003 | } |
| 4004 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4005 | HasErrors = true; |
| 4006 | break; |
| 4007 | } |
| 4008 | // Save results |
| 4009 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4010 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4011 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4012 | Built.Updates[Cnt] = Update.get(); |
| 4013 | Built.Finals[Cnt] = Final.get(); |
| 4014 | } |
| 4015 | } |
| 4016 | |
| 4017 | if (HasErrors) |
| 4018 | return 0; |
| 4019 | |
| 4020 | // Save results |
| 4021 | Built.IterationVarRef = IV.get(); |
| 4022 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4023 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4024 | Built.CalcLastIteration = |
| 4025 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4026 | Built.PreCond = PreCond.get(); |
| 4027 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4028 | Built.Init = Init.get(); |
| 4029 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4030 | Built.LB = LB.get(); |
| 4031 | Built.UB = UB.get(); |
| 4032 | Built.IL = IL.get(); |
| 4033 | Built.ST = ST.get(); |
| 4034 | Built.EUB = EUB.get(); |
| 4035 | Built.NLB = NextLB.get(); |
| 4036 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4037 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4038 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4039 | } |
| 4040 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4041 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4042 | auto CollapseClauses = |
| 4043 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4044 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4045 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4046 | return nullptr; |
| 4047 | } |
| 4048 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4049 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4050 | auto OrderedClauses = |
| 4051 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4052 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4053 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4054 | return nullptr; |
| 4055 | } |
| 4056 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4057 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4058 | const Expr *Safelen) { |
| 4059 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4060 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4061 | Simdlen->isInstantiationDependent() || |
| 4062 | Simdlen->containsUnexpandedParameterPack()) |
| 4063 | return false; |
| 4064 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4065 | Safelen->isInstantiationDependent() || |
| 4066 | Safelen->containsUnexpandedParameterPack()) |
| 4067 | return false; |
| 4068 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4069 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4070 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4071 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4072 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4073 | if (SimdlenRes > SafelenRes) { |
| 4074 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4075 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4076 | return true; |
| 4077 | } |
| 4078 | return false; |
| 4079 | } |
| 4080 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4081 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4082 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4083 | SourceLocation EndLoc, |
| 4084 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4085 | if (!AStmt) |
| 4086 | return StmtError(); |
| 4087 | |
| 4088 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4089 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4090 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4091 | // define the nested loops number. |
| 4092 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4093 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4094 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4095 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4096 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4097 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4098 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4099 | "omp simd loop exprs were not built"); |
| 4100 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4101 | if (!CurContext->isDependentContext()) { |
| 4102 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4103 | for (auto C : Clauses) { |
| 4104 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4105 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4106 | B.NumIterations, *this, CurScope)) |
| 4107 | return StmtError(); |
| 4108 | } |
| 4109 | } |
| 4110 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4111 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4112 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4113 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4114 | OMPSafelenClause *Safelen = nullptr; |
| 4115 | OMPSimdlenClause *Simdlen = nullptr; |
| 4116 | for (auto *Clause : Clauses) { |
| 4117 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4118 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4119 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4120 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4121 | if (Safelen && Simdlen) |
| 4122 | break; |
| 4123 | } |
| 4124 | if (Simdlen && Safelen && |
| 4125 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4126 | Safelen->getSafelen())) |
| 4127 | return StmtError(); |
| 4128 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4129 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4130 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4131 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4132 | } |
| 4133 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4134 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4135 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4136 | SourceLocation EndLoc, |
| 4137 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4138 | if (!AStmt) |
| 4139 | return StmtError(); |
| 4140 | |
| 4141 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4142 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4143 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4144 | // define the nested loops number. |
| 4145 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4146 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4147 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4148 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4149 | return StmtError(); |
| 4150 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4151 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4152 | "omp for loop exprs were not built"); |
| 4153 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4154 | if (!CurContext->isDependentContext()) { |
| 4155 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4156 | for (auto C : Clauses) { |
| 4157 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4158 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4159 | B.NumIterations, *this, CurScope)) |
| 4160 | return StmtError(); |
| 4161 | } |
| 4162 | } |
| 4163 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4164 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4165 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4166 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4167 | } |
| 4168 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4169 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4170 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4171 | SourceLocation EndLoc, |
| 4172 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4173 | if (!AStmt) |
| 4174 | return StmtError(); |
| 4175 | |
| 4176 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4177 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4178 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4179 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4180 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4181 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4182 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4183 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4184 | if (NestedLoopCount == 0) |
| 4185 | return StmtError(); |
| 4186 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4187 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4188 | "omp for simd loop exprs were not built"); |
| 4189 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4190 | if (!CurContext->isDependentContext()) { |
| 4191 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4192 | for (auto C : Clauses) { |
| 4193 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4194 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4195 | B.NumIterations, *this, CurScope)) |
| 4196 | return StmtError(); |
| 4197 | } |
| 4198 | } |
| 4199 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4200 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4201 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4202 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4203 | OMPSafelenClause *Safelen = nullptr; |
| 4204 | OMPSimdlenClause *Simdlen = nullptr; |
| 4205 | for (auto *Clause : Clauses) { |
| 4206 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4207 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4208 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4209 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4210 | if (Safelen && Simdlen) |
| 4211 | break; |
| 4212 | } |
| 4213 | if (Simdlen && Safelen && |
| 4214 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4215 | Safelen->getSafelen())) |
| 4216 | return StmtError(); |
| 4217 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4218 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4219 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4220 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4221 | } |
| 4222 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4223 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4224 | Stmt *AStmt, |
| 4225 | SourceLocation StartLoc, |
| 4226 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4227 | if (!AStmt) |
| 4228 | return StmtError(); |
| 4229 | |
| 4230 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4231 | auto BaseStmt = AStmt; |
| 4232 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4233 | BaseStmt = CS->getCapturedStmt(); |
| 4234 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4235 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4236 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4237 | return StmtError(); |
| 4238 | // All associated statements must be '#pragma omp section' except for |
| 4239 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4240 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4241 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4242 | if (SectionStmt) |
| 4243 | Diag(SectionStmt->getLocStart(), |
| 4244 | diag::err_omp_sections_substmt_not_section); |
| 4245 | return StmtError(); |
| 4246 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4247 | cast<OMPSectionDirective>(SectionStmt) |
| 4248 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4249 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4250 | } else { |
| 4251 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4252 | return StmtError(); |
| 4253 | } |
| 4254 | |
| 4255 | getCurFunction()->setHasBranchProtectedScope(); |
| 4256 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4257 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4258 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4259 | } |
| 4260 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4261 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4262 | SourceLocation StartLoc, |
| 4263 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4264 | if (!AStmt) |
| 4265 | return StmtError(); |
| 4266 | |
| 4267 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4268 | |
| 4269 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4270 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4271 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4272 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4273 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4274 | } |
| 4275 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4276 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4277 | Stmt *AStmt, |
| 4278 | SourceLocation StartLoc, |
| 4279 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4280 | if (!AStmt) |
| 4281 | return StmtError(); |
| 4282 | |
| 4283 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4284 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4285 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4286 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4287 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4288 | // The copyprivate clause must not be used with the nowait clause. |
| 4289 | OMPClause *Nowait = nullptr; |
| 4290 | OMPClause *Copyprivate = nullptr; |
| 4291 | for (auto *Clause : Clauses) { |
| 4292 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4293 | Nowait = Clause; |
| 4294 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4295 | Copyprivate = Clause; |
| 4296 | if (Copyprivate && Nowait) { |
| 4297 | Diag(Copyprivate->getLocStart(), |
| 4298 | diag::err_omp_single_copyprivate_with_nowait); |
| 4299 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4300 | return StmtError(); |
| 4301 | } |
| 4302 | } |
| 4303 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4304 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4305 | } |
| 4306 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4307 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4308 | SourceLocation StartLoc, |
| 4309 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4310 | if (!AStmt) |
| 4311 | return StmtError(); |
| 4312 | |
| 4313 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4314 | |
| 4315 | getCurFunction()->setHasBranchProtectedScope(); |
| 4316 | |
| 4317 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4318 | } |
| 4319 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4320 | StmtResult |
| 4321 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 4322 | Stmt *AStmt, SourceLocation StartLoc, |
| 4323 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4324 | if (!AStmt) |
| 4325 | return StmtError(); |
| 4326 | |
| 4327 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4328 | |
| 4329 | getCurFunction()->setHasBranchProtectedScope(); |
| 4330 | |
| 4331 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4332 | AStmt); |
| 4333 | } |
| 4334 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4335 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4336 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4337 | SourceLocation EndLoc, |
| 4338 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4339 | if (!AStmt) |
| 4340 | return StmtError(); |
| 4341 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4342 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4343 | // 1.2.2 OpenMP Language Terminology |
| 4344 | // Structured block - An executable statement with a single entry at the |
| 4345 | // top and a single exit at the bottom. |
| 4346 | // The point of exit cannot be a branch out of the structured block. |
| 4347 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4348 | CS->getCapturedDecl()->setNothrow(); |
| 4349 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4350 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4351 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4352 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4353 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4354 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4355 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4356 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4357 | if (NestedLoopCount == 0) |
| 4358 | return StmtError(); |
| 4359 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4360 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4361 | "omp parallel for loop exprs were not built"); |
| 4362 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4363 | if (!CurContext->isDependentContext()) { |
| 4364 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4365 | for (auto C : Clauses) { |
| 4366 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4367 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4368 | B.NumIterations, *this, CurScope)) |
| 4369 | return StmtError(); |
| 4370 | } |
| 4371 | } |
| 4372 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4373 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4374 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4375 | NestedLoopCount, Clauses, AStmt, B, |
| 4376 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4379 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4380 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4381 | SourceLocation EndLoc, |
| 4382 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4383 | if (!AStmt) |
| 4384 | return StmtError(); |
| 4385 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4386 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4387 | // 1.2.2 OpenMP Language Terminology |
| 4388 | // Structured block - An executable statement with a single entry at the |
| 4389 | // top and a single exit at the bottom. |
| 4390 | // The point of exit cannot be a branch out of the structured block. |
| 4391 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4392 | CS->getCapturedDecl()->setNothrow(); |
| 4393 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4394 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4395 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4396 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4397 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4398 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4399 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4400 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4401 | if (NestedLoopCount == 0) |
| 4402 | return StmtError(); |
| 4403 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4404 | if (!CurContext->isDependentContext()) { |
| 4405 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4406 | for (auto C : Clauses) { |
| 4407 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4408 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4409 | B.NumIterations, *this, CurScope)) |
| 4410 | return StmtError(); |
| 4411 | } |
| 4412 | } |
| 4413 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4414 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4415 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4416 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4417 | OMPSafelenClause *Safelen = nullptr; |
| 4418 | OMPSimdlenClause *Simdlen = nullptr; |
| 4419 | for (auto *Clause : Clauses) { |
| 4420 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4421 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4422 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4423 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4424 | if (Safelen && Simdlen) |
| 4425 | break; |
| 4426 | } |
| 4427 | if (Simdlen && Safelen && |
| 4428 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4429 | Safelen->getSafelen())) |
| 4430 | return StmtError(); |
| 4431 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4432 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4433 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4434 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4435 | } |
| 4436 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4437 | StmtResult |
| 4438 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4439 | Stmt *AStmt, SourceLocation StartLoc, |
| 4440 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4441 | if (!AStmt) |
| 4442 | return StmtError(); |
| 4443 | |
| 4444 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4445 | auto BaseStmt = AStmt; |
| 4446 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4447 | BaseStmt = CS->getCapturedStmt(); |
| 4448 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4449 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4450 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4451 | return StmtError(); |
| 4452 | // All associated statements must be '#pragma omp section' except for |
| 4453 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4454 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4455 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4456 | if (SectionStmt) |
| 4457 | Diag(SectionStmt->getLocStart(), |
| 4458 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4459 | return StmtError(); |
| 4460 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4461 | cast<OMPSectionDirective>(SectionStmt) |
| 4462 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4463 | } |
| 4464 | } else { |
| 4465 | Diag(AStmt->getLocStart(), |
| 4466 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4467 | return StmtError(); |
| 4468 | } |
| 4469 | |
| 4470 | getCurFunction()->setHasBranchProtectedScope(); |
| 4471 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4472 | return OMPParallelSectionsDirective::Create( |
| 4473 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4474 | } |
| 4475 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4476 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4477 | Stmt *AStmt, SourceLocation StartLoc, |
| 4478 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4479 | if (!AStmt) |
| 4480 | return StmtError(); |
| 4481 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4482 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4483 | // 1.2.2 OpenMP Language Terminology |
| 4484 | // Structured block - An executable statement with a single entry at the |
| 4485 | // top and a single exit at the bottom. |
| 4486 | // The point of exit cannot be a branch out of the structured block. |
| 4487 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4488 | CS->getCapturedDecl()->setNothrow(); |
| 4489 | |
| 4490 | getCurFunction()->setHasBranchProtectedScope(); |
| 4491 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4492 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4493 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4494 | } |
| 4495 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4496 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4497 | SourceLocation EndLoc) { |
| 4498 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4499 | } |
| 4500 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4501 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4502 | SourceLocation EndLoc) { |
| 4503 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4504 | } |
| 4505 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4506 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4507 | SourceLocation EndLoc) { |
| 4508 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4509 | } |
| 4510 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4511 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4512 | SourceLocation StartLoc, |
| 4513 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4514 | if (!AStmt) |
| 4515 | return StmtError(); |
| 4516 | |
| 4517 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4518 | |
| 4519 | getCurFunction()->setHasBranchProtectedScope(); |
| 4520 | |
| 4521 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4522 | } |
| 4523 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4524 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4525 | SourceLocation StartLoc, |
| 4526 | SourceLocation EndLoc) { |
| 4527 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4528 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4529 | } |
| 4530 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4531 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4532 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4533 | SourceLocation StartLoc, |
| 4534 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4535 | if (!AStmt) |
| 4536 | return StmtError(); |
| 4537 | |
| 4538 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4539 | |
| 4540 | getCurFunction()->setHasBranchProtectedScope(); |
| 4541 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4542 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4543 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4544 | for (auto *C: Clauses) { |
| 4545 | if (C->getClauseKind() == OMPC_threads) |
| 4546 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4547 | else if (C->getClauseKind() == OMPC_simd) |
| 4548 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4549 | } |
| 4550 | |
| 4551 | // TODO: this must happen only if 'threads' clause specified or if no clauses |
| 4552 | // is specified. |
| 4553 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4554 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4555 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) << (TC != nullptr); |
| 4556 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4557 | return StmtError(); |
| 4558 | } |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4559 | if (!SC && isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
| 4560 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4561 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4562 | // that can appear in the simd region. |
| 4563 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 4564 | return StmtError(); |
| 4565 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4566 | |
| 4567 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4568 | } |
| 4569 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4570 | namespace { |
| 4571 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4572 | /// construct. |
| 4573 | class OpenMPAtomicUpdateChecker { |
| 4574 | /// \brief Error results for atomic update expressions. |
| 4575 | enum ExprAnalysisErrorCode { |
| 4576 | /// \brief A statement is not an expression statement. |
| 4577 | NotAnExpression, |
| 4578 | /// \brief Expression is not builtin binary or unary operation. |
| 4579 | NotABinaryOrUnaryExpression, |
| 4580 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4581 | NotAnUnaryIncDecExpression, |
| 4582 | /// \brief An expression is not of scalar type. |
| 4583 | NotAScalarType, |
| 4584 | /// \brief A binary operation is not an assignment operation. |
| 4585 | NotAnAssignmentOp, |
| 4586 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4587 | NotABinaryExpression, |
| 4588 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4589 | /// expression. |
| 4590 | NotABinaryOperator, |
| 4591 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4592 | /// part. |
| 4593 | NotAnUpdateExpression, |
| 4594 | /// \brief No errors is found. |
| 4595 | NoError |
| 4596 | }; |
| 4597 | /// \brief Reference to Sema. |
| 4598 | Sema &SemaRef; |
| 4599 | /// \brief A location for note diagnostics (when error is found). |
| 4600 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4601 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4602 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4603 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4604 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4605 | /// \brief Helper expression of the form |
| 4606 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4607 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4608 | Expr *UpdateExpr; |
| 4609 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4610 | /// important for non-associative operations. |
| 4611 | bool IsXLHSInRHSPart; |
| 4612 | BinaryOperatorKind Op; |
| 4613 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4614 | /// \brief true if the source expression is a postfix unary operation, false |
| 4615 | /// if it is a prefix unary operation. |
| 4616 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4617 | |
| 4618 | public: |
| 4619 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4620 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4621 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4622 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4623 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4624 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4625 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4626 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4627 | /// \param NoteId Diagnostic note for the main error message. |
| 4628 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4629 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4630 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4631 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4632 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4633 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4634 | /// \brief Return the update expression used in calculation of the updated |
| 4635 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4636 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4637 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4638 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4639 | /// false otherwise. |
| 4640 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4641 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4642 | /// \brief true if the source expression is a postfix unary operation, false |
| 4643 | /// if it is a prefix unary operation. |
| 4644 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4645 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4646 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4647 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4648 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4649 | }; |
| 4650 | } // namespace |
| 4651 | |
| 4652 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4653 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4654 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4655 | SourceLocation ErrorLoc, NoteLoc; |
| 4656 | SourceRange ErrorRange, NoteRange; |
| 4657 | // Allowed constructs are: |
| 4658 | // x = x binop expr; |
| 4659 | // x = expr binop x; |
| 4660 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4661 | X = AtomicBinOp->getLHS(); |
| 4662 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4663 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4664 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4665 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4666 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4667 | Op = AtomicInnerBinOp->getOpcode(); |
| 4668 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4669 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4670 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4671 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4672 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4673 | /*Canonical=*/true); |
| 4674 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4675 | /*Canonical=*/true); |
| 4676 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4677 | /*Canonical=*/true); |
| 4678 | if (XId == LHSId) { |
| 4679 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4680 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4681 | } else if (XId == RHSId) { |
| 4682 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4683 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4684 | } else { |
| 4685 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4686 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4687 | NoteLoc = X->getExprLoc(); |
| 4688 | NoteRange = X->getSourceRange(); |
| 4689 | ErrorFound = NotAnUpdateExpression; |
| 4690 | } |
| 4691 | } else { |
| 4692 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4693 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4694 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4695 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4696 | ErrorFound = NotABinaryOperator; |
| 4697 | } |
| 4698 | } else { |
| 4699 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4700 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4701 | ErrorFound = NotABinaryExpression; |
| 4702 | } |
| 4703 | } else { |
| 4704 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4705 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4706 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4707 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4708 | ErrorFound = NotAnAssignmentOp; |
| 4709 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4710 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4711 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4712 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4713 | return true; |
| 4714 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4715 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4716 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4717 | } |
| 4718 | |
| 4719 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4720 | unsigned NoteId) { |
| 4721 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4722 | SourceLocation ErrorLoc, NoteLoc; |
| 4723 | SourceRange ErrorRange, NoteRange; |
| 4724 | // Allowed constructs are: |
| 4725 | // x++; |
| 4726 | // x--; |
| 4727 | // ++x; |
| 4728 | // --x; |
| 4729 | // x binop= expr; |
| 4730 | // x = x binop expr; |
| 4731 | // x = expr binop x; |
| 4732 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4733 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4734 | if (AtomicBody->getType()->isScalarType() || |
| 4735 | AtomicBody->isInstantiationDependent()) { |
| 4736 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4737 | AtomicBody->IgnoreParenImpCasts())) { |
| 4738 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4739 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4740 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4741 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4742 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4743 | X = AtomicCompAssignOp->getLHS(); |
| 4744 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4745 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4746 | AtomicBody->IgnoreParenImpCasts())) { |
| 4747 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4748 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4749 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4750 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4751 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4752 | // Check for Unary Operation |
| 4753 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4754 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4755 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4756 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4757 | X = AtomicUnaryOp->getSubExpr(); |
| 4758 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4759 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4760 | } else { |
| 4761 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4762 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4763 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4764 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4765 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4766 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4767 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4768 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4769 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4770 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4771 | } |
| 4772 | } else { |
| 4773 | ErrorFound = NotAScalarType; |
| 4774 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4775 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4776 | } |
| 4777 | } else { |
| 4778 | ErrorFound = NotAnExpression; |
| 4779 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4780 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4781 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4782 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4783 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4784 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4785 | return true; |
| 4786 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4787 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4788 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4789 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4790 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4791 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4792 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4793 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4794 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4795 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4796 | auto Update = |
| 4797 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4798 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4799 | if (Update.isInvalid()) |
| 4800 | return true; |
| 4801 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4802 | Sema::AA_Casting); |
| 4803 | if (Update.isInvalid()) |
| 4804 | return true; |
| 4805 | UpdateExpr = Update.get(); |
| 4806 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4807 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4808 | } |
| 4809 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4810 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4811 | Stmt *AStmt, |
| 4812 | SourceLocation StartLoc, |
| 4813 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4814 | if (!AStmt) |
| 4815 | return StmtError(); |
| 4816 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4817 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4818 | // 1.2.2 OpenMP Language Terminology |
| 4819 | // Structured block - An executable statement with a single entry at the |
| 4820 | // top and a single exit at the bottom. |
| 4821 | // The point of exit cannot be a branch out of the structured block. |
| 4822 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4823 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4824 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4825 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4826 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4827 | C->getClauseKind() == OMPC_update || |
| 4828 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4829 | if (AtomicKind != OMPC_unknown) { |
| 4830 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4831 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4832 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4833 | << getOpenMPClauseName(AtomicKind); |
| 4834 | } else { |
| 4835 | AtomicKind = C->getClauseKind(); |
| 4836 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4837 | } |
| 4838 | } |
| 4839 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4840 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4841 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4842 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4843 | Body = EWC->getSubExpr(); |
| 4844 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4845 | Expr *X = nullptr; |
| 4846 | Expr *V = nullptr; |
| 4847 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4848 | Expr *UE = nullptr; |
| 4849 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4850 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4851 | // OpenMP [2.12.6, atomic Construct] |
| 4852 | // In the next expressions: |
| 4853 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4854 | // * During the execution of an atomic region, multiple syntactic |
| 4855 | // occurrences of x must designate the same storage location. |
| 4856 | // * Neither of v and expr (as applicable) may access the storage location |
| 4857 | // designated by x. |
| 4858 | // * Neither of x and expr (as applicable) may access the storage location |
| 4859 | // designated by v. |
| 4860 | // * expr is an expression with scalar type. |
| 4861 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4862 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4863 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4864 | // (expr). This requirement is satisfied if the operators in expr have |
| 4865 | // precedence greater than binop, or by using parentheses around expr or |
| 4866 | // subexpressions of expr. |
| 4867 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4868 | // binop x. This requirement is satisfied if the operators in expr have |
| 4869 | // precedence equal to or greater than binop, or by using parentheses around |
| 4870 | // expr or subexpressions of expr. |
| 4871 | // * For forms that allow multiple occurrences of x, the number of times |
| 4872 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4873 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4874 | enum { |
| 4875 | NotAnExpression, |
| 4876 | NotAnAssignmentOp, |
| 4877 | NotAScalarType, |
| 4878 | NotAnLValue, |
| 4879 | NoError |
| 4880 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4881 | SourceLocation ErrorLoc, NoteLoc; |
| 4882 | SourceRange ErrorRange, NoteRange; |
| 4883 | // If clause is read: |
| 4884 | // v = x; |
| 4885 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4886 | auto AtomicBinOp = |
| 4887 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4888 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4889 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4890 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4891 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4892 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4893 | if (!X->isLValue() || !V->isLValue()) { |
| 4894 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4895 | ErrorFound = NotAnLValue; |
| 4896 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4897 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4898 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4899 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4900 | } |
| 4901 | } else if (!X->isInstantiationDependent() || |
| 4902 | !V->isInstantiationDependent()) { |
| 4903 | auto NotScalarExpr = |
| 4904 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4905 | ? V |
| 4906 | : X; |
| 4907 | ErrorFound = NotAScalarType; |
| 4908 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4909 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4910 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4911 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4912 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4913 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4914 | ErrorFound = NotAnAssignmentOp; |
| 4915 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4916 | ErrorRange = AtomicBody->getSourceRange(); |
| 4917 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4918 | : AtomicBody->getExprLoc(); |
| 4919 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4920 | : AtomicBody->getSourceRange(); |
| 4921 | } |
| 4922 | } else { |
| 4923 | ErrorFound = NotAnExpression; |
| 4924 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4925 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4926 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4927 | if (ErrorFound != NoError) { |
| 4928 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4929 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4930 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4931 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4932 | return StmtError(); |
| 4933 | } else if (CurContext->isDependentContext()) |
| 4934 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4935 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4936 | enum { |
| 4937 | NotAnExpression, |
| 4938 | NotAnAssignmentOp, |
| 4939 | NotAScalarType, |
| 4940 | NotAnLValue, |
| 4941 | NoError |
| 4942 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4943 | SourceLocation ErrorLoc, NoteLoc; |
| 4944 | SourceRange ErrorRange, NoteRange; |
| 4945 | // If clause is write: |
| 4946 | // x = expr; |
| 4947 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4948 | auto AtomicBinOp = |
| 4949 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4950 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4951 | X = AtomicBinOp->getLHS(); |
| 4952 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4953 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4954 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4955 | if (!X->isLValue()) { |
| 4956 | ErrorFound = NotAnLValue; |
| 4957 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4958 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4959 | NoteLoc = X->getExprLoc(); |
| 4960 | NoteRange = X->getSourceRange(); |
| 4961 | } |
| 4962 | } else if (!X->isInstantiationDependent() || |
| 4963 | !E->isInstantiationDependent()) { |
| 4964 | auto NotScalarExpr = |
| 4965 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4966 | ? E |
| 4967 | : X; |
| 4968 | ErrorFound = NotAScalarType; |
| 4969 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4970 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4971 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4972 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4973 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4974 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4975 | ErrorFound = NotAnAssignmentOp; |
| 4976 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4977 | ErrorRange = AtomicBody->getSourceRange(); |
| 4978 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4979 | : AtomicBody->getExprLoc(); |
| 4980 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4981 | : AtomicBody->getSourceRange(); |
| 4982 | } |
| 4983 | } else { |
| 4984 | ErrorFound = NotAnExpression; |
| 4985 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4986 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4987 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4988 | if (ErrorFound != NoError) { |
| 4989 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4990 | << ErrorRange; |
| 4991 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4992 | << NoteRange; |
| 4993 | return StmtError(); |
| 4994 | } else if (CurContext->isDependentContext()) |
| 4995 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4996 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4997 | // If clause is update: |
| 4998 | // x++; |
| 4999 | // x--; |
| 5000 | // ++x; |
| 5001 | // --x; |
| 5002 | // x binop= expr; |
| 5003 | // x = x binop expr; |
| 5004 | // x = expr binop x; |
| 5005 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5006 | if (Checker.checkStatement( |
| 5007 | Body, (AtomicKind == OMPC_update) |
| 5008 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5009 | : diag::err_omp_atomic_not_expression_statement, |
| 5010 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5011 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5012 | if (!CurContext->isDependentContext()) { |
| 5013 | E = Checker.getExpr(); |
| 5014 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5015 | UE = Checker.getUpdateExpr(); |
| 5016 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5017 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5018 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5019 | enum { |
| 5020 | NotAnAssignmentOp, |
| 5021 | NotACompoundStatement, |
| 5022 | NotTwoSubstatements, |
| 5023 | NotASpecificExpression, |
| 5024 | NoError |
| 5025 | } ErrorFound = NoError; |
| 5026 | SourceLocation ErrorLoc, NoteLoc; |
| 5027 | SourceRange ErrorRange, NoteRange; |
| 5028 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5029 | // If clause is a capture: |
| 5030 | // v = x++; |
| 5031 | // v = x--; |
| 5032 | // v = ++x; |
| 5033 | // v = --x; |
| 5034 | // v = x binop= expr; |
| 5035 | // v = x = x binop expr; |
| 5036 | // v = x = expr binop x; |
| 5037 | auto *AtomicBinOp = |
| 5038 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5039 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5040 | V = AtomicBinOp->getLHS(); |
| 5041 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5042 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5043 | if (Checker.checkStatement( |
| 5044 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5045 | diag::note_omp_atomic_update)) |
| 5046 | return StmtError(); |
| 5047 | E = Checker.getExpr(); |
| 5048 | X = Checker.getX(); |
| 5049 | UE = Checker.getUpdateExpr(); |
| 5050 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5051 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5052 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5053 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5054 | ErrorRange = AtomicBody->getSourceRange(); |
| 5055 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5056 | : AtomicBody->getExprLoc(); |
| 5057 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5058 | : AtomicBody->getSourceRange(); |
| 5059 | ErrorFound = NotAnAssignmentOp; |
| 5060 | } |
| 5061 | if (ErrorFound != NoError) { |
| 5062 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5063 | << ErrorRange; |
| 5064 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5065 | return StmtError(); |
| 5066 | } else if (CurContext->isDependentContext()) { |
| 5067 | UE = V = E = X = nullptr; |
| 5068 | } |
| 5069 | } else { |
| 5070 | // If clause is a capture: |
| 5071 | // { v = x; x = expr; } |
| 5072 | // { v = x; x++; } |
| 5073 | // { v = x; x--; } |
| 5074 | // { v = x; ++x; } |
| 5075 | // { v = x; --x; } |
| 5076 | // { v = x; x binop= expr; } |
| 5077 | // { v = x; x = x binop expr; } |
| 5078 | // { v = x; x = expr binop x; } |
| 5079 | // { x++; v = x; } |
| 5080 | // { x--; v = x; } |
| 5081 | // { ++x; v = x; } |
| 5082 | // { --x; v = x; } |
| 5083 | // { x binop= expr; v = x; } |
| 5084 | // { x = x binop expr; v = x; } |
| 5085 | // { x = expr binop x; v = x; } |
| 5086 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5087 | // Check that this is { expr1; expr2; } |
| 5088 | if (CS->size() == 2) { |
| 5089 | auto *First = CS->body_front(); |
| 5090 | auto *Second = CS->body_back(); |
| 5091 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5092 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5093 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5094 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5095 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5096 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5097 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5098 | BinaryOperator *BinOp = nullptr; |
| 5099 | if (IsUpdateExprFound) { |
| 5100 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5101 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5102 | } |
| 5103 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5104 | // { v = x; x++; } |
| 5105 | // { v = x; x--; } |
| 5106 | // { v = x; ++x; } |
| 5107 | // { v = x; --x; } |
| 5108 | // { v = x; x binop= expr; } |
| 5109 | // { v = x; x = x binop expr; } |
| 5110 | // { v = x; x = expr binop x; } |
| 5111 | // Check that the first expression has form v = x. |
| 5112 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5113 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5114 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5115 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5116 | IsUpdateExprFound = XId == PossibleXId; |
| 5117 | if (IsUpdateExprFound) { |
| 5118 | V = BinOp->getLHS(); |
| 5119 | X = Checker.getX(); |
| 5120 | E = Checker.getExpr(); |
| 5121 | UE = Checker.getUpdateExpr(); |
| 5122 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5123 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5124 | } |
| 5125 | } |
| 5126 | if (!IsUpdateExprFound) { |
| 5127 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5128 | BinOp = nullptr; |
| 5129 | if (IsUpdateExprFound) { |
| 5130 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5131 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5132 | } |
| 5133 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5134 | // { x++; v = x; } |
| 5135 | // { x--; v = x; } |
| 5136 | // { ++x; v = x; } |
| 5137 | // { --x; v = x; } |
| 5138 | // { x binop= expr; v = x; } |
| 5139 | // { x = x binop expr; v = x; } |
| 5140 | // { x = expr binop x; v = x; } |
| 5141 | // Check that the second expression has form v = x. |
| 5142 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5143 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5144 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5145 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5146 | IsUpdateExprFound = XId == PossibleXId; |
| 5147 | if (IsUpdateExprFound) { |
| 5148 | V = BinOp->getLHS(); |
| 5149 | X = Checker.getX(); |
| 5150 | E = Checker.getExpr(); |
| 5151 | UE = Checker.getUpdateExpr(); |
| 5152 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5153 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5154 | } |
| 5155 | } |
| 5156 | } |
| 5157 | if (!IsUpdateExprFound) { |
| 5158 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5159 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5160 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5161 | if (!FirstExpr || !SecondExpr || |
| 5162 | !(FirstExpr->isInstantiationDependent() || |
| 5163 | SecondExpr->isInstantiationDependent())) { |
| 5164 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5165 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5166 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5167 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5168 | : First->getLocStart(); |
| 5169 | NoteRange = ErrorRange = FirstBinOp |
| 5170 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5171 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5172 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5173 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5174 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5175 | ErrorFound = NotAnAssignmentOp; |
| 5176 | NoteLoc = ErrorLoc = SecondBinOp |
| 5177 | ? SecondBinOp->getOperatorLoc() |
| 5178 | : Second->getLocStart(); |
| 5179 | NoteRange = ErrorRange = |
| 5180 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5181 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5182 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5183 | auto *PossibleXRHSInFirst = |
| 5184 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5185 | auto *PossibleXLHSInSecond = |
| 5186 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5187 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5188 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5189 | /*Canonical=*/true); |
| 5190 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5191 | /*Canonical=*/true); |
| 5192 | IsUpdateExprFound = X1Id == X2Id; |
| 5193 | if (IsUpdateExprFound) { |
| 5194 | V = FirstBinOp->getLHS(); |
| 5195 | X = SecondBinOp->getLHS(); |
| 5196 | E = SecondBinOp->getRHS(); |
| 5197 | UE = nullptr; |
| 5198 | IsXLHSInRHSPart = false; |
| 5199 | IsPostfixUpdate = true; |
| 5200 | } else { |
| 5201 | ErrorFound = NotASpecificExpression; |
| 5202 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5203 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5204 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5205 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5206 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5207 | } |
| 5208 | } |
| 5209 | } |
| 5210 | } |
| 5211 | } else { |
| 5212 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5213 | NoteRange = ErrorRange = |
| 5214 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5215 | ErrorFound = NotTwoSubstatements; |
| 5216 | } |
| 5217 | } else { |
| 5218 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5219 | NoteRange = ErrorRange = |
| 5220 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5221 | ErrorFound = NotACompoundStatement; |
| 5222 | } |
| 5223 | if (ErrorFound != NoError) { |
| 5224 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5225 | << ErrorRange; |
| 5226 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5227 | return StmtError(); |
| 5228 | } else if (CurContext->isDependentContext()) { |
| 5229 | UE = V = E = X = nullptr; |
| 5230 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5231 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5232 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5233 | |
| 5234 | getCurFunction()->setHasBranchProtectedScope(); |
| 5235 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5236 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5237 | X, V, E, UE, IsXLHSInRHSPart, |
| 5238 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5239 | } |
| 5240 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5241 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5242 | Stmt *AStmt, |
| 5243 | SourceLocation StartLoc, |
| 5244 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5245 | if (!AStmt) |
| 5246 | return StmtError(); |
| 5247 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5248 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5249 | // 1.2.2 OpenMP Language Terminology |
| 5250 | // Structured block - An executable statement with a single entry at the |
| 5251 | // top and a single exit at the bottom. |
| 5252 | // The point of exit cannot be a branch out of the structured block. |
| 5253 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5254 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5255 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5256 | // OpenMP [2.16, Nesting of Regions] |
| 5257 | // If specified, a teams construct must be contained within a target |
| 5258 | // construct. That target construct must contain no statements or directives |
| 5259 | // outside of the teams construct. |
| 5260 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5261 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5262 | bool OMPTeamsFound = true; |
| 5263 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5264 | auto I = CS->body_begin(); |
| 5265 | while (I != CS->body_end()) { |
| 5266 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5267 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5268 | OMPTeamsFound = false; |
| 5269 | break; |
| 5270 | } |
| 5271 | ++I; |
| 5272 | } |
| 5273 | assert(I != CS->body_end() && "Not found statement"); |
| 5274 | S = *I; |
| 5275 | } |
| 5276 | if (!OMPTeamsFound) { |
| 5277 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5278 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5279 | diag::note_omp_nested_teams_construct_here); |
| 5280 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5281 | << isa<OMPExecutableDirective>(S); |
| 5282 | return StmtError(); |
| 5283 | } |
| 5284 | } |
| 5285 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5286 | getCurFunction()->setHasBranchProtectedScope(); |
| 5287 | |
| 5288 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5289 | } |
| 5290 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5291 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5292 | Stmt *AStmt, |
| 5293 | SourceLocation StartLoc, |
| 5294 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5295 | if (!AStmt) |
| 5296 | return StmtError(); |
| 5297 | |
| 5298 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5299 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5300 | getCurFunction()->setHasBranchProtectedScope(); |
| 5301 | |
| 5302 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5303 | AStmt); |
| 5304 | } |
| 5305 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5306 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5307 | Stmt *AStmt, SourceLocation StartLoc, |
| 5308 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5309 | if (!AStmt) |
| 5310 | return StmtError(); |
| 5311 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5312 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5313 | // 1.2.2 OpenMP Language Terminology |
| 5314 | // Structured block - An executable statement with a single entry at the |
| 5315 | // top and a single exit at the bottom. |
| 5316 | // The point of exit cannot be a branch out of the structured block. |
| 5317 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5318 | CS->getCapturedDecl()->setNothrow(); |
| 5319 | |
| 5320 | getCurFunction()->setHasBranchProtectedScope(); |
| 5321 | |
| 5322 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5323 | } |
| 5324 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5325 | StmtResult |
| 5326 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5327 | SourceLocation EndLoc, |
| 5328 | OpenMPDirectiveKind CancelRegion) { |
| 5329 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5330 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5331 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5332 | << getOpenMPDirectiveName(CancelRegion); |
| 5333 | return StmtError(); |
| 5334 | } |
| 5335 | if (DSAStack->isParentNowaitRegion()) { |
| 5336 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5337 | return StmtError(); |
| 5338 | } |
| 5339 | if (DSAStack->isParentOrderedRegion()) { |
| 5340 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5341 | return StmtError(); |
| 5342 | } |
| 5343 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5344 | CancelRegion); |
| 5345 | } |
| 5346 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5347 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5348 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5349 | SourceLocation EndLoc, |
| 5350 | OpenMPDirectiveKind CancelRegion) { |
| 5351 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5352 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5353 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5354 | << getOpenMPDirectiveName(CancelRegion); |
| 5355 | return StmtError(); |
| 5356 | } |
| 5357 | if (DSAStack->isParentNowaitRegion()) { |
| 5358 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5359 | return StmtError(); |
| 5360 | } |
| 5361 | if (DSAStack->isParentOrderedRegion()) { |
| 5362 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5363 | return StmtError(); |
| 5364 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5365 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5366 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5367 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5368 | } |
| 5369 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5370 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5371 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5372 | SourceLocation EndLoc, |
| 5373 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5374 | if (!AStmt) |
| 5375 | return StmtError(); |
| 5376 | |
| 5377 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5378 | OMPLoopDirective::HelperExprs B; |
| 5379 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5380 | // define the nested loops number. |
| 5381 | unsigned NestedLoopCount = |
| 5382 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5383 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5384 | VarsWithImplicitDSA, B); |
| 5385 | if (NestedLoopCount == 0) |
| 5386 | return StmtError(); |
| 5387 | |
| 5388 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5389 | "omp for loop exprs were not built"); |
| 5390 | |
| 5391 | getCurFunction()->setHasBranchProtectedScope(); |
| 5392 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5393 | NestedLoopCount, Clauses, AStmt, B); |
| 5394 | } |
| 5395 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5396 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5397 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5398 | SourceLocation EndLoc, |
| 5399 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5400 | if (!AStmt) |
| 5401 | return StmtError(); |
| 5402 | |
| 5403 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5404 | OMPLoopDirective::HelperExprs B; |
| 5405 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5406 | // define the nested loops number. |
| 5407 | unsigned NestedLoopCount = |
| 5408 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5409 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5410 | VarsWithImplicitDSA, B); |
| 5411 | if (NestedLoopCount == 0) |
| 5412 | return StmtError(); |
| 5413 | |
| 5414 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5415 | "omp for loop exprs were not built"); |
| 5416 | |
| 5417 | getCurFunction()->setHasBranchProtectedScope(); |
| 5418 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5419 | NestedLoopCount, Clauses, AStmt, B); |
| 5420 | } |
| 5421 | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 5422 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5423 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5424 | SourceLocation EndLoc, |
| 5425 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5426 | if (!AStmt) |
| 5427 | return StmtError(); |
| 5428 | |
| 5429 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5430 | OMPLoopDirective::HelperExprs B; |
| 5431 | // In presence of clause 'collapse' with number of loops, it will |
| 5432 | // define the nested loops number. |
| 5433 | unsigned NestedLoopCount = |
| 5434 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5435 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5436 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5437 | if (NestedLoopCount == 0) |
| 5438 | return StmtError(); |
| 5439 | |
| 5440 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5441 | "omp for loop exprs were not built"); |
| 5442 | |
| 5443 | getCurFunction()->setHasBranchProtectedScope(); |
| 5444 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5445 | NestedLoopCount, Clauses, AStmt, B); |
| 5446 | } |
| 5447 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5448 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5449 | SourceLocation StartLoc, |
| 5450 | SourceLocation LParenLoc, |
| 5451 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5452 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5453 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5454 | case OMPC_final: |
| 5455 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5456 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5457 | case OMPC_num_threads: |
| 5458 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5459 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5460 | case OMPC_safelen: |
| 5461 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5462 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5463 | case OMPC_simdlen: |
| 5464 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5465 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5466 | case OMPC_collapse: |
| 5467 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5468 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5469 | case OMPC_ordered: |
| 5470 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5471 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5472 | case OMPC_device: |
| 5473 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5474 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5475 | case OMPC_num_teams: |
| 5476 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5477 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5478 | case OMPC_thread_limit: |
| 5479 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5480 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5481 | case OMPC_priority: |
| 5482 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5483 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5484 | case OMPC_grainsize: |
| 5485 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5486 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5487 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5488 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5489 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5490 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5491 | case OMPC_private: |
| 5492 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5493 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5494 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5495 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5496 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5497 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5498 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5499 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5500 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5501 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5502 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5503 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5504 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5505 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5506 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5507 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5508 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5509 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5510 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5511 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5512 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5513 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5514 | case OMPC_nogroup: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5515 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5516 | llvm_unreachable("Clause is not allowed."); |
| 5517 | } |
| 5518 | return Res; |
| 5519 | } |
| 5520 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5521 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5522 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5523 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5524 | SourceLocation NameModifierLoc, |
| 5525 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5526 | SourceLocation EndLoc) { |
| 5527 | Expr *ValExpr = Condition; |
| 5528 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5529 | !Condition->isInstantiationDependent() && |
| 5530 | !Condition->containsUnexpandedParameterPack()) { |
| 5531 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5532 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5533 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5534 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5535 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5536 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5537 | } |
| 5538 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5539 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5540 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5541 | } |
| 5542 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5543 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5544 | SourceLocation StartLoc, |
| 5545 | SourceLocation LParenLoc, |
| 5546 | SourceLocation EndLoc) { |
| 5547 | Expr *ValExpr = Condition; |
| 5548 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5549 | !Condition->isInstantiationDependent() && |
| 5550 | !Condition->containsUnexpandedParameterPack()) { |
| 5551 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5552 | Condition->getExprLoc(), Condition); |
| 5553 | if (Val.isInvalid()) |
| 5554 | return nullptr; |
| 5555 | |
| 5556 | ValExpr = Val.get(); |
| 5557 | } |
| 5558 | |
| 5559 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5560 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5561 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5562 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5563 | if (!Op) |
| 5564 | return ExprError(); |
| 5565 | |
| 5566 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5567 | public: |
| 5568 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5569 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5570 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5571 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5572 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5573 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5574 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5575 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5576 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5577 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5578 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5579 | QualType T, |
| 5580 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5581 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5582 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5583 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5584 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5585 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5586 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5587 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5588 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5589 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5590 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5591 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5592 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5593 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5594 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5595 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5596 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5597 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5598 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5599 | llvm_unreachable("conversion functions are permitted"); |
| 5600 | } |
| 5601 | } ConvertDiagnoser; |
| 5602 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5603 | } |
| 5604 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5605 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5606 | OpenMPClauseKind CKind, |
| 5607 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5608 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 5609 | !ValExpr->isInstantiationDependent()) { |
| 5610 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 5611 | ExprResult Value = |
| 5612 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 5613 | if (Value.isInvalid()) |
| 5614 | return false; |
| 5615 | |
| 5616 | ValExpr = Value.get(); |
| 5617 | // The expression must evaluate to a non-negative integer value. |
| 5618 | llvm::APSInt Result; |
| 5619 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5620 | Result.isSigned() && |
| 5621 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 5622 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5623 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5624 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5625 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5626 | return false; |
| 5627 | } |
| 5628 | } |
| 5629 | return true; |
| 5630 | } |
| 5631 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5632 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5633 | SourceLocation StartLoc, |
| 5634 | SourceLocation LParenLoc, |
| 5635 | SourceLocation EndLoc) { |
| 5636 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5637 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5638 | // OpenMP [2.5, Restrictions] |
| 5639 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5640 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 5641 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5642 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5643 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5644 | return new (Context) |
| 5645 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5646 | } |
| 5647 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5648 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 5649 | OpenMPClauseKind CKind) { |
| 5650 | if (!E) |
| 5651 | return ExprError(); |
| 5652 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5653 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5654 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5655 | llvm::APSInt Result; |
| 5656 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5657 | if (ICE.isInvalid()) |
| 5658 | return ExprError(); |
| 5659 | if (!Result.isStrictlyPositive()) { |
| 5660 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5661 | << getOpenMPClauseName(CKind) << 1 << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5662 | return ExprError(); |
| 5663 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5664 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5665 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5666 | << E->getSourceRange(); |
| 5667 | return ExprError(); |
| 5668 | } |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5669 | if (CKind == OMPC_collapse) |
| 5670 | DSAStack->setCollapseNumber(Result.getExtValue()); |
| 5671 | else if (CKind == OMPC_ordered) |
| 5672 | DSAStack->setCollapseNumber(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5673 | return ICE; |
| 5674 | } |
| 5675 | |
| 5676 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5677 | SourceLocation LParenLoc, |
| 5678 | SourceLocation EndLoc) { |
| 5679 | // OpenMP [2.8.1, simd construct, Description] |
| 5680 | // The parameter of the safelen clause must be a constant |
| 5681 | // positive integer expression. |
| 5682 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5683 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5684 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5685 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5686 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5687 | } |
| 5688 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5689 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5690 | SourceLocation LParenLoc, |
| 5691 | SourceLocation EndLoc) { |
| 5692 | // OpenMP [2.8.1, simd construct, Description] |
| 5693 | // The parameter of the simdlen clause must be a constant |
| 5694 | // positive integer expression. |
| 5695 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5696 | if (Simdlen.isInvalid()) |
| 5697 | return nullptr; |
| 5698 | return new (Context) |
| 5699 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5700 | } |
| 5701 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5702 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5703 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5704 | SourceLocation LParenLoc, |
| 5705 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5706 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5707 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5708 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5709 | // The parameter of the collapse clause must be a constant |
| 5710 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5711 | ExprResult NumForLoopsResult = |
| 5712 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5713 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5714 | return nullptr; |
| 5715 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5716 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5717 | } |
| 5718 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5719 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5720 | SourceLocation EndLoc, |
| 5721 | SourceLocation LParenLoc, |
| 5722 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5723 | // OpenMP [2.7.1, loop construct, Description] |
| 5724 | // OpenMP [2.8.1, simd construct, Description] |
| 5725 | // OpenMP [2.9.6, distribute construct, Description] |
| 5726 | // The parameter of the ordered clause must be a constant |
| 5727 | // positive integer expression if any. |
| 5728 | if (NumForLoops && LParenLoc.isValid()) { |
| 5729 | ExprResult NumForLoopsResult = |
| 5730 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5731 | if (NumForLoopsResult.isInvalid()) |
| 5732 | return nullptr; |
| 5733 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5734 | } else |
| 5735 | NumForLoops = nullptr; |
| 5736 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5737 | return new (Context) |
| 5738 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5739 | } |
| 5740 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5741 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5742 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5743 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5744 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5745 | switch (Kind) { |
| 5746 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5747 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5748 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5749 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5750 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5751 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5752 | Res = ActOnOpenMPProcBindClause( |
| 5753 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5754 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5755 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5756 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5757 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5758 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5759 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5760 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5761 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5762 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5763 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5764 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5765 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5766 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5767 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5768 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5769 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5770 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5771 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5772 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5773 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5774 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5775 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5776 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5777 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5778 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5779 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5780 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5781 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5782 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5783 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5784 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5785 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5786 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5787 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5788 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5789 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5790 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5791 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5792 | case OMPC_nogroup: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5793 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5794 | llvm_unreachable("Clause is not allowed."); |
| 5795 | } |
| 5796 | return Res; |
| 5797 | } |
| 5798 | |
| 5799 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 5800 | SourceLocation KindKwLoc, |
| 5801 | SourceLocation StartLoc, |
| 5802 | SourceLocation LParenLoc, |
| 5803 | SourceLocation EndLoc) { |
| 5804 | if (Kind == OMPC_DEFAULT_unknown) { |
| 5805 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5806 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 5807 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 5808 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5809 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5810 | Values += "'"; |
| 5811 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 5812 | Values += "'"; |
| 5813 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5814 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5815 | Values += " or "; |
| 5816 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5817 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5818 | break; |
| 5819 | default: |
| 5820 | Values += Sep; |
| 5821 | break; |
| 5822 | } |
| 5823 | } |
| 5824 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5825 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5826 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5827 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5828 | switch (Kind) { |
| 5829 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5830 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5831 | break; |
| 5832 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5833 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5834 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5835 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5836 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5837 | break; |
| 5838 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5839 | return new (Context) |
| 5840 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5841 | } |
| 5842 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5843 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5844 | SourceLocation KindKwLoc, |
| 5845 | SourceLocation StartLoc, |
| 5846 | SourceLocation LParenLoc, |
| 5847 | SourceLocation EndLoc) { |
| 5848 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5849 | std::string Values; |
| 5850 | std::string Sep(", "); |
| 5851 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 5852 | Values += "'"; |
| 5853 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 5854 | Values += "'"; |
| 5855 | switch (i) { |
| 5856 | case OMPC_PROC_BIND_unknown - 2: |
| 5857 | Values += " or "; |
| 5858 | break; |
| 5859 | case OMPC_PROC_BIND_unknown - 1: |
| 5860 | break; |
| 5861 | default: |
| 5862 | Values += Sep; |
| 5863 | break; |
| 5864 | } |
| 5865 | } |
| 5866 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5867 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5868 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5869 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5870 | return new (Context) |
| 5871 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5872 | } |
| 5873 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5874 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 5875 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 5876 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5877 | SourceLocation ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5878 | SourceLocation EndLoc) { |
| 5879 | OMPClause *Res = nullptr; |
| 5880 | switch (Kind) { |
| 5881 | case OMPC_schedule: |
| 5882 | Res = ActOnOpenMPScheduleClause( |
| 5883 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5884 | LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5885 | break; |
| 5886 | case OMPC_if: |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5887 | Res = |
| 5888 | ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr, |
| 5889 | StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
| 5890 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5891 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5892 | case OMPC_num_threads: |
| 5893 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5894 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5895 | case OMPC_collapse: |
| 5896 | case OMPC_default: |
| 5897 | case OMPC_proc_bind: |
| 5898 | case OMPC_private: |
| 5899 | case OMPC_firstprivate: |
| 5900 | case OMPC_lastprivate: |
| 5901 | case OMPC_shared: |
| 5902 | case OMPC_reduction: |
| 5903 | case OMPC_linear: |
| 5904 | case OMPC_aligned: |
| 5905 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5906 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5907 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5908 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5909 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5910 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5911 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5912 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5913 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5914 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5915 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5916 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5917 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5918 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5919 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5920 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5921 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5922 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5923 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5924 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5925 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5926 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5927 | case OMPC_nogroup: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5928 | case OMPC_unknown: |
| 5929 | llvm_unreachable("Clause is not allowed."); |
| 5930 | } |
| 5931 | return Res; |
| 5932 | } |
| 5933 | |
| 5934 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 5935 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 5936 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 5937 | SourceLocation EndLoc) { |
| 5938 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 5939 | std::string Values; |
| 5940 | std::string Sep(", "); |
| 5941 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 5942 | Values += "'"; |
| 5943 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 5944 | Values += "'"; |
| 5945 | switch (i) { |
| 5946 | case OMPC_SCHEDULE_unknown - 2: |
| 5947 | Values += " or "; |
| 5948 | break; |
| 5949 | case OMPC_SCHEDULE_unknown - 1: |
| 5950 | break; |
| 5951 | default: |
| 5952 | Values += Sep; |
| 5953 | break; |
| 5954 | } |
| 5955 | } |
| 5956 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 5957 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 5958 | return nullptr; |
| 5959 | } |
| 5960 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5961 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5962 | if (ChunkSize) { |
| 5963 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 5964 | !ChunkSize->isInstantiationDependent() && |
| 5965 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 5966 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 5967 | ExprResult Val = |
| 5968 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 5969 | if (Val.isInvalid()) |
| 5970 | return nullptr; |
| 5971 | |
| 5972 | ValExpr = Val.get(); |
| 5973 | |
| 5974 | // OpenMP [2.7.1, Restrictions] |
| 5975 | // chunk_size must be a loop invariant integer expression with a positive |
| 5976 | // value. |
| 5977 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5978 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 5979 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 5980 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5981 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5982 | return nullptr; |
| 5983 | } |
| 5984 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 5985 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 5986 | ChunkSize->getType(), ".chunk."); |
| 5987 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 5988 | ChunkSize->getExprLoc(), |
| 5989 | /*RefersToCapture=*/true); |
| 5990 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5991 | } |
| 5992 | } |
| 5993 | } |
| 5994 | |
| 5995 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5996 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5997 | } |
| 5998 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5999 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6000 | SourceLocation StartLoc, |
| 6001 | SourceLocation EndLoc) { |
| 6002 | OMPClause *Res = nullptr; |
| 6003 | switch (Kind) { |
| 6004 | case OMPC_ordered: |
| 6005 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6006 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6007 | case OMPC_nowait: |
| 6008 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6009 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6010 | case OMPC_untied: |
| 6011 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6012 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6013 | case OMPC_mergeable: |
| 6014 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6015 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6016 | case OMPC_read: |
| 6017 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6018 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6019 | case OMPC_write: |
| 6020 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6021 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6022 | case OMPC_update: |
| 6023 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6024 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6025 | case OMPC_capture: |
| 6026 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6027 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6028 | case OMPC_seq_cst: |
| 6029 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6030 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6031 | case OMPC_threads: |
| 6032 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6033 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6034 | case OMPC_simd: |
| 6035 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6036 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6037 | case OMPC_nogroup: |
| 6038 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6039 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6040 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6041 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6042 | case OMPC_num_threads: |
| 6043 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6044 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6045 | case OMPC_collapse: |
| 6046 | case OMPC_schedule: |
| 6047 | case OMPC_private: |
| 6048 | case OMPC_firstprivate: |
| 6049 | case OMPC_lastprivate: |
| 6050 | case OMPC_shared: |
| 6051 | case OMPC_reduction: |
| 6052 | case OMPC_linear: |
| 6053 | case OMPC_aligned: |
| 6054 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6055 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6056 | case OMPC_default: |
| 6057 | case OMPC_proc_bind: |
| 6058 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6059 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6060 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6061 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6062 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6063 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6064 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6065 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6066 | case OMPC_grainsize: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6067 | case OMPC_unknown: |
| 6068 | llvm_unreachable("Clause is not allowed."); |
| 6069 | } |
| 6070 | return Res; |
| 6071 | } |
| 6072 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6073 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6074 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6075 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6076 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6077 | } |
| 6078 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6079 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6080 | SourceLocation EndLoc) { |
| 6081 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6082 | } |
| 6083 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6084 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6085 | SourceLocation EndLoc) { |
| 6086 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6087 | } |
| 6088 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6089 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6090 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6091 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6092 | } |
| 6093 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6094 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6095 | SourceLocation EndLoc) { |
| 6096 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6097 | } |
| 6098 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6099 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6100 | SourceLocation EndLoc) { |
| 6101 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6102 | } |
| 6103 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6104 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6105 | SourceLocation EndLoc) { |
| 6106 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6107 | } |
| 6108 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6109 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6110 | SourceLocation EndLoc) { |
| 6111 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6112 | } |
| 6113 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6114 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6115 | SourceLocation EndLoc) { |
| 6116 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6117 | } |
| 6118 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6119 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6120 | SourceLocation EndLoc) { |
| 6121 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6122 | } |
| 6123 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6124 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6125 | SourceLocation EndLoc) { |
| 6126 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6127 | } |
| 6128 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6129 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6130 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6131 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6132 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6133 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6134 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6135 | OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6136 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6137 | switch (Kind) { |
| 6138 | case OMPC_private: |
| 6139 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6140 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6141 | case OMPC_firstprivate: |
| 6142 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6143 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6144 | case OMPC_lastprivate: |
| 6145 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6146 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6147 | case OMPC_shared: |
| 6148 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6149 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6150 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6151 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6152 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6153 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6154 | case OMPC_linear: |
| 6155 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6156 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6157 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6158 | case OMPC_aligned: |
| 6159 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6160 | ColonLoc, EndLoc); |
| 6161 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6162 | case OMPC_copyin: |
| 6163 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6164 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6165 | case OMPC_copyprivate: |
| 6166 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6167 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6168 | case OMPC_flush: |
| 6169 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6170 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6171 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6172 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6173 | StartLoc, LParenLoc, EndLoc); |
| 6174 | break; |
| 6175 | case OMPC_map: |
| 6176 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, DepLinMapLoc, ColonLoc, |
| 6177 | VarList, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6178 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6179 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6180 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6181 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6182 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6183 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6184 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6185 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6186 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6187 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6188 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6189 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6190 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6191 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6192 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6193 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6194 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6195 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6196 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6197 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6198 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6199 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6200 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6201 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6202 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6203 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6204 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6205 | case OMPC_nogroup: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6206 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6207 | llvm_unreachable("Clause is not allowed."); |
| 6208 | } |
| 6209 | return Res; |
| 6210 | } |
| 6211 | |
| 6212 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6213 | SourceLocation StartLoc, |
| 6214 | SourceLocation LParenLoc, |
| 6215 | SourceLocation EndLoc) { |
| 6216 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6217 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6218 | for (auto &RefExpr : VarList) { |
| 6219 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 6220 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6221 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6222 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6223 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6224 | continue; |
| 6225 | } |
| 6226 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6227 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6228 | // OpenMP [2.1, C/C++] |
| 6229 | // A list item is a variable name. |
| 6230 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6231 | // A variable that is part of another variable (as an array or |
| 6232 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6233 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6234 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6235 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6236 | continue; |
| 6237 | } |
| 6238 | Decl *D = DE->getDecl(); |
| 6239 | VarDecl *VD = cast<VarDecl>(D); |
| 6240 | |
| 6241 | QualType Type = VD->getType(); |
| 6242 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6243 | // It will be analyzed later. |
| 6244 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6245 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6246 | continue; |
| 6247 | } |
| 6248 | |
| 6249 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6250 | // A variable that appears in a private clause must not have an incomplete |
| 6251 | // type or a reference type. |
| 6252 | if (RequireCompleteType(ELoc, Type, |
| 6253 | diag::err_omp_private_incomplete_type)) { |
| 6254 | continue; |
| 6255 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6256 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6257 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6258 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6259 | // in a Construct] |
| 6260 | // Variables with the predetermined data-sharing attributes may not be |
| 6261 | // listed in data-sharing attributes clauses, except for the cases |
| 6262 | // listed below. For these exceptions only, listing a predetermined |
| 6263 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6264 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6265 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6266 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6267 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6268 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6269 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6270 | continue; |
| 6271 | } |
| 6272 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6273 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6274 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6275 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6276 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6277 | << getOpenMPClauseName(OMPC_private) << Type |
| 6278 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6279 | bool IsDecl = |
| 6280 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6281 | Diag(VD->getLocation(), |
| 6282 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6283 | << VD; |
| 6284 | continue; |
| 6285 | } |
| 6286 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6287 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6288 | // A variable of class type (or array thereof) that appears in a private |
| 6289 | // clause requires an accessible, unambiguous default constructor for the |
| 6290 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6291 | // Generate helper private variable and initialize it with the default |
| 6292 | // value. The address of the original variable is replaced by the address of |
| 6293 | // the new private variable in CodeGen. This new variable is not added to |
| 6294 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6295 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6296 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6297 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 6298 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6299 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6300 | if (VDPrivate->isInvalidDecl()) |
| 6301 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6302 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6303 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6304 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6305 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6306 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6307 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6308 | } |
| 6309 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6310 | if (Vars.empty()) |
| 6311 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6312 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6313 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6314 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6315 | } |
| 6316 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6317 | namespace { |
| 6318 | class DiagsUninitializedSeveretyRAII { |
| 6319 | private: |
| 6320 | DiagnosticsEngine &Diags; |
| 6321 | SourceLocation SavedLoc; |
| 6322 | bool IsIgnored; |
| 6323 | |
| 6324 | public: |
| 6325 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6326 | bool IsIgnored) |
| 6327 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6328 | if (!IsIgnored) { |
| 6329 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6330 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6331 | } |
| 6332 | } |
| 6333 | ~DiagsUninitializedSeveretyRAII() { |
| 6334 | if (!IsIgnored) |
| 6335 | Diags.popMappings(SavedLoc); |
| 6336 | } |
| 6337 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6338 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6339 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6340 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6341 | SourceLocation StartLoc, |
| 6342 | SourceLocation LParenLoc, |
| 6343 | SourceLocation EndLoc) { |
| 6344 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6345 | SmallVector<Expr *, 8> PrivateCopies; |
| 6346 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6347 | bool IsImplicitClause = |
| 6348 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6349 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6350 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6351 | for (auto &RefExpr : VarList) { |
| 6352 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6353 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6354 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6355 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6356 | PrivateCopies.push_back(nullptr); |
| 6357 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6358 | continue; |
| 6359 | } |
| 6360 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6361 | SourceLocation ELoc = |
| 6362 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6363 | // OpenMP [2.1, C/C++] |
| 6364 | // A list item is a variable name. |
| 6365 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6366 | // A variable that is part of another variable (as an array or |
| 6367 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6368 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6369 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6370 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6371 | continue; |
| 6372 | } |
| 6373 | Decl *D = DE->getDecl(); |
| 6374 | VarDecl *VD = cast<VarDecl>(D); |
| 6375 | |
| 6376 | QualType Type = VD->getType(); |
| 6377 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6378 | // It will be analyzed later. |
| 6379 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6380 | PrivateCopies.push_back(nullptr); |
| 6381 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6382 | continue; |
| 6383 | } |
| 6384 | |
| 6385 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6386 | // A variable that appears in a private clause must not have an incomplete |
| 6387 | // type or a reference type. |
| 6388 | if (RequireCompleteType(ELoc, Type, |
| 6389 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6390 | continue; |
| 6391 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6392 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6393 | |
| 6394 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6395 | // 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] | 6396 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6397 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6398 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6399 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6400 | // If an implicit firstprivate variable found it was checked already. |
| 6401 | if (!IsImplicitClause) { |
| 6402 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6403 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6404 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6405 | // A list item that specifies a given variable may not appear in more |
| 6406 | // than one clause on the same directive, except that a variable may be |
| 6407 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6408 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6409 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6410 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6411 | << getOpenMPClauseName(DVar.CKind) |
| 6412 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6413 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6414 | continue; |
| 6415 | } |
| 6416 | |
| 6417 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6418 | // in a Construct] |
| 6419 | // Variables with the predetermined data-sharing attributes may not be |
| 6420 | // listed in data-sharing attributes clauses, except for the cases |
| 6421 | // listed below. For these exceptions only, listing a predetermined |
| 6422 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6423 | // the variable's predetermined data-sharing attributes. |
| 6424 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6425 | // in a Construct, C/C++, p.2] |
| 6426 | // Variables with const-qualified type having no mutable member may be |
| 6427 | // listed in a firstprivate clause, even if they are static data members. |
| 6428 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6429 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6430 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6431 | << getOpenMPClauseName(DVar.CKind) |
| 6432 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6433 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6434 | continue; |
| 6435 | } |
| 6436 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6437 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6438 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6439 | // A list item that is private within a parallel region must not appear |
| 6440 | // in a firstprivate clause on a worksharing construct if any of the |
| 6441 | // worksharing regions arising from the worksharing construct ever bind |
| 6442 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6443 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6444 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6445 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6446 | if (DVar.CKind != OMPC_shared && |
| 6447 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6448 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6449 | Diag(ELoc, diag::err_omp_required_access) |
| 6450 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6451 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6452 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6453 | continue; |
| 6454 | } |
| 6455 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6456 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6457 | // A list item that appears in a reduction clause of a parallel construct |
| 6458 | // must not appear in a firstprivate clause on a worksharing or task |
| 6459 | // construct if any of the worksharing or task regions arising from the |
| 6460 | // worksharing or task construct ever bind to any of the parallel regions |
| 6461 | // arising from the parallel construct. |
| 6462 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6463 | // A list item that appears in a reduction clause in worksharing |
| 6464 | // construct must not appear in a firstprivate clause in a task construct |
| 6465 | // encountered during execution of any of the worksharing regions arising |
| 6466 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6467 | if (CurrDir == OMPD_task) { |
| 6468 | DVar = |
| 6469 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6470 | [](OpenMPDirectiveKind K) -> bool { |
| 6471 | return isOpenMPParallelDirective(K) || |
| 6472 | isOpenMPWorksharingDirective(K); |
| 6473 | }, |
| 6474 | false); |
| 6475 | if (DVar.CKind == OMPC_reduction && |
| 6476 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6477 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6478 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6479 | << getOpenMPDirectiveName(DVar.DKind); |
| 6480 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6481 | continue; |
| 6482 | } |
| 6483 | } |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 6484 | |
| 6485 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6486 | // A list item that is private within a teams region must not appear in a |
| 6487 | // firstprivate clause on a distribute construct if any of the distribute |
| 6488 | // regions arising from the distribute construct ever bind to any of the |
| 6489 | // teams regions arising from the teams construct. |
| 6490 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6491 | // A list item that appears in a reduction clause of a teams construct |
| 6492 | // must not appear in a firstprivate clause on a distribute construct if |
| 6493 | // any of the distribute regions arising from the distribute construct |
| 6494 | // ever bind to any of the teams regions arising from the teams construct. |
| 6495 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6496 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6497 | // both. |
| 6498 | if (CurrDir == OMPD_distribute) { |
| 6499 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 6500 | [](OpenMPDirectiveKind K) -> bool { |
| 6501 | return isOpenMPTeamsDirective(K); |
| 6502 | }, |
| 6503 | false); |
| 6504 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 6505 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 6506 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6507 | continue; |
| 6508 | } |
| 6509 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6510 | [](OpenMPDirectiveKind K) -> bool { |
| 6511 | return isOpenMPTeamsDirective(K); |
| 6512 | }, |
| 6513 | false); |
| 6514 | if (DVar.CKind == OMPC_reduction && |
| 6515 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 6516 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 6517 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6518 | continue; |
| 6519 | } |
| 6520 | DVar = DSAStack->getTopDSA(VD, false); |
| 6521 | if (DVar.CKind == OMPC_lastprivate) { |
| 6522 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6523 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6524 | continue; |
| 6525 | } |
| 6526 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6527 | } |
| 6528 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6529 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6530 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6531 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6532 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6533 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6534 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6535 | bool IsDecl = |
| 6536 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6537 | Diag(VD->getLocation(), |
| 6538 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6539 | << VD; |
| 6540 | continue; |
| 6541 | } |
| 6542 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6543 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6544 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6545 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6546 | // Generate helper private variable and initialize it with the value of the |
| 6547 | // original variable. The address of the original variable is replaced by |
| 6548 | // the address of the new private variable in the CodeGen. This new variable |
| 6549 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 6550 | // original variable for proper diagnostics and variable capturing. |
| 6551 | Expr *VDInitRefExpr = nullptr; |
| 6552 | // For arrays generate initializer for single element and replace it by the |
| 6553 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6554 | if (Type->isArrayType()) { |
| 6555 | auto VDInit = |
| 6556 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 6557 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6558 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6559 | ElemType = ElemType.getUnqualifiedType(); |
| 6560 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 6561 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6562 | InitializedEntity Entity = |
| 6563 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6564 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 6565 | |
| 6566 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 6567 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 6568 | if (Result.isInvalid()) |
| 6569 | VDPrivate->setInvalidDecl(); |
| 6570 | else |
| 6571 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6572 | // Remove temp variable declaration. |
| 6573 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6574 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6575 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6576 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6577 | VDInitRefExpr = |
| 6578 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6579 | AddInitializerToDecl(VDPrivate, |
| 6580 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 6581 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6582 | } |
| 6583 | if (VDPrivate->isInvalidDecl()) { |
| 6584 | if (IsImplicitClause) { |
| 6585 | Diag(DE->getExprLoc(), |
| 6586 | diag::note_omp_task_predetermined_firstprivate_here); |
| 6587 | } |
| 6588 | continue; |
| 6589 | } |
| 6590 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6591 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6592 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6593 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 6594 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6595 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 6596 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6597 | } |
| 6598 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6599 | if (Vars.empty()) |
| 6600 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6601 | |
| 6602 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6603 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6604 | } |
| 6605 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6606 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6607 | SourceLocation StartLoc, |
| 6608 | SourceLocation LParenLoc, |
| 6609 | SourceLocation EndLoc) { |
| 6610 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6611 | SmallVector<Expr *, 8> SrcExprs; |
| 6612 | SmallVector<Expr *, 8> DstExprs; |
| 6613 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6614 | for (auto &RefExpr : VarList) { |
| 6615 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 6616 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6617 | // It will be analyzed later. |
| 6618 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6619 | SrcExprs.push_back(nullptr); |
| 6620 | DstExprs.push_back(nullptr); |
| 6621 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6622 | continue; |
| 6623 | } |
| 6624 | |
| 6625 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6626 | // OpenMP [2.1, C/C++] |
| 6627 | // A list item is a variable name. |
| 6628 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 6629 | // A variable that is part of another variable (as an array or structure |
| 6630 | // element) cannot appear in a lastprivate clause. |
| 6631 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 6632 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6633 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6634 | continue; |
| 6635 | } |
| 6636 | Decl *D = DE->getDecl(); |
| 6637 | VarDecl *VD = cast<VarDecl>(D); |
| 6638 | |
| 6639 | QualType Type = VD->getType(); |
| 6640 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6641 | // It will be analyzed later. |
| 6642 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6643 | SrcExprs.push_back(nullptr); |
| 6644 | DstExprs.push_back(nullptr); |
| 6645 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6646 | continue; |
| 6647 | } |
| 6648 | |
| 6649 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6650 | // A variable that appears in a lastprivate clause must not have an |
| 6651 | // incomplete type or a reference type. |
| 6652 | if (RequireCompleteType(ELoc, Type, |
| 6653 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6654 | continue; |
| 6655 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6656 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6657 | |
| 6658 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6659 | // in a Construct] |
| 6660 | // Variables with the predetermined data-sharing attributes may not be |
| 6661 | // listed in data-sharing attributes clauses, except for the cases |
| 6662 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6663 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6664 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6665 | DVar.CKind != OMPC_firstprivate && |
| 6666 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6667 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6668 | << getOpenMPClauseName(DVar.CKind) |
| 6669 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6670 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6671 | continue; |
| 6672 | } |
| 6673 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6674 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6675 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6676 | // A list item that is private within a parallel region, or that appears in |
| 6677 | // the reduction clause of a parallel construct, must not appear in a |
| 6678 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6679 | // worksharing regions ever binds to any of the corresponding parallel |
| 6680 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6681 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6682 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6683 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6684 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6685 | if (DVar.CKind != OMPC_shared) { |
| 6686 | Diag(ELoc, diag::err_omp_required_access) |
| 6687 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6688 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6689 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6690 | continue; |
| 6691 | } |
| 6692 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6693 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6694 | // A variable of class type (or array thereof) that appears in a |
| 6695 | // lastprivate clause requires an accessible, unambiguous default |
| 6696 | // constructor for the class type, unless the list item is also specified |
| 6697 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6698 | // A variable of class type (or array thereof) that appears in a |
| 6699 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6700 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6701 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6702 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6703 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6704 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6705 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6706 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6707 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6708 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6709 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6710 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6711 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6712 | // For arrays generate assignment operation for single element and replace |
| 6713 | // it by the original array element in CodeGen. |
| 6714 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6715 | PseudoDstExpr, PseudoSrcExpr); |
| 6716 | if (AssignmentOp.isInvalid()) |
| 6717 | continue; |
| 6718 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6719 | /*DiscardedValue=*/true); |
| 6720 | if (AssignmentOp.isInvalid()) |
| 6721 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6722 | |
Carlo Bertolli | b9bfa75 | 2015-12-08 04:21:03 +0000 | [diff] [blame] | 6723 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6724 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6725 | // both. |
| 6726 | if (CurrDir == OMPD_distribute) { |
| 6727 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 6728 | if (DVar.CKind == OMPC_firstprivate) { |
| 6729 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6730 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6731 | continue; |
| 6732 | } |
| 6733 | } |
| 6734 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6735 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6736 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6737 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6738 | SrcExprs.push_back(PseudoSrcExpr); |
| 6739 | DstExprs.push_back(PseudoDstExpr); |
| 6740 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6741 | } |
| 6742 | |
| 6743 | if (Vars.empty()) |
| 6744 | return nullptr; |
| 6745 | |
| 6746 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6747 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6748 | } |
| 6749 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6750 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 6751 | SourceLocation StartLoc, |
| 6752 | SourceLocation LParenLoc, |
| 6753 | SourceLocation EndLoc) { |
| 6754 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6755 | for (auto &RefExpr : VarList) { |
| 6756 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6757 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6758 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6759 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6760 | continue; |
| 6761 | } |
| 6762 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6763 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6764 | // OpenMP [2.1, C/C++] |
| 6765 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 6766 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 6767 | // A variable that is part of another variable (as an array or structure |
| 6768 | // element) cannot appear in a shared unless it is a static data member |
| 6769 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6770 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6771 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6772 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6773 | continue; |
| 6774 | } |
| 6775 | Decl *D = DE->getDecl(); |
| 6776 | VarDecl *VD = cast<VarDecl>(D); |
| 6777 | |
| 6778 | QualType Type = VD->getType(); |
| 6779 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6780 | // It will be analyzed later. |
| 6781 | Vars.push_back(DE); |
| 6782 | continue; |
| 6783 | } |
| 6784 | |
| 6785 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6786 | // in a Construct] |
| 6787 | // Variables with the predetermined data-sharing attributes may not be |
| 6788 | // listed in data-sharing attributes clauses, except for the cases |
| 6789 | // listed below. For these exceptions only, listing a predetermined |
| 6790 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6791 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6792 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6793 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 6794 | DVar.RefExpr) { |
| 6795 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6796 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6797 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6798 | continue; |
| 6799 | } |
| 6800 | |
| 6801 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 6802 | Vars.push_back(DE); |
| 6803 | } |
| 6804 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6805 | if (Vars.empty()) |
| 6806 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6807 | |
| 6808 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 6809 | } |
| 6810 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6811 | namespace { |
| 6812 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 6813 | DSAStackTy *Stack; |
| 6814 | |
| 6815 | public: |
| 6816 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 6817 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6818 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6819 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 6820 | return false; |
| 6821 | if (DVar.CKind != OMPC_unknown) |
| 6822 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6823 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6824 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6825 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6826 | return true; |
| 6827 | return false; |
| 6828 | } |
| 6829 | return false; |
| 6830 | } |
| 6831 | bool VisitStmt(Stmt *S) { |
| 6832 | for (auto Child : S->children()) { |
| 6833 | if (Child && Visit(Child)) |
| 6834 | return true; |
| 6835 | } |
| 6836 | return false; |
| 6837 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6838 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6839 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6840 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6841 | |
| 6842 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 6843 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 6844 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 6845 | CXXScopeSpec &ReductionIdScopeSpec, |
| 6846 | const DeclarationNameInfo &ReductionId) { |
| 6847 | // TODO: Allow scope specification search when 'declare reduction' is |
| 6848 | // supported. |
| 6849 | assert(ReductionIdScopeSpec.isEmpty() && |
| 6850 | "No support for scoped reduction identifiers yet."); |
| 6851 | |
| 6852 | auto DN = ReductionId.getName(); |
| 6853 | auto OOK = DN.getCXXOverloadedOperator(); |
| 6854 | BinaryOperatorKind BOK = BO_Comma; |
| 6855 | |
| 6856 | // OpenMP [2.14.3.6, reduction clause] |
| 6857 | // C |
| 6858 | // reduction-identifier is either an identifier or one of the following |
| 6859 | // operators: +, -, *, &, |, ^, && and || |
| 6860 | // C++ |
| 6861 | // reduction-identifier is either an id-expression or one of the following |
| 6862 | // operators: +, -, *, &, |, ^, && and || |
| 6863 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 6864 | switch (OOK) { |
| 6865 | case OO_Plus: |
| 6866 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6867 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6868 | break; |
| 6869 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6870 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6871 | break; |
| 6872 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6873 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6874 | break; |
| 6875 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6876 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6877 | break; |
| 6878 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6879 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6880 | break; |
| 6881 | case OO_AmpAmp: |
| 6882 | BOK = BO_LAnd; |
| 6883 | break; |
| 6884 | case OO_PipePipe: |
| 6885 | BOK = BO_LOr; |
| 6886 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6887 | case OO_New: |
| 6888 | case OO_Delete: |
| 6889 | case OO_Array_New: |
| 6890 | case OO_Array_Delete: |
| 6891 | case OO_Slash: |
| 6892 | case OO_Percent: |
| 6893 | case OO_Tilde: |
| 6894 | case OO_Exclaim: |
| 6895 | case OO_Equal: |
| 6896 | case OO_Less: |
| 6897 | case OO_Greater: |
| 6898 | case OO_LessEqual: |
| 6899 | case OO_GreaterEqual: |
| 6900 | case OO_PlusEqual: |
| 6901 | case OO_MinusEqual: |
| 6902 | case OO_StarEqual: |
| 6903 | case OO_SlashEqual: |
| 6904 | case OO_PercentEqual: |
| 6905 | case OO_CaretEqual: |
| 6906 | case OO_AmpEqual: |
| 6907 | case OO_PipeEqual: |
| 6908 | case OO_LessLess: |
| 6909 | case OO_GreaterGreater: |
| 6910 | case OO_LessLessEqual: |
| 6911 | case OO_GreaterGreaterEqual: |
| 6912 | case OO_EqualEqual: |
| 6913 | case OO_ExclaimEqual: |
| 6914 | case OO_PlusPlus: |
| 6915 | case OO_MinusMinus: |
| 6916 | case OO_Comma: |
| 6917 | case OO_ArrowStar: |
| 6918 | case OO_Arrow: |
| 6919 | case OO_Call: |
| 6920 | case OO_Subscript: |
| 6921 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 6922 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6923 | case NUM_OVERLOADED_OPERATORS: |
| 6924 | llvm_unreachable("Unexpected reduction identifier"); |
| 6925 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6926 | if (auto II = DN.getAsIdentifierInfo()) { |
| 6927 | if (II->isStr("max")) |
| 6928 | BOK = BO_GT; |
| 6929 | else if (II->isStr("min")) |
| 6930 | BOK = BO_LT; |
| 6931 | } |
| 6932 | break; |
| 6933 | } |
| 6934 | SourceRange ReductionIdRange; |
| 6935 | if (ReductionIdScopeSpec.isValid()) { |
| 6936 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 6937 | } |
| 6938 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 6939 | if (BOK == BO_Comma) { |
| 6940 | // Not allowed reduction identifier is found. |
| 6941 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 6942 | << ReductionIdRange; |
| 6943 | return nullptr; |
| 6944 | } |
| 6945 | |
| 6946 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6947 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6948 | SmallVector<Expr *, 8> LHSs; |
| 6949 | SmallVector<Expr *, 8> RHSs; |
| 6950 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6951 | for (auto RefExpr : VarList) { |
| 6952 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 6953 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6954 | // It will be analyzed later. |
| 6955 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6956 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6957 | LHSs.push_back(nullptr); |
| 6958 | RHSs.push_back(nullptr); |
| 6959 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6960 | continue; |
| 6961 | } |
| 6962 | |
| 6963 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6964 | RefExpr->isInstantiationDependent() || |
| 6965 | RefExpr->containsUnexpandedParameterPack()) { |
| 6966 | // It will be analyzed later. |
| 6967 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6968 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6969 | LHSs.push_back(nullptr); |
| 6970 | RHSs.push_back(nullptr); |
| 6971 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6972 | continue; |
| 6973 | } |
| 6974 | |
| 6975 | auto ELoc = RefExpr->getExprLoc(); |
| 6976 | auto ERange = RefExpr->getSourceRange(); |
| 6977 | // OpenMP [2.1, C/C++] |
| 6978 | // A list item is a variable or array section, subject to the restrictions |
| 6979 | // specified in Section 2.4 on page 42 and in each of the sections |
| 6980 | // describing clauses and directives for which a list appears. |
| 6981 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6982 | // A variable that is part of another variable (as an array or |
| 6983 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6984 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6985 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 6986 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 6987 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
| 6988 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6989 | continue; |
| 6990 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6991 | QualType Type; |
| 6992 | VarDecl *VD = nullptr; |
| 6993 | if (DE) { |
| 6994 | auto D = DE->getDecl(); |
| 6995 | VD = cast<VarDecl>(D); |
| 6996 | Type = VD->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6997 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6998 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6999 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7000 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7001 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7002 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7003 | if (DE) |
| 7004 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7005 | if (!VD) { |
| 7006 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7007 | << 0 << Base->getSourceRange(); |
| 7008 | continue; |
| 7009 | } |
| 7010 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7011 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7012 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7013 | Type = ATy->getElementType(); |
| 7014 | else |
| 7015 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7016 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7017 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7018 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7019 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7020 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7021 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7022 | if (DE) |
| 7023 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7024 | if (!VD) { |
| 7025 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7026 | << 1 << Base->getSourceRange(); |
| 7027 | continue; |
| 7028 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7029 | } |
| 7030 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7031 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7032 | // A variable that appears in a private clause must not have an incomplete |
| 7033 | // type or a reference type. |
| 7034 | if (RequireCompleteType(ELoc, Type, |
| 7035 | diag::err_omp_reduction_incomplete_type)) |
| 7036 | continue; |
| 7037 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7038 | // Arrays may not appear in a reduction clause. |
| 7039 | if (Type.getNonReferenceType()->isArrayType()) { |
| 7040 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7041 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7042 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7043 | VarDecl::DeclarationOnly; |
| 7044 | Diag(VD->getLocation(), |
| 7045 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7046 | << VD; |
| 7047 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7048 | continue; |
| 7049 | } |
| 7050 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7051 | // A list item that appears in a reduction clause must not be |
| 7052 | // const-qualified. |
| 7053 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7054 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7055 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7056 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7057 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7058 | VarDecl::DeclarationOnly; |
| 7059 | Diag(VD->getLocation(), |
| 7060 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7061 | << VD; |
| 7062 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7063 | continue; |
| 7064 | } |
| 7065 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7066 | // If a list-item is a reference type then it must bind to the same object |
| 7067 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7068 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7069 | VarDecl *VDDef = VD->getDefinition(); |
| 7070 | if (Type->isReferenceType() && VDDef) { |
| 7071 | DSARefChecker Check(DSAStack); |
| 7072 | if (Check.Visit(VDDef->getInit())) { |
| 7073 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7074 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7075 | continue; |
| 7076 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7077 | } |
| 7078 | } |
| 7079 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7080 | // The type of a list item that appears in a reduction clause must be valid |
| 7081 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7082 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7083 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7084 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7085 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7086 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7087 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7088 | !(Type->isScalarType() || |
| 7089 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7090 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7091 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7092 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7093 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7094 | VarDecl::DeclarationOnly; |
| 7095 | Diag(VD->getLocation(), |
| 7096 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7097 | << VD; |
| 7098 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7099 | continue; |
| 7100 | } |
| 7101 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7102 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7103 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7104 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7105 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7106 | VarDecl::DeclarationOnly; |
| 7107 | Diag(VD->getLocation(), |
| 7108 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7109 | << VD; |
| 7110 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7111 | continue; |
| 7112 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7113 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7114 | // in a Construct] |
| 7115 | // Variables with the predetermined data-sharing attributes may not be |
| 7116 | // listed in data-sharing attributes clauses, except for the cases |
| 7117 | // listed below. For these exceptions only, listing a predetermined |
| 7118 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7119 | // the variable's predetermined data-sharing attributes. |
| 7120 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7121 | // Any number of reduction clauses can be specified on the directive, |
| 7122 | // but a list item can appear only once in the reduction clauses for that |
| 7123 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7124 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7125 | DVar = DSAStack->getTopDSA(VD, false); |
| 7126 | if (DVar.CKind == OMPC_reduction) { |
| 7127 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7128 | << getOpenMPClauseName(OMPC_reduction); |
| 7129 | if (DVar.RefExpr) { |
| 7130 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7131 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7132 | } else if (DVar.CKind != OMPC_unknown) { |
| 7133 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7134 | << getOpenMPClauseName(DVar.CKind) |
| 7135 | << getOpenMPClauseName(OMPC_reduction); |
| 7136 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7137 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7138 | } |
| 7139 | |
| 7140 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7141 | // A list item that appears in a reduction clause of a worksharing |
| 7142 | // construct must be shared in the parallel regions to which any of the |
| 7143 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7144 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7145 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7146 | !isOpenMPParallelDirective(CurrDir)) { |
| 7147 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7148 | if (DVar.CKind != OMPC_shared) { |
| 7149 | Diag(ELoc, diag::err_omp_required_access) |
| 7150 | << getOpenMPClauseName(OMPC_reduction) |
| 7151 | << getOpenMPClauseName(OMPC_shared); |
| 7152 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7153 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7154 | } |
| 7155 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7156 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7157 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7158 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7159 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7160 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7161 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7162 | auto PrivateTy = Type; |
| 7163 | if (OASE) { |
| 7164 | // For array sections only: |
| 7165 | // Create pseudo array type for private copy. The size for this array will |
| 7166 | // be generated during codegen. |
| 7167 | // For array subscripts or single variables Private Ty is the same as Type |
| 7168 | // (type of the variable or single array element). |
| 7169 | PrivateTy = Context.getVariableArrayType( |
| 7170 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7171 | Context.getSizeType(), VK_RValue), |
| 7172 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| 7173 | } |
| 7174 | // Private copy. |
| 7175 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7176 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7177 | // Add initializer for private variable. |
| 7178 | Expr *Init = nullptr; |
| 7179 | switch (BOK) { |
| 7180 | case BO_Add: |
| 7181 | case BO_Xor: |
| 7182 | case BO_Or: |
| 7183 | case BO_LOr: |
| 7184 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7185 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7186 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7187 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7188 | break; |
| 7189 | case BO_Mul: |
| 7190 | case BO_LAnd: |
| 7191 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7192 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7193 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 7194 | } |
| 7195 | break; |
| 7196 | case BO_And: { |
| 7197 | // '&' reduction op - initializer is '~0'. |
| 7198 | QualType OrigType = Type; |
| 7199 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 7200 | Type = ComplexTy->getElementType(); |
| 7201 | } |
| 7202 | if (Type->isRealFloatingType()) { |
| 7203 | llvm::APFloat InitValue = |
| 7204 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 7205 | /*isIEEE=*/true); |
| 7206 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7207 | Type, ELoc); |
| 7208 | } else if (Type->isScalarType()) { |
| 7209 | auto Size = Context.getTypeSize(Type); |
| 7210 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 7211 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 7212 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7213 | } |
| 7214 | if (Init && OrigType->isAnyComplexType()) { |
| 7215 | // Init = 0xFFFF + 0xFFFFi; |
| 7216 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 7217 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 7218 | } |
| 7219 | Type = OrigType; |
| 7220 | break; |
| 7221 | } |
| 7222 | case BO_LT: |
| 7223 | case BO_GT: { |
| 7224 | // 'min' reduction op - initializer is 'Largest representable number in |
| 7225 | // the reduction list item type'. |
| 7226 | // 'max' reduction op - initializer is 'Least representable number in |
| 7227 | // the reduction list item type'. |
| 7228 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 7229 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 7230 | auto Size = Context.getTypeSize(Type); |
| 7231 | QualType IntTy = |
| 7232 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 7233 | llvm::APInt InitValue = |
| 7234 | (BOK != BO_LT) |
| 7235 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 7236 | : llvm::APInt::getMinValue(Size) |
| 7237 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 7238 | : llvm::APInt::getMaxValue(Size); |
| 7239 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7240 | if (Type->isPointerType()) { |
| 7241 | // Cast to pointer type. |
| 7242 | auto CastExpr = BuildCStyleCastExpr( |
| 7243 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 7244 | SourceLocation(), Init); |
| 7245 | if (CastExpr.isInvalid()) |
| 7246 | continue; |
| 7247 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7248 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7249 | } else if (Type->isRealFloatingType()) { |
| 7250 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 7251 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 7252 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7253 | Type, ELoc); |
| 7254 | } |
| 7255 | break; |
| 7256 | } |
| 7257 | case BO_PtrMemD: |
| 7258 | case BO_PtrMemI: |
| 7259 | case BO_MulAssign: |
| 7260 | case BO_Div: |
| 7261 | case BO_Rem: |
| 7262 | case BO_Sub: |
| 7263 | case BO_Shl: |
| 7264 | case BO_Shr: |
| 7265 | case BO_LE: |
| 7266 | case BO_GE: |
| 7267 | case BO_EQ: |
| 7268 | case BO_NE: |
| 7269 | case BO_AndAssign: |
| 7270 | case BO_XorAssign: |
| 7271 | case BO_OrAssign: |
| 7272 | case BO_Assign: |
| 7273 | case BO_AddAssign: |
| 7274 | case BO_SubAssign: |
| 7275 | case BO_DivAssign: |
| 7276 | case BO_RemAssign: |
| 7277 | case BO_ShlAssign: |
| 7278 | case BO_ShrAssign: |
| 7279 | case BO_Comma: |
| 7280 | llvm_unreachable("Unexpected reduction operation"); |
| 7281 | } |
| 7282 | if (Init) { |
| 7283 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7284 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7285 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7286 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7287 | if (!RHSVD->hasInit()) { |
| 7288 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7289 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7290 | if (VD) { |
| 7291 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7292 | VarDecl::DeclarationOnly; |
| 7293 | Diag(VD->getLocation(), |
| 7294 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7295 | << VD; |
| 7296 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7297 | continue; |
| 7298 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7299 | // Store initializer for single element in private copy. Will be used during |
| 7300 | // codegen. |
| 7301 | PrivateVD->setInit(RHSVD->getInit()); |
| 7302 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7303 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7304 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7305 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7306 | ExprResult ReductionOp = |
| 7307 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7308 | LHSDRE, RHSDRE); |
| 7309 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7310 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7311 | ReductionOp = |
| 7312 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7313 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7314 | } else { |
| 7315 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7316 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7317 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7318 | ReductionOp = |
| 7319 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7320 | BO_Assign, LHSDRE, ConditionalOp); |
| 7321 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7322 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7323 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7324 | if (ReductionOp.isInvalid()) |
| 7325 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7326 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7327 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7328 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7329 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7330 | LHSs.push_back(LHSDRE); |
| 7331 | RHSs.push_back(RHSDRE); |
| 7332 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | if (Vars.empty()) |
| 7336 | return nullptr; |
| 7337 | |
| 7338 | return OMPReductionClause::Create( |
| 7339 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7340 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7341 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7342 | } |
| 7343 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7344 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7345 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7346 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7347 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7348 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7349 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7350 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7351 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7352 | LinKind == OMPC_LINEAR_unknown) { |
| 7353 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7354 | LinKind = OMPC_LINEAR_val; |
| 7355 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7356 | for (auto &RefExpr : VarList) { |
| 7357 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7358 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7359 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7360 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7361 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7362 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7363 | continue; |
| 7364 | } |
| 7365 | |
| 7366 | // OpenMP [2.14.3.7, linear clause] |
| 7367 | // A list item that appears in a linear clause is subject to the private |
| 7368 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7369 | // noted. In addition, the value of the new list item on each iteration |
| 7370 | // of the associated loop(s) corresponds to the value of the original |
| 7371 | // list item before entering the construct plus the logical number of |
| 7372 | // the iteration times linear-step. |
| 7373 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7374 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7375 | // OpenMP [2.1, C/C++] |
| 7376 | // A list item is a variable name. |
| 7377 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7378 | // A variable that is part of another variable (as an array or |
| 7379 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7380 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7381 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7382 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7383 | continue; |
| 7384 | } |
| 7385 | |
| 7386 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7387 | |
| 7388 | // OpenMP [2.14.3.7, linear clause] |
| 7389 | // A list-item cannot appear in more than one linear clause. |
| 7390 | // A list-item that appears in a linear clause cannot appear in any |
| 7391 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7392 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7393 | if (DVar.RefExpr) { |
| 7394 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7395 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7396 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7397 | continue; |
| 7398 | } |
| 7399 | |
| 7400 | QualType QType = VD->getType(); |
| 7401 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7402 | // It will be analyzed later. |
| 7403 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7404 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7405 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7406 | continue; |
| 7407 | } |
| 7408 | |
| 7409 | // A variable must not have an incomplete type or a reference type. |
| 7410 | if (RequireCompleteType(ELoc, QType, |
| 7411 | diag::err_omp_linear_incomplete_type)) { |
| 7412 | continue; |
| 7413 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7414 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7415 | !QType->isReferenceType()) { |
| 7416 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7417 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7418 | continue; |
| 7419 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7420 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7421 | |
| 7422 | // A list item must not be const-qualified. |
| 7423 | if (QType.isConstant(Context)) { |
| 7424 | Diag(ELoc, diag::err_omp_const_variable) |
| 7425 | << getOpenMPClauseName(OMPC_linear); |
| 7426 | bool IsDecl = |
| 7427 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7428 | Diag(VD->getLocation(), |
| 7429 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7430 | << VD; |
| 7431 | continue; |
| 7432 | } |
| 7433 | |
| 7434 | // A list item must be of integral or pointer type. |
| 7435 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7436 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7437 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7438 | !Ty->isPointerType())) { |
| 7439 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 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 | } |
| 7447 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7448 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7449 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7450 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7451 | auto *PrivateRef = buildDeclRefExpr( |
| 7452 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7453 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7454 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7455 | Expr *InitExpr; |
| 7456 | if (LinKind == OMPC_LINEAR_uval) |
| 7457 | InitExpr = VD->getInit(); |
| 7458 | else |
| 7459 | InitExpr = DE; |
| 7460 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7461 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7462 | auto InitRef = buildDeclRefExpr( |
| 7463 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7464 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7465 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7466 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7467 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7468 | } |
| 7469 | |
| 7470 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7471 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7472 | |
| 7473 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7474 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7475 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7476 | !Step->isInstantiationDependent() && |
| 7477 | !Step->containsUnexpandedParameterPack()) { |
| 7478 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7479 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7480 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7481 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7482 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7483 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7484 | // Build var to save the step value. |
| 7485 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7486 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7487 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7488 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7489 | ExprResult CalcStep = |
| 7490 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7491 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7492 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7493 | // Warn about zero linear step (it would be probably better specified as |
| 7494 | // making corresponding variables 'const'). |
| 7495 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7496 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7497 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7498 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7499 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7500 | if (!IsConstant && CalcStep.isUsable()) { |
| 7501 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7502 | // (This is not used if the number of iterations may be kfold-ed). |
| 7503 | CalcStepExpr = CalcStep.get(); |
| 7504 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7505 | } |
| 7506 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7507 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7508 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7509 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7513 | Expr *NumIterations, Sema &SemaRef, |
| 7514 | Scope *S) { |
| 7515 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7516 | SmallVector<Expr *, 8> Updates; |
| 7517 | SmallVector<Expr *, 8> Finals; |
| 7518 | Expr *Step = Clause.getStep(); |
| 7519 | Expr *CalcStep = Clause.getCalcStep(); |
| 7520 | // OpenMP [2.14.3.7, linear clause] |
| 7521 | // If linear-step is not specified it is assumed to be 1. |
| 7522 | if (Step == nullptr) |
| 7523 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7524 | else if (CalcStep) |
| 7525 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7526 | bool HasErrors = false; |
| 7527 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7528 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7529 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7530 | for (auto &RefExpr : Clause.varlists()) { |
| 7531 | Expr *InitExpr = *CurInit; |
| 7532 | |
| 7533 | // Build privatized reference to the current linear var. |
| 7534 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7535 | Expr *CapturedRef; |
| 7536 | if (LinKind == OMPC_LINEAR_uval) |
| 7537 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 7538 | else |
| 7539 | CapturedRef = |
| 7540 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 7541 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 7542 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7543 | |
| 7544 | // Build update: Var = InitExpr + IV * Step |
| 7545 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7546 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7547 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7548 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 7549 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7550 | |
| 7551 | // Build final: Var = InitExpr + NumIterations * Step |
| 7552 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7553 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7554 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7555 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 7556 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7557 | if (!Update.isUsable() || !Final.isUsable()) { |
| 7558 | Updates.push_back(nullptr); |
| 7559 | Finals.push_back(nullptr); |
| 7560 | HasErrors = true; |
| 7561 | } else { |
| 7562 | Updates.push_back(Update.get()); |
| 7563 | Finals.push_back(Final.get()); |
| 7564 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7565 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7566 | } |
| 7567 | Clause.setUpdates(Updates); |
| 7568 | Clause.setFinals(Finals); |
| 7569 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7570 | } |
| 7571 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7572 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 7573 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 7574 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 7575 | |
| 7576 | SmallVector<Expr *, 8> Vars; |
| 7577 | for (auto &RefExpr : VarList) { |
| 7578 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 7579 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7580 | // It will be analyzed later. |
| 7581 | Vars.push_back(RefExpr); |
| 7582 | continue; |
| 7583 | } |
| 7584 | |
| 7585 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7586 | // OpenMP [2.1, C/C++] |
| 7587 | // A list item is a variable name. |
| 7588 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7589 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7590 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7591 | continue; |
| 7592 | } |
| 7593 | |
| 7594 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7595 | |
| 7596 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7597 | // The type of list items appearing in the aligned clause must be |
| 7598 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7599 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7600 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7601 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7602 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 7603 | !Ty->isPointerType())) { |
| 7604 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 7605 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 7606 | bool IsDecl = |
| 7607 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7608 | Diag(VD->getLocation(), |
| 7609 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7610 | << VD; |
| 7611 | continue; |
| 7612 | } |
| 7613 | |
| 7614 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7615 | // A list-item cannot appear in more than one aligned clause. |
| 7616 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 7617 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 7618 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 7619 | << getOpenMPClauseName(OMPC_aligned); |
| 7620 | continue; |
| 7621 | } |
| 7622 | |
| 7623 | Vars.push_back(DE); |
| 7624 | } |
| 7625 | |
| 7626 | // OpenMP [2.8.1, simd construct, Description] |
| 7627 | // The parameter of the aligned clause, alignment, must be a constant |
| 7628 | // positive integer expression. |
| 7629 | // If no optional parameter is specified, implementation-defined default |
| 7630 | // alignments for SIMD instructions on the target platforms are assumed. |
| 7631 | if (Alignment != nullptr) { |
| 7632 | ExprResult AlignResult = |
| 7633 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 7634 | if (AlignResult.isInvalid()) |
| 7635 | return nullptr; |
| 7636 | Alignment = AlignResult.get(); |
| 7637 | } |
| 7638 | if (Vars.empty()) |
| 7639 | return nullptr; |
| 7640 | |
| 7641 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 7642 | EndLoc, Vars, Alignment); |
| 7643 | } |
| 7644 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7645 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 7646 | SourceLocation StartLoc, |
| 7647 | SourceLocation LParenLoc, |
| 7648 | SourceLocation EndLoc) { |
| 7649 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7650 | SmallVector<Expr *, 8> SrcExprs; |
| 7651 | SmallVector<Expr *, 8> DstExprs; |
| 7652 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7653 | for (auto &RefExpr : VarList) { |
| 7654 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 7655 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7656 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7657 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7658 | SrcExprs.push_back(nullptr); |
| 7659 | DstExprs.push_back(nullptr); |
| 7660 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7661 | continue; |
| 7662 | } |
| 7663 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7664 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7665 | // OpenMP [2.1, C/C++] |
| 7666 | // A list item is a variable name. |
| 7667 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7668 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7669 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7670 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7671 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7672 | continue; |
| 7673 | } |
| 7674 | |
| 7675 | Decl *D = DE->getDecl(); |
| 7676 | VarDecl *VD = cast<VarDecl>(D); |
| 7677 | |
| 7678 | QualType Type = VD->getType(); |
| 7679 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7680 | // It will be analyzed later. |
| 7681 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7682 | SrcExprs.push_back(nullptr); |
| 7683 | DstExprs.push_back(nullptr); |
| 7684 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7685 | continue; |
| 7686 | } |
| 7687 | |
| 7688 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 7689 | // A list item that appears in a copyin clause must be threadprivate. |
| 7690 | if (!DSAStack->isThreadPrivate(VD)) { |
| 7691 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7692 | << getOpenMPClauseName(OMPC_copyin) |
| 7693 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7694 | continue; |
| 7695 | } |
| 7696 | |
| 7697 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7698 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7699 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7700 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7701 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7702 | auto *SrcVD = |
| 7703 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 7704 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7705 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7706 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 7707 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7708 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 7709 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7710 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7711 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7712 | // For arrays generate assignment operation for single element and replace |
| 7713 | // it by the original array element in CodeGen. |
| 7714 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7715 | PseudoDstExpr, PseudoSrcExpr); |
| 7716 | if (AssignmentOp.isInvalid()) |
| 7717 | continue; |
| 7718 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7719 | /*DiscardedValue=*/true); |
| 7720 | if (AssignmentOp.isInvalid()) |
| 7721 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7722 | |
| 7723 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 7724 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7725 | SrcExprs.push_back(PseudoSrcExpr); |
| 7726 | DstExprs.push_back(PseudoDstExpr); |
| 7727 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7728 | } |
| 7729 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7730 | if (Vars.empty()) |
| 7731 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7732 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7733 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7734 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7735 | } |
| 7736 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7737 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7738 | SourceLocation StartLoc, |
| 7739 | SourceLocation LParenLoc, |
| 7740 | SourceLocation EndLoc) { |
| 7741 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7742 | SmallVector<Expr *, 8> SrcExprs; |
| 7743 | SmallVector<Expr *, 8> DstExprs; |
| 7744 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7745 | for (auto &RefExpr : VarList) { |
| 7746 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7747 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7748 | // It will be analyzed later. |
| 7749 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7750 | SrcExprs.push_back(nullptr); |
| 7751 | DstExprs.push_back(nullptr); |
| 7752 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7753 | continue; |
| 7754 | } |
| 7755 | |
| 7756 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7757 | // OpenMP [2.1, C/C++] |
| 7758 | // A list item is a variable name. |
| 7759 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7760 | // A list item that appears in a copyin clause must be threadprivate. |
| 7761 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7762 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7763 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7764 | continue; |
| 7765 | } |
| 7766 | |
| 7767 | Decl *D = DE->getDecl(); |
| 7768 | VarDecl *VD = cast<VarDecl>(D); |
| 7769 | |
| 7770 | QualType Type = VD->getType(); |
| 7771 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7772 | // It will be analyzed later. |
| 7773 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7774 | SrcExprs.push_back(nullptr); |
| 7775 | DstExprs.push_back(nullptr); |
| 7776 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7777 | continue; |
| 7778 | } |
| 7779 | |
| 7780 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 7781 | // A list item that appears in a copyprivate clause may not appear in a |
| 7782 | // private or firstprivate clause on the single construct. |
| 7783 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7784 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7785 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 7786 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7787 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7788 | << getOpenMPClauseName(DVar.CKind) |
| 7789 | << getOpenMPClauseName(OMPC_copyprivate); |
| 7790 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7791 | continue; |
| 7792 | } |
| 7793 | |
| 7794 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 7795 | // All list items that appear in a copyprivate clause must be either |
| 7796 | // threadprivate or private in the enclosing context. |
| 7797 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7798 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7799 | if (DVar.CKind == OMPC_shared) { |
| 7800 | Diag(ELoc, diag::err_omp_required_access) |
| 7801 | << getOpenMPClauseName(OMPC_copyprivate) |
| 7802 | << "threadprivate or private in the enclosing context"; |
| 7803 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7804 | continue; |
| 7805 | } |
| 7806 | } |
| 7807 | } |
| 7808 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7809 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7810 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7811 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7812 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 7813 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7814 | bool IsDecl = |
| 7815 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7816 | Diag(VD->getLocation(), |
| 7817 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7818 | << VD; |
| 7819 | continue; |
| 7820 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7821 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7822 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7823 | // A variable of class type (or array thereof) that appears in a |
| 7824 | // copyin clause requires an accessible, unambiguous copy assignment |
| 7825 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7826 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 7827 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7828 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7829 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 7830 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7831 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7832 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7833 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7834 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 7835 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7836 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7837 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7838 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7839 | PseudoDstExpr, PseudoSrcExpr); |
| 7840 | if (AssignmentOp.isInvalid()) |
| 7841 | continue; |
| 7842 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7843 | /*DiscardedValue=*/true); |
| 7844 | if (AssignmentOp.isInvalid()) |
| 7845 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7846 | |
| 7847 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 7848 | // implicitly private. |
| 7849 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7850 | SrcExprs.push_back(PseudoSrcExpr); |
| 7851 | DstExprs.push_back(PseudoDstExpr); |
| 7852 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7853 | } |
| 7854 | |
| 7855 | if (Vars.empty()) |
| 7856 | return nullptr; |
| 7857 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7858 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 7859 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7860 | } |
| 7861 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7862 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 7863 | SourceLocation StartLoc, |
| 7864 | SourceLocation LParenLoc, |
| 7865 | SourceLocation EndLoc) { |
| 7866 | if (VarList.empty()) |
| 7867 | return nullptr; |
| 7868 | |
| 7869 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 7870 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7871 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7872 | OMPClause * |
| 7873 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 7874 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 7875 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 7876 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7877 | if (DepKind == OMPC_DEPEND_unknown) { |
| 7878 | std::string Values; |
| 7879 | std::string Sep(", "); |
| 7880 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 7881 | Values += "'"; |
| 7882 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 7883 | Values += "'"; |
| 7884 | switch (i) { |
| 7885 | case OMPC_DEPEND_unknown - 2: |
| 7886 | Values += " or "; |
| 7887 | break; |
| 7888 | case OMPC_DEPEND_unknown - 1: |
| 7889 | break; |
| 7890 | default: |
| 7891 | Values += Sep; |
| 7892 | break; |
| 7893 | } |
| 7894 | } |
| 7895 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 7896 | << Values << getOpenMPClauseName(OMPC_depend); |
| 7897 | return nullptr; |
| 7898 | } |
| 7899 | SmallVector<Expr *, 8> Vars; |
| 7900 | for (auto &RefExpr : VarList) { |
| 7901 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7902 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7903 | // It will be analyzed later. |
| 7904 | Vars.push_back(RefExpr); |
| 7905 | continue; |
| 7906 | } |
| 7907 | |
| 7908 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7909 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 7910 | // A variable that is part of another variable (such as a field of a |
| 7911 | // structure) but is not an array element or an array section cannot appear |
| 7912 | // in a depend clause. |
| 7913 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7914 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7915 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7916 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7917 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 7918 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7919 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7920 | !ASE->getBase()->getType()->isArrayType())) { |
| 7921 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7922 | << RefExpr->getSourceRange(); |
| 7923 | continue; |
| 7924 | } |
| 7925 | |
| 7926 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 7927 | } |
| 7928 | |
| 7929 | if (Vars.empty()) |
| 7930 | return nullptr; |
| 7931 | |
| 7932 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 7933 | DepLoc, ColonLoc, Vars); |
| 7934 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7935 | |
| 7936 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 7937 | SourceLocation LParenLoc, |
| 7938 | SourceLocation EndLoc) { |
| 7939 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7940 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7941 | // OpenMP [2.9.1, Restrictions] |
| 7942 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7943 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 7944 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7945 | return nullptr; |
| 7946 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7947 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7948 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7949 | |
| 7950 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 7951 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 7952 | if (!RD || RD->isInvalidDecl()) |
| 7953 | return true; |
| 7954 | |
| 7955 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 7956 | if (RD->isDynamicClass()) { |
| 7957 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7958 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 7959 | return false; |
| 7960 | } |
| 7961 | auto *DC = RD; |
| 7962 | bool IsCorrect = true; |
| 7963 | for (auto *I : DC->decls()) { |
| 7964 | if (I) { |
| 7965 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 7966 | if (MD->isStatic()) { |
| 7967 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7968 | SemaRef.Diag(MD->getLocation(), |
| 7969 | diag::note_omp_static_member_in_target); |
| 7970 | IsCorrect = false; |
| 7971 | } |
| 7972 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 7973 | if (VD->isStaticDataMember()) { |
| 7974 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7975 | SemaRef.Diag(VD->getLocation(), |
| 7976 | diag::note_omp_static_member_in_target); |
| 7977 | IsCorrect = false; |
| 7978 | } |
| 7979 | } |
| 7980 | } |
| 7981 | } |
| 7982 | |
| 7983 | for (auto &I : RD->bases()) { |
| 7984 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 7985 | I.getType()->getAsCXXRecordDecl())) |
| 7986 | IsCorrect = false; |
| 7987 | } |
| 7988 | return IsCorrect; |
| 7989 | } |
| 7990 | |
| 7991 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 7992 | DSAStackTy *Stack, QualType QTy) { |
| 7993 | NamedDecl *ND; |
| 7994 | if (QTy->isIncompleteType(&ND)) { |
| 7995 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 7996 | return false; |
| 7997 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 7998 | if (!RD->isInvalidDecl() && |
| 7999 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8000 | return false; |
| 8001 | } |
| 8002 | return true; |
| 8003 | } |
| 8004 | |
| 8005 | OMPClause *Sema::ActOnOpenMPMapClause( |
| 8006 | OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, |
| 8007 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 8008 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 8009 | SmallVector<Expr *, 4> Vars; |
| 8010 | |
| 8011 | for (auto &RE : VarList) { |
| 8012 | assert(RE && "Null expr in omp map"); |
| 8013 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 8014 | // It will be analyzed later. |
| 8015 | Vars.push_back(RE); |
| 8016 | continue; |
| 8017 | } |
| 8018 | SourceLocation ELoc = RE->getExprLoc(); |
| 8019 | |
| 8020 | // OpenMP [2.14.5, Restrictions] |
| 8021 | // A variable that is part of another variable (such as field of a |
| 8022 | // structure) but is not an array element or an array section cannot appear |
| 8023 | // in a map clause. |
| 8024 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 8025 | |
| 8026 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 8027 | VE->isInstantiationDependent() || |
| 8028 | VE->containsUnexpandedParameterPack()) { |
| 8029 | // It will be analyzed later. |
| 8030 | Vars.push_back(RE); |
| 8031 | continue; |
| 8032 | } |
| 8033 | |
| 8034 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
| 8035 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8036 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8037 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8038 | |
| 8039 | if (!RE->IgnoreParenImpCasts()->isLValue() || |
| 8040 | (!OASE && !ASE && !DE) || |
| 8041 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8042 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8043 | !ASE->getBase()->getType()->isArrayType())) { |
| 8044 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 8045 | << RE->getSourceRange(); |
| 8046 | continue; |
| 8047 | } |
| 8048 | |
| 8049 | Decl *D = nullptr; |
| 8050 | if (DE) { |
| 8051 | D = DE->getDecl(); |
| 8052 | } else if (ASE) { |
| 8053 | auto *B = ASE->getBase()->IgnoreParenCasts(); |
| 8054 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8055 | } else if (OASE) { |
| 8056 | auto *B = OASE->getBase(); |
| 8057 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8058 | } |
| 8059 | assert(D && "Null decl on map clause."); |
| 8060 | auto *VD = cast<VarDecl>(D); |
| 8061 | |
| 8062 | // OpenMP [2.14.5, Restrictions, p.8] |
| 8063 | // threadprivate variables cannot appear in a map clause. |
| 8064 | if (DSAStack->isThreadPrivate(VD)) { |
| 8065 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 8066 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 8067 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8068 | continue; |
| 8069 | } |
| 8070 | |
| 8071 | // OpenMP [2.14.5, Restrictions, p.2] |
| 8072 | // At most one list item can be an array item derived from a given variable |
| 8073 | // in map clauses of the same construct. |
| 8074 | // OpenMP [2.14.5, Restrictions, p.3] |
| 8075 | // List items of map clauses in the same construct must not share original |
| 8076 | // storage. |
| 8077 | // OpenMP [2.14.5, Restrictions, C/C++, p.2] |
| 8078 | // A variable for which the type is pointer, reference to array, or |
| 8079 | // reference to pointer and an array section derived from that variable |
| 8080 | // must not appear as list items of map clauses of the same construct. |
| 8081 | DSAStackTy::MapInfo MI = DSAStack->IsMappedInCurrentRegion(VD); |
| 8082 | if (MI.RefExpr) { |
| 8083 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8084 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8085 | << MI.RefExpr->getSourceRange(); |
| 8086 | continue; |
| 8087 | } |
| 8088 | |
| 8089 | // OpenMP [2.14.5, Restrictions, C/C++, p.3,4] |
| 8090 | // A variable for which the type is pointer, reference to array, or |
| 8091 | // reference to pointer must not appear as a list item if the enclosing |
| 8092 | // device data environment already contains an array section derived from |
| 8093 | // that variable. |
| 8094 | // An array section derived from a variable for which the type is pointer, |
| 8095 | // reference to array, or reference to pointer must not appear as a list |
| 8096 | // item if the enclosing device data environment already contains that |
| 8097 | // variable. |
| 8098 | QualType Type = VD->getType(); |
| 8099 | MI = DSAStack->getMapInfoForVar(VD); |
| 8100 | if (MI.RefExpr && (isa<DeclRefExpr>(MI.RefExpr->IgnoreParenLValueCasts()) != |
| 8101 | isa<DeclRefExpr>(VE)) && |
| 8102 | (Type->isPointerType() || Type->isReferenceType())) { |
| 8103 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8104 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8105 | << MI.RefExpr->getSourceRange(); |
| 8106 | continue; |
| 8107 | } |
| 8108 | |
| 8109 | // OpenMP [2.14.5, Restrictions, C/C++, p.7] |
| 8110 | // A list item must have a mappable type. |
| 8111 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 8112 | DSAStack, Type)) |
| 8113 | continue; |
| 8114 | |
| 8115 | Vars.push_back(RE); |
| 8116 | MI.RefExpr = RE; |
| 8117 | DSAStack->addMapInfoForVar(VD, MI); |
| 8118 | } |
| 8119 | if (Vars.empty()) |
| 8120 | return nullptr; |
| 8121 | |
| 8122 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8123 | MapTypeModifier, MapType, MapLoc); |
| 8124 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8125 | |
| 8126 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 8127 | SourceLocation StartLoc, |
| 8128 | SourceLocation LParenLoc, |
| 8129 | SourceLocation EndLoc) { |
| 8130 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8131 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8132 | // OpenMP [teams Constrcut, Restrictions] |
| 8133 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8134 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 8135 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8136 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8137 | |
| 8138 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8139 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8140 | |
| 8141 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 8142 | SourceLocation StartLoc, |
| 8143 | SourceLocation LParenLoc, |
| 8144 | SourceLocation EndLoc) { |
| 8145 | Expr *ValExpr = ThreadLimit; |
| 8146 | |
| 8147 | // OpenMP [teams Constrcut, Restrictions] |
| 8148 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8149 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 8150 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8151 | return nullptr; |
| 8152 | |
| 8153 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 8154 | EndLoc); |
| 8155 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8156 | |
| 8157 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 8158 | SourceLocation StartLoc, |
| 8159 | SourceLocation LParenLoc, |
| 8160 | SourceLocation EndLoc) { |
| 8161 | Expr *ValExpr = Priority; |
| 8162 | |
| 8163 | // OpenMP [2.9.1, task Constrcut] |
| 8164 | // The priority-value is a non-negative numerical scalar expression. |
| 8165 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 8166 | /*StrictlyPositive=*/false)) |
| 8167 | return nullptr; |
| 8168 | |
| 8169 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8170 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8171 | |
| 8172 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 8173 | SourceLocation StartLoc, |
| 8174 | SourceLocation LParenLoc, |
| 8175 | SourceLocation EndLoc) { |
| 8176 | Expr *ValExpr = Grainsize; |
| 8177 | |
| 8178 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8179 | // The parameter of the grainsize clause must be a positive integer |
| 8180 | // expression. |
| 8181 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 8182 | /*StrictlyPositive=*/true)) |
| 8183 | return nullptr; |
| 8184 | |
| 8185 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8186 | } |