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 |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 568 | // in a Construct, C/C++, predetermined, p.4] |
| 569 | // Static data members are shared. |
| 570 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 571 | // in a Construct, C/C++, predetermined, p.7] |
| 572 | // Variables with static storage duration that are declared in a scope |
| 573 | // inside the construct are shared. |
| 574 | if (D->isStaticDataMember()) { |
| 575 | DSAVarData DVarTemp = |
| 576 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 577 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 578 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 579 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 580 | DVar.CKind = OMPC_shared; |
| 581 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 585 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 586 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 587 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 588 | // in a Construct, C/C++, predetermined, p.6] |
| 589 | // Variables with const qualified type having no mutable member are |
| 590 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 591 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 592 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 593 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 594 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 595 | // Variables with const-qualified type having no mutable member may be |
| 596 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 597 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 598 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 599 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 600 | return DVar; |
| 601 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 602 | DVar.CKind = OMPC_shared; |
| 603 | return DVar; |
| 604 | } |
| 605 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 606 | // Explicitly specified attributes and local variables with predetermined |
| 607 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 608 | auto StartI = std::next(Stack.rbegin()); |
| 609 | auto EndI = std::prev(Stack.rend()); |
| 610 | if (FromParent && StartI != EndI) { |
| 611 | StartI = std::next(StartI); |
| 612 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 613 | auto I = std::prev(StartI); |
| 614 | if (I->SharingMap.count(D)) { |
| 615 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 616 | DVar.CKind = I->SharingMap[D].Attributes; |
| 617 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | return DVar; |
| 621 | } |
| 622 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 623 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 624 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 625 | auto StartI = Stack.rbegin(); |
| 626 | auto EndI = std::prev(Stack.rend()); |
| 627 | if (FromParent && StartI != EndI) { |
| 628 | StartI = std::next(StartI); |
| 629 | } |
| 630 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 633 | template <class ClausesPredicate, class DirectivesPredicate> |
| 634 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 635 | DirectivesPredicate DPred, |
| 636 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 637 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 638 | auto StartI = std::next(Stack.rbegin()); |
| 639 | auto EndI = std::prev(Stack.rend()); |
| 640 | if (FromParent && StartI != EndI) { |
| 641 | StartI = std::next(StartI); |
| 642 | } |
| 643 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 644 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 645 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 646 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 647 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 648 | return DVar; |
| 649 | } |
| 650 | return DSAVarData(); |
| 651 | } |
| 652 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 653 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 654 | DSAStackTy::DSAVarData |
| 655 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 656 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 657 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 658 | auto StartI = std::next(Stack.rbegin()); |
| 659 | auto EndI = std::prev(Stack.rend()); |
| 660 | if (FromParent && StartI != EndI) { |
| 661 | StartI = std::next(StartI); |
| 662 | } |
| 663 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 664 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 665 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 666 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 667 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 668 | return DVar; |
| 669 | return DSAVarData(); |
| 670 | } |
| 671 | return DSAVarData(); |
| 672 | } |
| 673 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 674 | bool DSAStackTy::hasExplicitDSA( |
| 675 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 676 | unsigned Level) { |
| 677 | if (CPred(ClauseKindMode)) |
| 678 | return true; |
| 679 | if (isClauseParsingMode()) |
| 680 | ++Level; |
| 681 | D = D->getCanonicalDecl(); |
| 682 | auto StartI = Stack.rbegin(); |
| 683 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 684 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 685 | return false; |
| 686 | std::advance(StartI, Level); |
| 687 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 688 | CPred(StartI->SharingMap[D].Attributes); |
| 689 | } |
| 690 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 691 | bool DSAStackTy::hasExplicitDirective( |
| 692 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 693 | unsigned Level) { |
| 694 | if (isClauseParsingMode()) |
| 695 | ++Level; |
| 696 | auto StartI = Stack.rbegin(); |
| 697 | auto EndI = std::prev(Stack.rend()); |
| 698 | if (std::distance(StartI, EndI) <= (int)Level) |
| 699 | return false; |
| 700 | std::advance(StartI, Level); |
| 701 | return DPred(StartI->Directive); |
| 702 | } |
| 703 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 704 | template <class NamedDirectivesPredicate> |
| 705 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 706 | auto StartI = std::next(Stack.rbegin()); |
| 707 | auto EndI = std::prev(Stack.rend()); |
| 708 | if (FromParent && StartI != EndI) { |
| 709 | StartI = std::next(StartI); |
| 710 | } |
| 711 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 712 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 713 | return true; |
| 714 | } |
| 715 | return false; |
| 716 | } |
| 717 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 718 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 719 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 720 | if (I->CurScope == S) |
| 721 | return I->Directive; |
| 722 | return OMPD_unknown; |
| 723 | } |
| 724 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 725 | void Sema::InitDataSharingAttributesStack() { |
| 726 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 727 | } |
| 728 | |
| 729 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 730 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 731 | bool Sema::IsOpenMPCapturedByRef(VarDecl *VD, |
| 732 | const CapturedRegionScopeInfo *RSI) { |
| 733 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 734 | |
| 735 | auto &Ctx = getASTContext(); |
| 736 | bool IsByRef = true; |
| 737 | |
| 738 | // Find the directive that is associated with the provided scope. |
| 739 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
| 740 | auto Ty = VD->getType(); |
| 741 | |
| 742 | if (isOpenMPTargetDirective(DKind)) { |
| 743 | // This table summarizes how a given variable should be passed to the device |
| 744 | // given its type and the clauses where it appears. This table is based on |
| 745 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 746 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 747 | // |
| 748 | // ========================================================================= |
| 749 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 750 | // | |(tofrom:scalar)| | pvt | | | | |
| 751 | // ========================================================================= |
| 752 | // | scl | | | | - | | bycopy| |
| 753 | // | scl | | - | x | - | - | bycopy| |
| 754 | // | scl | | x | - | - | - | null | |
| 755 | // | scl | x | | | - | | byref | |
| 756 | // | scl | x | - | x | - | - | bycopy| |
| 757 | // | scl | x | x | - | - | - | null | |
| 758 | // | scl | | - | - | - | x | byref | |
| 759 | // | scl | x | - | - | - | x | byref | |
| 760 | // |
| 761 | // | agg | n.a. | | | - | | byref | |
| 762 | // | agg | n.a. | - | x | - | - | byref | |
| 763 | // | agg | n.a. | x | - | - | - | null | |
| 764 | // | agg | n.a. | - | - | - | x | byref | |
| 765 | // | agg | n.a. | - | - | - | x[] | byref | |
| 766 | // |
| 767 | // | ptr | n.a. | | | - | | bycopy| |
| 768 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 769 | // | ptr | n.a. | x | - | - | - | null | |
| 770 | // | ptr | n.a. | - | - | - | x | byref | |
| 771 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 772 | // | ptr | n.a. | - | - | x | | bycopy| |
| 773 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 774 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 775 | // ========================================================================= |
| 776 | // Legend: |
| 777 | // scl - scalar |
| 778 | // ptr - pointer |
| 779 | // agg - aggregate |
| 780 | // x - applies |
| 781 | // - - invalid in this combination |
| 782 | // [] - mapped with an array section |
| 783 | // byref - should be mapped by reference |
| 784 | // byval - should be mapped by value |
| 785 | // null - initialize a local variable to null on the device |
| 786 | // |
| 787 | // Observations: |
| 788 | // - All scalar declarations that show up in a map clause have to be passed |
| 789 | // by reference, because they may have been mapped in the enclosing data |
| 790 | // environment. |
| 791 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 792 | // passed by reference, regardless the result in the table above. |
| 793 | // - For pointers mapped by value that have either an implicit map or an |
| 794 | // array section, the runtime library may pass the NULL value to the |
| 795 | // device instead of the value passed to it by the compiler. |
| 796 | |
| 797 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 798 | // values requires having the map, private, and firstprivate clauses SEMA |
| 799 | // and parsing in place, which we don't yet. |
| 800 | |
| 801 | if (Ty->isReferenceType()) |
| 802 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 803 | IsByRef = !Ty->isScalarType(); |
| 804 | } |
| 805 | |
| 806 | // When passing data by value, we need to make sure it fits the uintptr size |
| 807 | // and alignment, because the runtime library only deals with uintptr types. |
| 808 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 809 | // instead. |
| 810 | if (!IsByRef && |
| 811 | (Ctx.getTypeSizeInChars(Ty) > |
| 812 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
| 813 | Ctx.getDeclAlign(VD) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
| 814 | IsByRef = true; |
| 815 | |
| 816 | return IsByRef; |
| 817 | } |
| 818 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 819 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 820 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 821 | VD = VD->getCanonicalDecl(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 822 | |
| 823 | // If we are attempting to capture a global variable in a directive with |
| 824 | // 'target' we return true so that this global is also mapped to the device. |
| 825 | // |
| 826 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 827 | // then it should not be captured. Therefore, an extra check has to be |
| 828 | // inserted here once support for 'declare target' is added. |
| 829 | // |
| 830 | if (!VD->hasLocalStorage()) { |
| 831 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 832 | !DSAStack->isClauseParsingMode()) { |
| 833 | return true; |
| 834 | } |
| 835 | if (DSAStack->getCurScope() && |
| 836 | DSAStack->hasDirective( |
| 837 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 838 | SourceLocation Loc) -> bool { |
| 839 | return isOpenMPTargetDirective(K); |
| 840 | }, |
| 841 | false)) { |
| 842 | return true; |
| 843 | } |
| 844 | } |
| 845 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 846 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 847 | (!DSAStack->isClauseParsingMode() || |
| 848 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 849 | if (DSAStack->isLoopControlVariable(VD) || |
| 850 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 851 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 852 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 853 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 854 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 855 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 856 | return true; |
| 857 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 858 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 859 | return DVarPrivate.CKind != OMPC_unknown; |
| 860 | } |
| 861 | return false; |
| 862 | } |
| 863 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 864 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 865 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 866 | return DSAStack->hasExplicitDSA( |
| 867 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 868 | } |
| 869 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 870 | bool Sema::isOpenMPTargetCapturedVar(VarDecl *VD, unsigned Level) { |
| 871 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 872 | // Return true if the current level is no longer enclosed in a target region. |
| 873 | |
| 874 | return !VD->hasLocalStorage() && |
| 875 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 876 | } |
| 877 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 878 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 879 | |
| 880 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 881 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 882 | Scope *CurScope, SourceLocation Loc) { |
| 883 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 884 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 885 | } |
| 886 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 887 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 888 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 891 | void Sema::EndOpenMPClause() { |
| 892 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 893 | } |
| 894 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 895 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 896 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 897 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 898 | // clause requires an accessible, unambiguous default constructor for the |
| 899 | // class type, unless the list item is also specified in a firstprivate |
| 900 | // clause. |
| 901 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 902 | for (auto *C : D->clauses()) { |
| 903 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 904 | SmallVector<Expr *, 8> PrivateCopies; |
| 905 | for (auto *DE : Clause->varlists()) { |
| 906 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 907 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 908 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 909 | } |
| 910 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 911 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 912 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 913 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 914 | // Generate helper private variable and initialize it with the |
| 915 | // default value. The address of the original variable is replaced |
| 916 | // by the address of the new private variable in CodeGen. This new |
| 917 | // variable is not added to IdResolver, so the code in the OpenMP |
| 918 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 919 | auto *VDPrivate = buildVarDecl( |
| 920 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 921 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 922 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 923 | if (VDPrivate->isInvalidDecl()) |
| 924 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 925 | PrivateCopies.push_back(buildDeclRefExpr( |
| 926 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 927 | } else { |
| 928 | // The variable is also a firstprivate, so initialization sequence |
| 929 | // for private copy is generated already. |
| 930 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 931 | } |
| 932 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 933 | // Set initializers to private copies if no errors were found. |
| 934 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 935 | Clause->setPrivateCopies(PrivateCopies); |
| 936 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 941 | DSAStack->pop(); |
| 942 | DiscardCleanupsInEvaluationContext(); |
| 943 | PopExpressionEvaluationContext(); |
| 944 | } |
| 945 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 946 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 947 | Expr *NumIterations, Sema &SemaRef, |
| 948 | Scope *S); |
| 949 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 950 | namespace { |
| 951 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 952 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 953 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 954 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 955 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 956 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 957 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 958 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 959 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 960 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 961 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 962 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 963 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 964 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 965 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 966 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 967 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 968 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 969 | |
| 970 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 971 | CXXScopeSpec &ScopeSpec, |
| 972 | const DeclarationNameInfo &Id) { |
| 973 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 974 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 975 | |
| 976 | if (Lookup.isAmbiguous()) |
| 977 | return ExprError(); |
| 978 | |
| 979 | VarDecl *VD; |
| 980 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 981 | if (TypoCorrection Corrected = CorrectTypo( |
| 982 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 983 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 984 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 985 | PDiag(Lookup.empty() |
| 986 | ? diag::err_undeclared_var_use_suggest |
| 987 | : diag::err_omp_expected_var_arg_suggest) |
| 988 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 989 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 990 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 991 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 992 | : diag::err_omp_expected_var_arg) |
| 993 | << Id.getName(); |
| 994 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 995 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 996 | } else { |
| 997 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 998 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 999 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1000 | return ExprError(); |
| 1001 | } |
| 1002 | } |
| 1003 | Lookup.suppressDiagnostics(); |
| 1004 | |
| 1005 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1006 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1007 | if (!VD->hasGlobalStorage()) { |
| 1008 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1009 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1010 | bool IsDecl = |
| 1011 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1012 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1013 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1014 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1015 | return ExprError(); |
| 1016 | } |
| 1017 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1018 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1019 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1020 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1021 | // A threadprivate directive for file-scope variables must appear outside |
| 1022 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1023 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1024 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1025 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1026 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1027 | bool IsDecl = |
| 1028 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1029 | Diag(VD->getLocation(), |
| 1030 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1031 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1032 | return ExprError(); |
| 1033 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1034 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1035 | // A threadprivate directive for static class member variables must appear |
| 1036 | // in the class definition, in the same scope in which the member |
| 1037 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1038 | if (CanonicalVD->isStaticDataMember() && |
| 1039 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1040 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1041 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1042 | bool IsDecl = |
| 1043 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1044 | Diag(VD->getLocation(), |
| 1045 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1046 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1047 | return ExprError(); |
| 1048 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1049 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1050 | // A threadprivate directive for namespace-scope variables must appear |
| 1051 | // outside any definition or declaration other than the namespace |
| 1052 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1053 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1054 | (!getCurLexicalContext()->isFileContext() || |
| 1055 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 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.6] |
| 1066 | // A threadprivate directive for static block-scope variables must appear |
| 1067 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1068 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1069 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1070 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1071 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1072 | bool IsDecl = |
| 1073 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1074 | Diag(VD->getLocation(), |
| 1075 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1076 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1077 | return ExprError(); |
| 1078 | } |
| 1079 | |
| 1080 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1081 | // A threadprivate directive must lexically precede all references to any |
| 1082 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1083 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1084 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1085 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1086 | return ExprError(); |
| 1087 | } |
| 1088 | |
| 1089 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1090 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1091 | return DE; |
| 1092 | } |
| 1093 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1094 | Sema::DeclGroupPtrTy |
| 1095 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1096 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1097 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1098 | CurContext->addDecl(D); |
| 1099 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1100 | } |
| 1101 | return DeclGroupPtrTy(); |
| 1102 | } |
| 1103 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1104 | namespace { |
| 1105 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1106 | Sema &SemaRef; |
| 1107 | |
| 1108 | public: |
| 1109 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1110 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1111 | if (VD->hasLocalStorage()) { |
| 1112 | SemaRef.Diag(E->getLocStart(), |
| 1113 | diag::err_omp_local_var_in_threadprivate_init) |
| 1114 | << E->getSourceRange(); |
| 1115 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1116 | << VD << VD->getSourceRange(); |
| 1117 | return true; |
| 1118 | } |
| 1119 | } |
| 1120 | return false; |
| 1121 | } |
| 1122 | bool VisitStmt(const Stmt *S) { |
| 1123 | for (auto Child : S->children()) { |
| 1124 | if (Child && Visit(Child)) |
| 1125 | return true; |
| 1126 | } |
| 1127 | return false; |
| 1128 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1129 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1130 | }; |
| 1131 | } // namespace |
| 1132 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1133 | OMPThreadPrivateDecl * |
| 1134 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1135 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1136 | for (auto &RefExpr : VarList) { |
| 1137 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1138 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1139 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1140 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1141 | QualType QType = VD->getType(); |
| 1142 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1143 | // It will be analyzed later. |
| 1144 | Vars.push_back(DE); |
| 1145 | continue; |
| 1146 | } |
| 1147 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1148 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1149 | // A threadprivate variable must not have an incomplete type. |
| 1150 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1151 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1152 | continue; |
| 1153 | } |
| 1154 | |
| 1155 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1156 | // A threadprivate variable must not have a reference type. |
| 1157 | if (VD->getType()->isReferenceType()) { |
| 1158 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1159 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1160 | bool IsDecl = |
| 1161 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1162 | Diag(VD->getLocation(), |
| 1163 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1164 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1165 | continue; |
| 1166 | } |
| 1167 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1168 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1169 | // the corresponding diagnostic. |
| 1170 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1171 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1172 | getLangOpts().OpenMPUseTLS && |
| 1173 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1174 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1175 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1176 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1177 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1178 | bool IsDecl = |
| 1179 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1180 | Diag(VD->getLocation(), |
| 1181 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1182 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1183 | continue; |
| 1184 | } |
| 1185 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1186 | // Check if initial value of threadprivate variable reference variable with |
| 1187 | // local storage (it is not supported by runtime). |
| 1188 | if (auto Init = VD->getAnyInitializer()) { |
| 1189 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1190 | if (Checker.Visit(Init)) |
| 1191 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1192 | } |
| 1193 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1194 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1195 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1196 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1197 | Context, SourceRange(Loc, Loc))); |
| 1198 | if (auto *ML = Context.getASTMutationListener()) |
| 1199 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1200 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1201 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1202 | if (!Vars.empty()) { |
| 1203 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1204 | Vars); |
| 1205 | D->setAccess(AS_public); |
| 1206 | } |
| 1207 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1208 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1209 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1210 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1211 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1212 | bool IsLoopIterVar = false) { |
| 1213 | if (DVar.RefExpr) { |
| 1214 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1215 | << getOpenMPClauseName(DVar.CKind); |
| 1216 | return; |
| 1217 | } |
| 1218 | enum { |
| 1219 | PDSA_StaticMemberShared, |
| 1220 | PDSA_StaticLocalVarShared, |
| 1221 | PDSA_LoopIterVarPrivate, |
| 1222 | PDSA_LoopIterVarLinear, |
| 1223 | PDSA_LoopIterVarLastprivate, |
| 1224 | PDSA_ConstVarShared, |
| 1225 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1226 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1227 | PDSA_LocalVarPrivate, |
| 1228 | PDSA_Implicit |
| 1229 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1230 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1231 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1232 | if (IsLoopIterVar) { |
| 1233 | if (DVar.CKind == OMPC_private) |
| 1234 | Reason = PDSA_LoopIterVarPrivate; |
| 1235 | else if (DVar.CKind == OMPC_lastprivate) |
| 1236 | Reason = PDSA_LoopIterVarLastprivate; |
| 1237 | else |
| 1238 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1239 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1240 | Reason = PDSA_TaskVarFirstprivate; |
| 1241 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1242 | } else if (VD->isStaticLocal()) |
| 1243 | Reason = PDSA_StaticLocalVarShared; |
| 1244 | else if (VD->isStaticDataMember()) |
| 1245 | Reason = PDSA_StaticMemberShared; |
| 1246 | else if (VD->isFileVarDecl()) |
| 1247 | Reason = PDSA_GlobalVarShared; |
| 1248 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1249 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1250 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1251 | ReportHint = true; |
| 1252 | Reason = PDSA_LocalVarPrivate; |
| 1253 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1254 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1255 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1256 | << Reason << ReportHint |
| 1257 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1258 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1259 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1260 | << getOpenMPClauseName(DVar.CKind); |
| 1261 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1264 | namespace { |
| 1265 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1266 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1267 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1268 | bool ErrorFound; |
| 1269 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1270 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1271 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1272 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1273 | public: |
| 1274 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1275 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1276 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1277 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1278 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1279 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1280 | auto DVar = Stack->getTopDSA(VD, false); |
| 1281 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1282 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1283 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1284 | auto ELoc = E->getExprLoc(); |
| 1285 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1286 | // The default(none) clause requires that each variable that is referenced |
| 1287 | // in the construct, and does not have a predetermined data-sharing |
| 1288 | // attribute, must have its data-sharing attribute explicitly determined |
| 1289 | // by being listed in a data-sharing attribute clause. |
| 1290 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1291 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1292 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1293 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1298 | // A list item that appears in a reduction clause of the innermost |
| 1299 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1300 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1301 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1302 | [](OpenMPDirectiveKind K) -> bool { |
| 1303 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1304 | isOpenMPWorksharingDirective(K) || |
| 1305 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1306 | }, |
| 1307 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1308 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1309 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1310 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1311 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1312 | return; |
| 1313 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1314 | |
| 1315 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1316 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1317 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1318 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1319 | } |
| 1320 | } |
| 1321 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1322 | for (auto *C : S->clauses()) { |
| 1323 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1324 | // for task directives. |
| 1325 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1326 | for (auto *CC : C->children()) { |
| 1327 | if (CC) |
| 1328 | Visit(CC); |
| 1329 | } |
| 1330 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1331 | } |
| 1332 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1333 | for (auto *C : S->children()) { |
| 1334 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1335 | Visit(C); |
| 1336 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1337 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1338 | |
| 1339 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1340 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1341 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1342 | return VarsWithInheritedDSA; |
| 1343 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1344 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1345 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1346 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1347 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1348 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1349 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1350 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1351 | switch (DKind) { |
| 1352 | case OMPD_parallel: { |
| 1353 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1354 | QualType KmpInt32PtrTy = |
| 1355 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1356 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1357 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1358 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1359 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1360 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1361 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1362 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1363 | break; |
| 1364 | } |
| 1365 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1366 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1367 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1368 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1369 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1370 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1371 | break; |
| 1372 | } |
| 1373 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1374 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 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 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1381 | case OMPD_for_simd: { |
| 1382 | Sema::CapturedParamNameType Params[] = { |
| 1383 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1384 | }; |
| 1385 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1386 | Params); |
| 1387 | break; |
| 1388 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1389 | case OMPD_sections: { |
| 1390 | Sema::CapturedParamNameType Params[] = { |
| 1391 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1392 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1393 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1394 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1395 | break; |
| 1396 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1397 | case OMPD_section: { |
| 1398 | Sema::CapturedParamNameType Params[] = { |
| 1399 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1400 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1401 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1402 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1403 | break; |
| 1404 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1405 | case OMPD_single: { |
| 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 | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1411 | break; |
| 1412 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1413 | case OMPD_master: { |
| 1414 | Sema::CapturedParamNameType Params[] = { |
| 1415 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1416 | }; |
| 1417 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1418 | Params); |
| 1419 | break; |
| 1420 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1421 | case OMPD_critical: { |
| 1422 | Sema::CapturedParamNameType Params[] = { |
| 1423 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1424 | }; |
| 1425 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1426 | Params); |
| 1427 | break; |
| 1428 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1429 | case OMPD_parallel_for: { |
| 1430 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1431 | QualType KmpInt32PtrTy = |
| 1432 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1433 | Sema::CapturedParamNameType Params[] = { |
| 1434 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1435 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1436 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1437 | }; |
| 1438 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1439 | Params); |
| 1440 | break; |
| 1441 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1442 | case OMPD_parallel_for_simd: { |
| 1443 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1444 | QualType KmpInt32PtrTy = |
| 1445 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1446 | Sema::CapturedParamNameType Params[] = { |
| 1447 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1448 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1449 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1450 | }; |
| 1451 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1452 | Params); |
| 1453 | break; |
| 1454 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1455 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1456 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1457 | QualType KmpInt32PtrTy = |
| 1458 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1459 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1460 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1461 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1462 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1463 | }; |
| 1464 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1465 | Params); |
| 1466 | break; |
| 1467 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1468 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1469 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1470 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1471 | FunctionProtoType::ExtProtoInfo EPI; |
| 1472 | EPI.Variadic = true; |
| 1473 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1474 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1475 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1476 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1477 | std::make_pair(".privates.", |
| 1478 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1479 | std::make_pair( |
| 1480 | ".copy_fn.", |
| 1481 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1482 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1483 | }; |
| 1484 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1485 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1486 | // Mark this captured region as inlined, because we don't use outlined |
| 1487 | // function directly. |
| 1488 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1489 | AlwaysInlineAttr::CreateImplicit( |
| 1490 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1491 | break; |
| 1492 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1493 | case OMPD_ordered: { |
| 1494 | Sema::CapturedParamNameType Params[] = { |
| 1495 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1496 | }; |
| 1497 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1498 | Params); |
| 1499 | break; |
| 1500 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1501 | case OMPD_atomic: { |
| 1502 | Sema::CapturedParamNameType Params[] = { |
| 1503 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1504 | }; |
| 1505 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1506 | Params); |
| 1507 | break; |
| 1508 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1509 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1510 | case OMPD_target: { |
| 1511 | Sema::CapturedParamNameType Params[] = { |
| 1512 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1513 | }; |
| 1514 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1515 | Params); |
| 1516 | break; |
| 1517 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1518 | case OMPD_teams: { |
| 1519 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1520 | QualType KmpInt32PtrTy = |
| 1521 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1522 | Sema::CapturedParamNameType Params[] = { |
| 1523 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1524 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1525 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1526 | }; |
| 1527 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1528 | Params); |
| 1529 | break; |
| 1530 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1531 | case OMPD_taskgroup: { |
| 1532 | Sema::CapturedParamNameType Params[] = { |
| 1533 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1534 | }; |
| 1535 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1536 | Params); |
| 1537 | break; |
| 1538 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1539 | case OMPD_taskloop: { |
| 1540 | Sema::CapturedParamNameType Params[] = { |
| 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 | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1547 | case OMPD_taskloop_simd: { |
| 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 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1555 | case OMPD_distribute: { |
| 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 | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1563 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1564 | case OMPD_taskyield: |
| 1565 | case OMPD_barrier: |
| 1566 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1567 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1568 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1569 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1570 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1571 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1572 | llvm_unreachable("Unknown OpenMP directive"); |
| 1573 | } |
| 1574 | } |
| 1575 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1576 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1577 | ArrayRef<OMPClause *> Clauses) { |
| 1578 | if (!S.isUsable()) { |
| 1579 | ActOnCapturedRegionError(); |
| 1580 | return StmtError(); |
| 1581 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1582 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1583 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1584 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1585 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1586 | (getLangOpts().OpenMPUseTLS && |
| 1587 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1588 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1589 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1590 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1591 | for (auto *VarRef : Clause->children()) { |
| 1592 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1593 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1594 | } |
| 1595 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1596 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1597 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1598 | Clause->getClauseKind() == OMPC_schedule) { |
| 1599 | // Mark all variables in private list clauses as used in inner region. |
| 1600 | // Required for proper codegen of combined directives. |
| 1601 | // TODO: add processing for other clauses. |
| 1602 | if (auto *E = cast_or_null<Expr>( |
| 1603 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1604 | MarkDeclarationsReferencedInExpr(E); |
| 1605 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1606 | } |
| 1607 | } |
| 1608 | return ActOnCapturedRegionEnd(S.get()); |
| 1609 | } |
| 1610 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1611 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1612 | OpenMPDirectiveKind CurrentRegion, |
| 1613 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1614 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1615 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1616 | // Allowed nesting of constructs |
| 1617 | // +------------------+-----------------+------------------------------------+ |
| 1618 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1619 | // +------------------+-----------------+------------------------------------+ |
| 1620 | // | parallel | parallel | * | |
| 1621 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1622 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1623 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1624 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1625 | // | parallel | simd | * | |
| 1626 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1627 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1628 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1629 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1630 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1631 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1632 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1633 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1634 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1635 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1636 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1637 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1638 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1639 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1640 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1641 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1642 | // | parallel | cancellation | | |
| 1643 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1644 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1645 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1646 | // | parallel | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1647 | // | parallel | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1648 | // +------------------+-----------------+------------------------------------+ |
| 1649 | // | for | parallel | * | |
| 1650 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1651 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1652 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1653 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1654 | // | for | simd | * | |
| 1655 | // | for | sections | + | |
| 1656 | // | for | section | + | |
| 1657 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1658 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1659 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1660 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1661 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1662 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1663 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1664 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1665 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1666 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1667 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1668 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1669 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1670 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1671 | // | for | cancellation | | |
| 1672 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1673 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1674 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1675 | // | for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1676 | // | for | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1677 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1678 | // | master | parallel | * | |
| 1679 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1680 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1681 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1682 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1683 | // | master | simd | * | |
| 1684 | // | master | sections | + | |
| 1685 | // | master | section | + | |
| 1686 | // | master | single | + | |
| 1687 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1688 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1689 | // | master |parallel sections| * | |
| 1690 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1691 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1692 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1693 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1694 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1695 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1696 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1697 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1698 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1699 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1700 | // | master | cancellation | | |
| 1701 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1702 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1703 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1704 | // | master | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1705 | // | master | distribute | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1706 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1707 | // | critical | parallel | * | |
| 1708 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1709 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1710 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1711 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1712 | // | critical | simd | * | |
| 1713 | // | critical | sections | + | |
| 1714 | // | critical | section | + | |
| 1715 | // | critical | single | + | |
| 1716 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1717 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1718 | // | critical |parallel sections| * | |
| 1719 | // | critical | task | * | |
| 1720 | // | critical | taskyield | * | |
| 1721 | // | critical | barrier | + | |
| 1722 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1723 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1724 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1725 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1726 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1727 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1728 | // | critical | cancellation | | |
| 1729 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1730 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1731 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1732 | // | critical | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1733 | // | critical | distribute | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1734 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1735 | // | simd | parallel | | |
| 1736 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1737 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1738 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1739 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1740 | // | simd | simd | | |
| 1741 | // | simd | sections | | |
| 1742 | // | simd | section | | |
| 1743 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1744 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1745 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1746 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1747 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1748 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1749 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1750 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1751 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1752 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1753 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1754 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1755 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1756 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1757 | // | simd | cancellation | | |
| 1758 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1759 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1760 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1761 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1762 | // | simd | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1763 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1764 | // | for simd | parallel | | |
| 1765 | // | for simd | for | | |
| 1766 | // | for simd | for simd | | |
| 1767 | // | for simd | master | | |
| 1768 | // | for simd | critical | | |
| 1769 | // | for simd | simd | | |
| 1770 | // | for simd | sections | | |
| 1771 | // | for simd | section | | |
| 1772 | // | for simd | single | | |
| 1773 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1774 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1775 | // | for simd |parallel sections| | |
| 1776 | // | for simd | task | | |
| 1777 | // | for simd | taskyield | | |
| 1778 | // | for simd | barrier | | |
| 1779 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1780 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1781 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1782 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1783 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1784 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1785 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1786 | // | for simd | cancellation | | |
| 1787 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1788 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1789 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1790 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1791 | // | for simd | distribute | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1792 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1793 | // | parallel for simd| parallel | | |
| 1794 | // | parallel for simd| for | | |
| 1795 | // | parallel for simd| for simd | | |
| 1796 | // | parallel for simd| master | | |
| 1797 | // | parallel for simd| critical | | |
| 1798 | // | parallel for simd| simd | | |
| 1799 | // | parallel for simd| sections | | |
| 1800 | // | parallel for simd| section | | |
| 1801 | // | parallel for simd| single | | |
| 1802 | // | parallel for simd| parallel for | | |
| 1803 | // | parallel for simd|parallel for simd| | |
| 1804 | // | parallel for simd|parallel sections| | |
| 1805 | // | parallel for simd| task | | |
| 1806 | // | parallel for simd| taskyield | | |
| 1807 | // | parallel for simd| barrier | | |
| 1808 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1809 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1810 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1811 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1812 | // | parallel for simd| atomic | | |
| 1813 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1814 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1815 | // | parallel for simd| cancellation | | |
| 1816 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1817 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1818 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1819 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1820 | // | parallel for simd| distribute | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1821 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1822 | // | sections | parallel | * | |
| 1823 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1824 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1825 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1826 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1827 | // | sections | simd | * | |
| 1828 | // | sections | sections | + | |
| 1829 | // | sections | section | * | |
| 1830 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1831 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1832 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1833 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1834 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1835 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1836 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1837 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1838 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1839 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1840 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1841 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1842 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1843 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1844 | // | sections | cancellation | | |
| 1845 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1846 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1847 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1848 | // | sections | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1849 | // | sections | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1850 | // +------------------+-----------------+------------------------------------+ |
| 1851 | // | section | parallel | * | |
| 1852 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1853 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1854 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1855 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1856 | // | section | simd | * | |
| 1857 | // | section | sections | + | |
| 1858 | // | section | section | + | |
| 1859 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1860 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1861 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1862 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1863 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1864 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1865 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1866 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1867 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1868 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1869 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1870 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1871 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1872 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1873 | // | section | cancellation | | |
| 1874 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1875 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1876 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1877 | // | section | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1878 | // | section | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1879 | // +------------------+-----------------+------------------------------------+ |
| 1880 | // | single | parallel | * | |
| 1881 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1882 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1883 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1884 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1885 | // | single | simd | * | |
| 1886 | // | single | sections | + | |
| 1887 | // | single | section | + | |
| 1888 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1889 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1890 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1891 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1892 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1893 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1894 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1895 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1896 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1897 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1898 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1899 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1900 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1901 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1902 | // | single | cancellation | | |
| 1903 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1904 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1905 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1906 | // | single | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1907 | // | single | distribute | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1908 | // +------------------+-----------------+------------------------------------+ |
| 1909 | // | parallel for | parallel | * | |
| 1910 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1911 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1912 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1913 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1914 | // | parallel for | simd | * | |
| 1915 | // | parallel for | sections | + | |
| 1916 | // | parallel for | section | + | |
| 1917 | // | parallel for | single | + | |
| 1918 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1919 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1920 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1921 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1922 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1923 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1924 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1925 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1926 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1927 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1928 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1929 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1930 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1931 | // | parallel for | cancellation | | |
| 1932 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1933 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1934 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1935 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1936 | // | parallel for | distribute | | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1937 | // +------------------+-----------------+------------------------------------+ |
| 1938 | // | parallel sections| parallel | * | |
| 1939 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1940 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1941 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1942 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1943 | // | parallel sections| simd | * | |
| 1944 | // | parallel sections| sections | + | |
| 1945 | // | parallel sections| section | * | |
| 1946 | // | parallel sections| single | + | |
| 1947 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1948 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1949 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1950 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1951 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1952 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1953 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1954 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1955 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1956 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1957 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1958 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1959 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1960 | // | parallel sections| cancellation | | |
| 1961 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1962 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1963 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1964 | // | parallel sections| taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1965 | // | parallel sections| distribute | | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1966 | // +------------------+-----------------+------------------------------------+ |
| 1967 | // | task | parallel | * | |
| 1968 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1969 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1970 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1971 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1972 | // | task | simd | * | |
| 1973 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1974 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1975 | // | task | single | + | |
| 1976 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1977 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1978 | // | task |parallel sections| * | |
| 1979 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1980 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1981 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1982 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1983 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1984 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1985 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1986 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1987 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1988 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1989 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1990 | // | | point | ! | |
| 1991 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1992 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1993 | // | task | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1994 | // | task | distribute | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1995 | // +------------------+-----------------+------------------------------------+ |
| 1996 | // | ordered | parallel | * | |
| 1997 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1998 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1999 | // | ordered | master | * | |
| 2000 | // | ordered | critical | * | |
| 2001 | // | ordered | simd | * | |
| 2002 | // | ordered | sections | + | |
| 2003 | // | ordered | section | + | |
| 2004 | // | ordered | single | + | |
| 2005 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2006 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2007 | // | ordered |parallel sections| * | |
| 2008 | // | ordered | task | * | |
| 2009 | // | ordered | taskyield | * | |
| 2010 | // | ordered | barrier | + | |
| 2011 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2012 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2013 | // | ordered | flush | * | |
| 2014 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2015 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2016 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2017 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2018 | // | ordered | cancellation | | |
| 2019 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2020 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2021 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2022 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2023 | // | ordered | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2024 | // +------------------+-----------------+------------------------------------+ |
| 2025 | // | atomic | parallel | | |
| 2026 | // | atomic | for | | |
| 2027 | // | atomic | for simd | | |
| 2028 | // | atomic | master | | |
| 2029 | // | atomic | critical | | |
| 2030 | // | atomic | simd | | |
| 2031 | // | atomic | sections | | |
| 2032 | // | atomic | section | | |
| 2033 | // | atomic | single | | |
| 2034 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2035 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2036 | // | atomic |parallel sections| | |
| 2037 | // | atomic | task | | |
| 2038 | // | atomic | taskyield | | |
| 2039 | // | atomic | barrier | | |
| 2040 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2041 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2042 | // | atomic | flush | | |
| 2043 | // | atomic | ordered | | |
| 2044 | // | atomic | atomic | | |
| 2045 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2046 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2047 | // | atomic | cancellation | | |
| 2048 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2049 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2050 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2051 | // | atomic | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2052 | // | atomic | distribute | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2053 | // +------------------+-----------------+------------------------------------+ |
| 2054 | // | target | parallel | * | |
| 2055 | // | target | for | * | |
| 2056 | // | target | for simd | * | |
| 2057 | // | target | master | * | |
| 2058 | // | target | critical | * | |
| 2059 | // | target | simd | * | |
| 2060 | // | target | sections | * | |
| 2061 | // | target | section | * | |
| 2062 | // | target | single | * | |
| 2063 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2064 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2065 | // | target |parallel sections| * | |
| 2066 | // | target | task | * | |
| 2067 | // | target | taskyield | * | |
| 2068 | // | target | barrier | * | |
| 2069 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2070 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2071 | // | target | flush | * | |
| 2072 | // | target | ordered | * | |
| 2073 | // | target | atomic | * | |
| 2074 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2075 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2076 | // | target | cancellation | | |
| 2077 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2078 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2079 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2080 | // | target | taskloop simd | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2081 | // | target | distribute | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2082 | // +------------------+-----------------+------------------------------------+ |
| 2083 | // | teams | parallel | * | |
| 2084 | // | teams | for | + | |
| 2085 | // | teams | for simd | + | |
| 2086 | // | teams | master | + | |
| 2087 | // | teams | critical | + | |
| 2088 | // | teams | simd | + | |
| 2089 | // | teams | sections | + | |
| 2090 | // | teams | section | + | |
| 2091 | // | teams | single | + | |
| 2092 | // | teams | parallel for | * | |
| 2093 | // | teams |parallel for simd| * | |
| 2094 | // | teams |parallel sections| * | |
| 2095 | // | teams | task | + | |
| 2096 | // | teams | taskyield | + | |
| 2097 | // | teams | barrier | + | |
| 2098 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2099 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2100 | // | teams | flush | + | |
| 2101 | // | teams | ordered | + | |
| 2102 | // | teams | atomic | + | |
| 2103 | // | teams | target | + | |
| 2104 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2105 | // | teams | cancellation | | |
| 2106 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2107 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2108 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2109 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2110 | // | teams | distribute | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2111 | // +------------------+-----------------+------------------------------------+ |
| 2112 | // | taskloop | parallel | * | |
| 2113 | // | taskloop | for | + | |
| 2114 | // | taskloop | for simd | + | |
| 2115 | // | taskloop | master | + | |
| 2116 | // | taskloop | critical | * | |
| 2117 | // | taskloop | simd | * | |
| 2118 | // | taskloop | sections | + | |
| 2119 | // | taskloop | section | + | |
| 2120 | // | taskloop | single | + | |
| 2121 | // | taskloop | parallel for | * | |
| 2122 | // | taskloop |parallel for simd| * | |
| 2123 | // | taskloop |parallel sections| * | |
| 2124 | // | taskloop | task | * | |
| 2125 | // | taskloop | taskyield | * | |
| 2126 | // | taskloop | barrier | + | |
| 2127 | // | taskloop | taskwait | * | |
| 2128 | // | taskloop | taskgroup | * | |
| 2129 | // | taskloop | flush | * | |
| 2130 | // | taskloop | ordered | + | |
| 2131 | // | taskloop | atomic | * | |
| 2132 | // | taskloop | target | * | |
| 2133 | // | taskloop | teams | + | |
| 2134 | // | taskloop | cancellation | | |
| 2135 | // | | point | | |
| 2136 | // | taskloop | cancel | | |
| 2137 | // | taskloop | taskloop | * | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2138 | // | taskloop | distribute | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2139 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2140 | // | taskloop simd | parallel | | |
| 2141 | // | taskloop simd | for | | |
| 2142 | // | taskloop simd | for simd | | |
| 2143 | // | taskloop simd | master | | |
| 2144 | // | taskloop simd | critical | | |
| 2145 | // | taskloop simd | simd | | |
| 2146 | // | taskloop simd | sections | | |
| 2147 | // | taskloop simd | section | | |
| 2148 | // | taskloop simd | single | | |
| 2149 | // | taskloop simd | parallel for | | |
| 2150 | // | taskloop simd |parallel for simd| | |
| 2151 | // | taskloop simd |parallel sections| | |
| 2152 | // | taskloop simd | task | | |
| 2153 | // | taskloop simd | taskyield | | |
| 2154 | // | taskloop simd | barrier | | |
| 2155 | // | taskloop simd | taskwait | | |
| 2156 | // | taskloop simd | taskgroup | | |
| 2157 | // | taskloop simd | flush | | |
| 2158 | // | taskloop simd | ordered | + (with simd clause) | |
| 2159 | // | taskloop simd | atomic | | |
| 2160 | // | taskloop simd | target | | |
| 2161 | // | taskloop simd | teams | | |
| 2162 | // | taskloop simd | cancellation | | |
| 2163 | // | | point | | |
| 2164 | // | taskloop simd | cancel | | |
| 2165 | // | taskloop simd | taskloop | | |
| 2166 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2167 | // | taskloop simd | distribute | | |
| 2168 | // +------------------+-----------------+------------------------------------+ |
| 2169 | // | distribute | parallel | * | |
| 2170 | // | distribute | for | * | |
| 2171 | // | distribute | for simd | * | |
| 2172 | // | distribute | master | * | |
| 2173 | // | distribute | critical | * | |
| 2174 | // | distribute | simd | * | |
| 2175 | // | distribute | sections | * | |
| 2176 | // | distribute | section | * | |
| 2177 | // | distribute | single | * | |
| 2178 | // | distribute | parallel for | * | |
| 2179 | // | distribute |parallel for simd| * | |
| 2180 | // | distribute |parallel sections| * | |
| 2181 | // | distribute | task | * | |
| 2182 | // | distribute | taskyield | * | |
| 2183 | // | distribute | barrier | * | |
| 2184 | // | distribute | taskwait | * | |
| 2185 | // | distribute | taskgroup | * | |
| 2186 | // | distribute | flush | * | |
| 2187 | // | distribute | ordered | + | |
| 2188 | // | distribute | atomic | * | |
| 2189 | // | distribute | target | | |
| 2190 | // | distribute | teams | | |
| 2191 | // | distribute | cancellation | + | |
| 2192 | // | | point | | |
| 2193 | // | distribute | cancel | + | |
| 2194 | // | distribute | taskloop | * | |
| 2195 | // | distribute | taskloop simd | * | |
| 2196 | // | distribute | distribute | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2197 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2198 | if (Stack->getCurScope()) { |
| 2199 | auto ParentRegion = Stack->getParentDirective(); |
| 2200 | bool NestingProhibited = false; |
| 2201 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2202 | enum { |
| 2203 | NoRecommend, |
| 2204 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2205 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2206 | ShouldBeInTargetRegion, |
| 2207 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2208 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2209 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2210 | // OpenMP [2.16, Nesting of Regions] |
| 2211 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2212 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2213 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2214 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2215 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2216 | return true; |
| 2217 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2218 | if (ParentRegion == OMPD_atomic) { |
| 2219 | // OpenMP [2.16, Nesting of Regions] |
| 2220 | // OpenMP constructs may not be nested inside an atomic region. |
| 2221 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2222 | return true; |
| 2223 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2224 | if (CurrentRegion == OMPD_section) { |
| 2225 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2226 | // Orphaned section directives are prohibited. That is, the section |
| 2227 | // directives must appear within the sections construct and must not be |
| 2228 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2229 | if (ParentRegion != OMPD_sections && |
| 2230 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2231 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2232 | << (ParentRegion != OMPD_unknown) |
| 2233 | << getOpenMPDirectiveName(ParentRegion); |
| 2234 | return true; |
| 2235 | } |
| 2236 | return false; |
| 2237 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2238 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2239 | // called from OpenMP regions with the required preconditions). |
| 2240 | if (ParentRegion == OMPD_unknown) |
| 2241 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2242 | if (CurrentRegion == OMPD_cancellation_point || |
| 2243 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2244 | // OpenMP [2.16, Nesting of Regions] |
| 2245 | // A cancellation point construct for which construct-type-clause is |
| 2246 | // taskgroup must be nested inside a task construct. A cancellation |
| 2247 | // point construct for which construct-type-clause is not taskgroup must |
| 2248 | // be closely nested inside an OpenMP construct that matches the type |
| 2249 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2250 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2251 | // nested inside a task construct. A cancel construct for which |
| 2252 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2253 | // OpenMP construct that matches the type specified in |
| 2254 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2255 | NestingProhibited = |
| 2256 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2257 | (CancelRegion == OMPD_for && |
| 2258 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2259 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2260 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2261 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2262 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2263 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2264 | // OpenMP [2.16, Nesting of Regions] |
| 2265 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2266 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2267 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2268 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2269 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2270 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2271 | // OpenMP [2.16, Nesting of Regions] |
| 2272 | // A critical region may not be nested (closely or otherwise) inside a |
| 2273 | // critical region with the same name. Note that this restriction is not |
| 2274 | // sufficient to prevent deadlock. |
| 2275 | SourceLocation PreviousCriticalLoc; |
| 2276 | bool DeadLock = |
| 2277 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2278 | OpenMPDirectiveKind K, |
| 2279 | const DeclarationNameInfo &DNI, |
| 2280 | SourceLocation Loc) |
| 2281 | ->bool { |
| 2282 | if (K == OMPD_critical && |
| 2283 | DNI.getName() == CurrentName.getName()) { |
| 2284 | PreviousCriticalLoc = Loc; |
| 2285 | return true; |
| 2286 | } else |
| 2287 | return false; |
| 2288 | }, |
| 2289 | false /* skip top directive */); |
| 2290 | if (DeadLock) { |
| 2291 | SemaRef.Diag(StartLoc, |
| 2292 | diag::err_omp_prohibited_region_critical_same_name) |
| 2293 | << CurrentName.getName(); |
| 2294 | if (PreviousCriticalLoc.isValid()) |
| 2295 | SemaRef.Diag(PreviousCriticalLoc, |
| 2296 | diag::note_omp_previous_critical_region); |
| 2297 | return true; |
| 2298 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2299 | } else if (CurrentRegion == OMPD_barrier) { |
| 2300 | // OpenMP [2.16, Nesting of Regions] |
| 2301 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2302 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2303 | NestingProhibited = |
| 2304 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2305 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2306 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2307 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2308 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2309 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2310 | // OpenMP [2.16, Nesting of Regions] |
| 2311 | // A worksharing region may not be closely nested inside a worksharing, |
| 2312 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2313 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2314 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2315 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2316 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2317 | isOpenMPTaskLoopDirective(ParentRegion); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2318 | Recommend = ShouldBeInParallelRegion; |
| 2319 | } else if (CurrentRegion == OMPD_ordered) { |
| 2320 | // OpenMP [2.16, Nesting of Regions] |
| 2321 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2322 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2323 | // An ordered region must be closely nested inside a loop region (or |
| 2324 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2325 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2326 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2327 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2328 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2329 | ParentRegion == OMPD_task || |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2330 | isOpenMPTaskLoopDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2331 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2332 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2333 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2334 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2335 | // OpenMP [2.16, Nesting of Regions] |
| 2336 | // If specified, a teams construct must be contained within a target |
| 2337 | // construct. |
| 2338 | NestingProhibited = ParentRegion != OMPD_target; |
| 2339 | Recommend = ShouldBeInTargetRegion; |
| 2340 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2341 | } |
| 2342 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2343 | // OpenMP [2.16, Nesting of Regions] |
| 2344 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2345 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2346 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2347 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2348 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2349 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2350 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2351 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 2352 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2353 | // The region associated with the distribute construct must be strictly |
| 2354 | // nested inside a teams region |
| 2355 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 2356 | Recommend = ShouldBeInTeamsRegion; |
| 2357 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2358 | if (NestingProhibited) { |
| 2359 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2360 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2361 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2362 | return true; |
| 2363 | } |
| 2364 | } |
| 2365 | return false; |
| 2366 | } |
| 2367 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2368 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2369 | ArrayRef<OMPClause *> Clauses, |
| 2370 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2371 | bool ErrorFound = false; |
| 2372 | unsigned NamedModifiersNumber = 0; |
| 2373 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2374 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2375 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2376 | for (const auto *C : Clauses) { |
| 2377 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2378 | // At most one if clause without a directive-name-modifier can appear on |
| 2379 | // the directive. |
| 2380 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2381 | if (FoundNameModifiers[CurNM]) { |
| 2382 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2383 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2384 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2385 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2386 | } else if (CurNM != OMPD_unknown) { |
| 2387 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2388 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2389 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2390 | FoundNameModifiers[CurNM] = IC; |
| 2391 | if (CurNM == OMPD_unknown) |
| 2392 | continue; |
| 2393 | // Check if the specified name modifier is allowed for the current |
| 2394 | // directive. |
| 2395 | // At most one if clause with the particular directive-name-modifier can |
| 2396 | // appear on the directive. |
| 2397 | bool MatchFound = false; |
| 2398 | for (auto NM : AllowedNameModifiers) { |
| 2399 | if (CurNM == NM) { |
| 2400 | MatchFound = true; |
| 2401 | break; |
| 2402 | } |
| 2403 | } |
| 2404 | if (!MatchFound) { |
| 2405 | S.Diag(IC->getNameModifierLoc(), |
| 2406 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2407 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2408 | ErrorFound = true; |
| 2409 | } |
| 2410 | } |
| 2411 | } |
| 2412 | // If any if clause on the directive includes a directive-name-modifier then |
| 2413 | // all if clauses on the directive must include a directive-name-modifier. |
| 2414 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2415 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2416 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2417 | diag::err_omp_no_more_if_clause); |
| 2418 | } else { |
| 2419 | std::string Values; |
| 2420 | std::string Sep(", "); |
| 2421 | unsigned AllowedCnt = 0; |
| 2422 | unsigned TotalAllowedNum = |
| 2423 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2424 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2425 | ++Cnt) { |
| 2426 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2427 | if (!FoundNameModifiers[NM]) { |
| 2428 | Values += "'"; |
| 2429 | Values += getOpenMPDirectiveName(NM); |
| 2430 | Values += "'"; |
| 2431 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2432 | Values += " or "; |
| 2433 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2434 | Values += Sep; |
| 2435 | ++AllowedCnt; |
| 2436 | } |
| 2437 | } |
| 2438 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2439 | diag::err_omp_unnamed_if_clause) |
| 2440 | << (TotalAllowedNum > 1) << Values; |
| 2441 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2442 | for (auto Loc : NameModifierLoc) { |
| 2443 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2444 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2445 | ErrorFound = true; |
| 2446 | } |
| 2447 | return ErrorFound; |
| 2448 | } |
| 2449 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2450 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2451 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2452 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2453 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2454 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2455 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2456 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2457 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2458 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2459 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2460 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2461 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2462 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2463 | if (AStmt) { |
| 2464 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2465 | |
| 2466 | // Check default data sharing attributes for referenced variables. |
| 2467 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2468 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2469 | if (DSAChecker.isErrorFound()) |
| 2470 | return StmtError(); |
| 2471 | // Generate list of implicitly defined firstprivate variables. |
| 2472 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2473 | |
| 2474 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2475 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2476 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2477 | SourceLocation(), SourceLocation())) { |
| 2478 | ClausesWithImplicit.push_back(Implicit); |
| 2479 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2480 | DSAChecker.getImplicitFirstprivate().size(); |
| 2481 | } else |
| 2482 | ErrorFound = true; |
| 2483 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2484 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2485 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2486 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2487 | switch (Kind) { |
| 2488 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2489 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2490 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2491 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2492 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2493 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2494 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2495 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2496 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2497 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2498 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2499 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2500 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2501 | case OMPD_for_simd: |
| 2502 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2503 | EndLoc, VarsWithInheritedDSA); |
| 2504 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2505 | case OMPD_sections: |
| 2506 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2507 | EndLoc); |
| 2508 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2509 | case OMPD_section: |
| 2510 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2511 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2512 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2513 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2514 | case OMPD_single: |
| 2515 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2516 | EndLoc); |
| 2517 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2518 | case OMPD_master: |
| 2519 | assert(ClausesWithImplicit.empty() && |
| 2520 | "No clauses are allowed for 'omp master' directive"); |
| 2521 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2522 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2523 | case OMPD_critical: |
| 2524 | assert(ClausesWithImplicit.empty() && |
| 2525 | "No clauses are allowed for 'omp critical' directive"); |
| 2526 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2527 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2528 | case OMPD_parallel_for: |
| 2529 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2530 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2531 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2532 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2533 | case OMPD_parallel_for_simd: |
| 2534 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2535 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2536 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2537 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2538 | case OMPD_parallel_sections: |
| 2539 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2540 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2541 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2542 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2543 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2544 | Res = |
| 2545 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2546 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2547 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2548 | case OMPD_taskyield: |
| 2549 | assert(ClausesWithImplicit.empty() && |
| 2550 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2551 | assert(AStmt == nullptr && |
| 2552 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2553 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2554 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2555 | case OMPD_barrier: |
| 2556 | assert(ClausesWithImplicit.empty() && |
| 2557 | "No clauses are allowed for 'omp barrier' directive"); |
| 2558 | assert(AStmt == nullptr && |
| 2559 | "No associated statement allowed for 'omp barrier' directive"); |
| 2560 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2561 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2562 | case OMPD_taskwait: |
| 2563 | assert(ClausesWithImplicit.empty() && |
| 2564 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2565 | assert(AStmt == nullptr && |
| 2566 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2567 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2568 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2569 | case OMPD_taskgroup: |
| 2570 | assert(ClausesWithImplicit.empty() && |
| 2571 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2572 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2573 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2574 | case OMPD_flush: |
| 2575 | assert(AStmt == nullptr && |
| 2576 | "No associated statement allowed for 'omp flush' directive"); |
| 2577 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2578 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2579 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2580 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2581 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2582 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2583 | case OMPD_atomic: |
| 2584 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2585 | EndLoc); |
| 2586 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2587 | case OMPD_teams: |
| 2588 | Res = |
| 2589 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2590 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2591 | case OMPD_target: |
| 2592 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2593 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2594 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2595 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2596 | case OMPD_cancellation_point: |
| 2597 | assert(ClausesWithImplicit.empty() && |
| 2598 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2599 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2600 | "cancellation point' directive"); |
| 2601 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2602 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2603 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2604 | assert(AStmt == nullptr && |
| 2605 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2606 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2607 | CancelRegion); |
| 2608 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2609 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2610 | case OMPD_target_data: |
| 2611 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2612 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2613 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2614 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2615 | case OMPD_taskloop: |
| 2616 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2617 | EndLoc, VarsWithInheritedDSA); |
| 2618 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2619 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2620 | case OMPD_taskloop_simd: |
| 2621 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2622 | EndLoc, VarsWithInheritedDSA); |
| 2623 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2624 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2625 | case OMPD_distribute: |
| 2626 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2627 | EndLoc, VarsWithInheritedDSA); |
| 2628 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2629 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2630 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2631 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2632 | llvm_unreachable("Unknown OpenMP directive"); |
| 2633 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2634 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2635 | for (auto P : VarsWithInheritedDSA) { |
| 2636 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2637 | << P.first << P.second->getSourceRange(); |
| 2638 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2639 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2640 | |
| 2641 | if (!AllowedNameModifiers.empty()) |
| 2642 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2643 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2644 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2645 | if (ErrorFound) |
| 2646 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2647 | return Res; |
| 2648 | } |
| 2649 | |
| 2650 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2651 | Stmt *AStmt, |
| 2652 | SourceLocation StartLoc, |
| 2653 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2654 | if (!AStmt) |
| 2655 | return StmtError(); |
| 2656 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2657 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2658 | // 1.2.2 OpenMP Language Terminology |
| 2659 | // Structured block - An executable statement with a single entry at the |
| 2660 | // top and a single exit at the bottom. |
| 2661 | // The point of exit cannot be a branch out of the structured block. |
| 2662 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2663 | CS->getCapturedDecl()->setNothrow(); |
| 2664 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2665 | getCurFunction()->setHasBranchProtectedScope(); |
| 2666 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2667 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2668 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2669 | } |
| 2670 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2671 | namespace { |
| 2672 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2673 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2674 | /// for IR generation. |
| 2675 | class OpenMPIterationSpaceChecker { |
| 2676 | /// \brief Reference to Sema. |
| 2677 | Sema &SemaRef; |
| 2678 | /// \brief A location for diagnostics (when there is no some better location). |
| 2679 | SourceLocation DefaultLoc; |
| 2680 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2681 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2682 | /// \brief A source location for referring to loop init later. |
| 2683 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2684 | /// \brief A source location for referring to condition later. |
| 2685 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2686 | /// \brief A source location for referring to increment later. |
| 2687 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2688 | /// \brief Loop variable. |
| 2689 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2690 | /// \brief Reference to loop variable. |
| 2691 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2692 | /// \brief Lower bound (initializer for the var). |
| 2693 | Expr *LB; |
| 2694 | /// \brief Upper bound. |
| 2695 | Expr *UB; |
| 2696 | /// \brief Loop step (increment). |
| 2697 | Expr *Step; |
| 2698 | /// \brief This flag is true when condition is one of: |
| 2699 | /// Var < UB |
| 2700 | /// Var <= UB |
| 2701 | /// UB > Var |
| 2702 | /// UB >= Var |
| 2703 | bool TestIsLessOp; |
| 2704 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2705 | bool TestIsStrictOp; |
| 2706 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2707 | bool SubtractStep; |
| 2708 | |
| 2709 | public: |
| 2710 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2711 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2712 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2713 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2714 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2715 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2716 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2717 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2718 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2719 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2720 | /// for less/greater and for strict/non-strict comparison. |
| 2721 | bool CheckCond(Expr *S); |
| 2722 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2723 | /// does not conform, otherwise save loop step (#Step). |
| 2724 | bool CheckInc(Expr *S); |
| 2725 | /// \brief Return the loop counter variable. |
| 2726 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2727 | /// \brief Return the reference expression to loop counter variable. |
| 2728 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2729 | /// \brief Source range of the loop init. |
| 2730 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2731 | /// \brief Source range of the loop condition. |
| 2732 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2733 | /// \brief Source range of the loop increment. |
| 2734 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2735 | /// \brief True if the step should be subtracted. |
| 2736 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2737 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2738 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2739 | /// \brief Build the precondition expression for the loops. |
| 2740 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2741 | /// \brief Build reference expression to the counter be used for codegen. |
| 2742 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2743 | /// \brief Build reference expression to the private counter be used for |
| 2744 | /// codegen. |
| 2745 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2746 | /// \brief Build initization of the counter be used for codegen. |
| 2747 | Expr *BuildCounterInit() const; |
| 2748 | /// \brief Build step of the counter be used for codegen. |
| 2749 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2750 | /// \brief Return true if any expression is dependent. |
| 2751 | bool Dependent() const; |
| 2752 | |
| 2753 | private: |
| 2754 | /// \brief Check the right-hand side of an assignment in the increment |
| 2755 | /// expression. |
| 2756 | bool CheckIncRHS(Expr *RHS); |
| 2757 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2758 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2759 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2760 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2761 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2762 | /// \brief Helper to set loop increment. |
| 2763 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2764 | }; |
| 2765 | |
| 2766 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2767 | if (!Var) { |
| 2768 | assert(!LB && !UB && !Step); |
| 2769 | return false; |
| 2770 | } |
| 2771 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2772 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2773 | } |
| 2774 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2775 | template <typename T> |
| 2776 | static T *getExprAsWritten(T *E) { |
| 2777 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2778 | E = ExprTemp->getSubExpr(); |
| 2779 | |
| 2780 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2781 | E = MTE->GetTemporaryExpr(); |
| 2782 | |
| 2783 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2784 | E = Binder->getSubExpr(); |
| 2785 | |
| 2786 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2787 | E = ICE->getSubExprAsWritten(); |
| 2788 | return E->IgnoreParens(); |
| 2789 | } |
| 2790 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2791 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2792 | DeclRefExpr *NewVarRefExpr, |
| 2793 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2794 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2795 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2796 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2797 | if (!NewVar || !NewLB) |
| 2798 | return true; |
| 2799 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2800 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2801 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2802 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2803 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2804 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2805 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2806 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2807 | LB = NewLB; |
| 2808 | return false; |
| 2809 | } |
| 2810 | |
| 2811 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2812 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2813 | // State consistency checking to ensure correct usage. |
| 2814 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2815 | !TestIsLessOp && !TestIsStrictOp); |
| 2816 | if (!NewUB) |
| 2817 | return true; |
| 2818 | UB = NewUB; |
| 2819 | TestIsLessOp = LessOp; |
| 2820 | TestIsStrictOp = StrictOp; |
| 2821 | ConditionSrcRange = SR; |
| 2822 | ConditionLoc = SL; |
| 2823 | return false; |
| 2824 | } |
| 2825 | |
| 2826 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2827 | // State consistency checking to ensure correct usage. |
| 2828 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2829 | if (!NewStep) |
| 2830 | return true; |
| 2831 | if (!NewStep->isValueDependent()) { |
| 2832 | // Check that the step is integer expression. |
| 2833 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2834 | ExprResult Val = |
| 2835 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2836 | if (Val.isInvalid()) |
| 2837 | return true; |
| 2838 | NewStep = Val.get(); |
| 2839 | |
| 2840 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2841 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2842 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2843 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2844 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2845 | // the loop. |
| 2846 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2847 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2848 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2849 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2850 | // the loop. |
| 2851 | llvm::APSInt Result; |
| 2852 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2853 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2854 | bool IsConstNeg = |
| 2855 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2856 | bool IsConstPos = |
| 2857 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2858 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2859 | if (UB && (IsConstZero || |
| 2860 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2861 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2862 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2863 | diag::err_omp_loop_incr_not_compatible) |
| 2864 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2865 | SemaRef.Diag(ConditionLoc, |
| 2866 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2867 | << TestIsLessOp << ConditionSrcRange; |
| 2868 | return true; |
| 2869 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2870 | if (TestIsLessOp == Subtract) { |
| 2871 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2872 | NewStep).get(); |
| 2873 | Subtract = !Subtract; |
| 2874 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | Step = NewStep; |
| 2878 | SubtractStep = Subtract; |
| 2879 | return false; |
| 2880 | } |
| 2881 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2882 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2883 | // Check init-expr for canonical loop form and save loop counter |
| 2884 | // variable - #Var and its initialization value - #LB. |
| 2885 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2886 | // var = lb |
| 2887 | // integer-type var = lb |
| 2888 | // random-access-iterator-type var = lb |
| 2889 | // pointer-type var = lb |
| 2890 | // |
| 2891 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2892 | if (EmitDiags) { |
| 2893 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2894 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2895 | return true; |
| 2896 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2897 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2898 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2899 | S = E->IgnoreParens(); |
| 2900 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2901 | if (BO->getOpcode() == BO_Assign) |
| 2902 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2903 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2904 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2905 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2906 | if (DS->isSingleDecl()) { |
| 2907 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2908 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2909 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2910 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2911 | SemaRef.Diag(S->getLocStart(), |
| 2912 | diag::ext_omp_loop_not_canonical_init) |
| 2913 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2914 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2915 | } |
| 2916 | } |
| 2917 | } |
| 2918 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2919 | if (CE->getOperator() == OO_Equal) |
| 2920 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2921 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2922 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2923 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2924 | if (EmitDiags) { |
| 2925 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2926 | << S->getSourceRange(); |
| 2927 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2928 | return true; |
| 2929 | } |
| 2930 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2931 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2932 | /// variable (which may be the loop variable) if possible. |
| 2933 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2934 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2935 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2936 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2937 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2938 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2939 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2940 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2941 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2942 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2943 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2944 | if (!DRE) |
| 2945 | return nullptr; |
| 2946 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2947 | } |
| 2948 | |
| 2949 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2950 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2951 | // less/greater and for strict/non-strict comparison. |
| 2952 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2953 | // var relational-op b |
| 2954 | // b relational-op var |
| 2955 | // |
| 2956 | if (!S) { |
| 2957 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2958 | return true; |
| 2959 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2960 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2961 | SourceLocation CondLoc = S->getLocStart(); |
| 2962 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2963 | if (BO->isRelationalOp()) { |
| 2964 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2965 | return SetUB(BO->getRHS(), |
| 2966 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2967 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2968 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2969 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2970 | return SetUB(BO->getLHS(), |
| 2971 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2972 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2973 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2974 | } |
| 2975 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2976 | if (CE->getNumArgs() == 2) { |
| 2977 | auto Op = CE->getOperator(); |
| 2978 | switch (Op) { |
| 2979 | case OO_Greater: |
| 2980 | case OO_GreaterEqual: |
| 2981 | case OO_Less: |
| 2982 | case OO_LessEqual: |
| 2983 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2984 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2985 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2986 | CE->getOperatorLoc()); |
| 2987 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2988 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2989 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2990 | CE->getOperatorLoc()); |
| 2991 | break; |
| 2992 | default: |
| 2993 | break; |
| 2994 | } |
| 2995 | } |
| 2996 | } |
| 2997 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2998 | << S->getSourceRange() << Var; |
| 2999 | return true; |
| 3000 | } |
| 3001 | |
| 3002 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3003 | // RHS of canonical loop form increment can be: |
| 3004 | // var + incr |
| 3005 | // incr + var |
| 3006 | // var - incr |
| 3007 | // |
| 3008 | RHS = RHS->IgnoreParenImpCasts(); |
| 3009 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 3010 | if (BO->isAdditiveOp()) { |
| 3011 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 3012 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3013 | return SetStep(BO->getRHS(), !IsAdd); |
| 3014 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 3015 | return SetStep(BO->getLHS(), false); |
| 3016 | } |
| 3017 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 3018 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3019 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 3020 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3021 | return SetStep(CE->getArg(1), !IsAdd); |
| 3022 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 3023 | return SetStep(CE->getArg(0), false); |
| 3024 | } |
| 3025 | } |
| 3026 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3027 | << RHS->getSourceRange() << Var; |
| 3028 | return true; |
| 3029 | } |
| 3030 | |
| 3031 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3032 | // Check incr-expr for canonical loop form and return true if it |
| 3033 | // does not conform. |
| 3034 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3035 | // ++var |
| 3036 | // var++ |
| 3037 | // --var |
| 3038 | // var-- |
| 3039 | // var += incr |
| 3040 | // var -= incr |
| 3041 | // var = var + incr |
| 3042 | // var = incr + var |
| 3043 | // var = var - incr |
| 3044 | // |
| 3045 | if (!S) { |
| 3046 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 3047 | return true; |
| 3048 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3049 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3050 | S = S->IgnoreParens(); |
| 3051 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 3052 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 3053 | return SetStep( |
| 3054 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 3055 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 3056 | false); |
| 3057 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 3058 | switch (BO->getOpcode()) { |
| 3059 | case BO_AddAssign: |
| 3060 | case BO_SubAssign: |
| 3061 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3062 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3063 | break; |
| 3064 | case BO_Assign: |
| 3065 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 3066 | return CheckIncRHS(BO->getRHS()); |
| 3067 | break; |
| 3068 | default: |
| 3069 | break; |
| 3070 | } |
| 3071 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 3072 | switch (CE->getOperator()) { |
| 3073 | case OO_PlusPlus: |
| 3074 | case OO_MinusMinus: |
| 3075 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3076 | return SetStep( |
| 3077 | SemaRef.ActOnIntegerConstant( |
| 3078 | CE->getLocStart(), |
| 3079 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 3080 | false); |
| 3081 | break; |
| 3082 | case OO_PlusEqual: |
| 3083 | case OO_MinusEqual: |
| 3084 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3085 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3086 | break; |
| 3087 | case OO_Equal: |
| 3088 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 3089 | return CheckIncRHS(CE->getArg(1)); |
| 3090 | break; |
| 3091 | default: |
| 3092 | break; |
| 3093 | } |
| 3094 | } |
| 3095 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 3096 | << S->getSourceRange() << Var; |
| 3097 | return true; |
| 3098 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3099 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3100 | namespace { |
| 3101 | // Transform variables declared in GNU statement expressions to new ones to |
| 3102 | // avoid crash on codegen. |
| 3103 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 3104 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 3105 | |
| 3106 | public: |
| 3107 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 3108 | |
| 3109 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3110 | if (auto *VD = cast<VarDecl>(D)) |
| 3111 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3112 | !isa<ImplicitParamDecl>(D)) { |
| 3113 | auto *NewVD = VarDecl::Create( |
| 3114 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3115 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3116 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3117 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3118 | NewVD->setInit(VD->getInit()); |
| 3119 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3120 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3121 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3122 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3123 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3124 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3125 | NewVD->setPreviousDeclInSameBlockScope( |
| 3126 | VD->isPreviousDeclInSameBlockScope()); |
| 3127 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3128 | if (VD->hasAttrs()) |
| 3129 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3130 | transformedLocalDecl(VD, NewVD); |
| 3131 | return NewVD; |
| 3132 | } |
| 3133 | return BaseTransform::TransformDefinition(Loc, D); |
| 3134 | } |
| 3135 | |
| 3136 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3137 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3138 | if (E->getDecl() != NewD) { |
| 3139 | NewD->setReferenced(); |
| 3140 | NewD->markUsed(SemaRef.Context); |
| 3141 | return DeclRefExpr::Create( |
| 3142 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3143 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3144 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3145 | } |
| 3146 | return BaseTransform::TransformDeclRefExpr(E); |
| 3147 | } |
| 3148 | }; |
| 3149 | } |
| 3150 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3151 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3152 | Expr * |
| 3153 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3154 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3155 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3156 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3157 | auto VarType = Var->getType().getNonReferenceType(); |
| 3158 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3159 | SemaRef.getLangOpts().CPlusPlus) { |
| 3160 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3161 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3162 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3163 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3164 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3165 | if (!Upper || !Lower) |
| 3166 | return nullptr; |
| 3167 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3168 | Sema::AA_Converting, |
| 3169 | /*AllowExplicit=*/true) |
| 3170 | .get(); |
| 3171 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3172 | Sema::AA_Converting, |
| 3173 | /*AllowExplicit=*/true) |
| 3174 | .get(); |
| 3175 | if (!Upper || !Lower) |
| 3176 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3177 | |
| 3178 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3179 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3180 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3181 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3182 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3183 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3184 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3185 | return nullptr; |
| 3186 | } |
| 3187 | } |
| 3188 | |
| 3189 | if (!Diff.isUsable()) |
| 3190 | return nullptr; |
| 3191 | |
| 3192 | // Upper - Lower [- 1] |
| 3193 | if (TestIsStrictOp) |
| 3194 | Diff = SemaRef.BuildBinOp( |
| 3195 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3196 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3197 | if (!Diff.isUsable()) |
| 3198 | return nullptr; |
| 3199 | |
| 3200 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3201 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3202 | if (NewStep.isInvalid()) |
| 3203 | return nullptr; |
| 3204 | NewStep = SemaRef.PerformImplicitConversion( |
| 3205 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3206 | /*AllowExplicit=*/true); |
| 3207 | if (NewStep.isInvalid()) |
| 3208 | return nullptr; |
| 3209 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3210 | if (!Diff.isUsable()) |
| 3211 | return nullptr; |
| 3212 | |
| 3213 | // Parentheses (for dumping/debugging purposes only). |
| 3214 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3215 | if (!Diff.isUsable()) |
| 3216 | return nullptr; |
| 3217 | |
| 3218 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3219 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3220 | if (NewStep.isInvalid()) |
| 3221 | return nullptr; |
| 3222 | NewStep = SemaRef.PerformImplicitConversion( |
| 3223 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3224 | /*AllowExplicit=*/true); |
| 3225 | if (NewStep.isInvalid()) |
| 3226 | return nullptr; |
| 3227 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3228 | if (!Diff.isUsable()) |
| 3229 | return nullptr; |
| 3230 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3231 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3232 | QualType Type = Diff.get()->getType(); |
| 3233 | auto &C = SemaRef.Context; |
| 3234 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3235 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3236 | if (!Type->isIntegerType() || UseVarType) { |
| 3237 | unsigned NewSize = |
| 3238 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3239 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3240 | : Type->hasSignedIntegerRepresentation(); |
| 3241 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3242 | Diff = SemaRef.PerformImplicitConversion( |
| 3243 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3244 | if (!Diff.isUsable()) |
| 3245 | return nullptr; |
| 3246 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3247 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3248 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3249 | if (NewSize != C.getTypeSize(Type)) { |
| 3250 | if (NewSize < C.getTypeSize(Type)) { |
| 3251 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3252 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3253 | << InitSrcRange << ConditionSrcRange; |
| 3254 | } |
| 3255 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3256 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3257 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3258 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3259 | Sema::AA_Converting, true); |
| 3260 | if (!Diff.isUsable()) |
| 3261 | return nullptr; |
| 3262 | } |
| 3263 | } |
| 3264 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3265 | return Diff.get(); |
| 3266 | } |
| 3267 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3268 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3269 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3270 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3271 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3272 | TransformToNewDefs Transform(SemaRef); |
| 3273 | |
| 3274 | auto NewLB = Transform.TransformExpr(LB); |
| 3275 | auto NewUB = Transform.TransformExpr(UB); |
| 3276 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3277 | return Cond; |
| 3278 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3279 | Sema::AA_Converting, |
| 3280 | /*AllowExplicit=*/true); |
| 3281 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3282 | Sema::AA_Converting, |
| 3283 | /*AllowExplicit=*/true); |
| 3284 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3285 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3286 | auto CondExpr = SemaRef.BuildBinOp( |
| 3287 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3288 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3289 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3290 | if (CondExpr.isUsable()) { |
| 3291 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3292 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3293 | /*AllowExplicit=*/true); |
| 3294 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3295 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3296 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3297 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3298 | } |
| 3299 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3300 | /// \brief Build reference expression to the counter be used for codegen. |
| 3301 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3302 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3303 | DefaultLoc); |
| 3304 | } |
| 3305 | |
| 3306 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3307 | if (Var && !Var->isInvalidDecl()) { |
| 3308 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3309 | auto *PrivateVar = |
| 3310 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3311 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3312 | if (PrivateVar->isInvalidDecl()) |
| 3313 | return nullptr; |
| 3314 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3315 | } |
| 3316 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3317 | } |
| 3318 | |
| 3319 | /// \brief Build initization of the counter be used for codegen. |
| 3320 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3321 | |
| 3322 | /// \brief Build step of the counter be used for codegen. |
| 3323 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3324 | |
| 3325 | /// \brief Iteration space of a single for loop. |
| 3326 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3327 | /// \brief Condition of the loop. |
| 3328 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3329 | /// \brief This expression calculates the number of iterations in the loop. |
| 3330 | /// It is always possible to calculate it before starting the loop. |
| 3331 | Expr *NumIterations; |
| 3332 | /// \brief The loop counter variable. |
| 3333 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3334 | /// \brief Private loop counter variable. |
| 3335 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3336 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3337 | Expr *CounterInit; |
| 3338 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3339 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3340 | Expr *CounterStep; |
| 3341 | /// \brief Should step be subtracted? |
| 3342 | bool Subtract; |
| 3343 | /// \brief Source range of the loop init. |
| 3344 | SourceRange InitSrcRange; |
| 3345 | /// \brief Source range of the loop condition. |
| 3346 | SourceRange CondSrcRange; |
| 3347 | /// \brief Source range of the loop increment. |
| 3348 | SourceRange IncSrcRange; |
| 3349 | }; |
| 3350 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3351 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3352 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3353 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3354 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3355 | assert(Init && "Expected loop in canonical form."); |
| 3356 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 3357 | if (CollapseIteration > 0 && |
| 3358 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3359 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 3360 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3361 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 3362 | } |
| 3363 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 3364 | } |
| 3365 | } |
| 3366 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3367 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3368 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3369 | static bool CheckOpenMPIterationSpace( |
| 3370 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3371 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3372 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3373 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3374 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3375 | // OpenMP [2.6, Canonical Loop Form] |
| 3376 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3377 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3378 | if (!For) { |
| 3379 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3380 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3381 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3382 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3383 | if (NestedLoopCount > 1) { |
| 3384 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3385 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3386 | diag::note_omp_collapse_ordered_expr) |
| 3387 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3388 | << OrderedLoopCountExpr->getSourceRange(); |
| 3389 | else if (CollapseLoopCountExpr) |
| 3390 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3391 | diag::note_omp_collapse_ordered_expr) |
| 3392 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3393 | else |
| 3394 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3395 | diag::note_omp_collapse_ordered_expr) |
| 3396 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3397 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3398 | return true; |
| 3399 | } |
| 3400 | assert(For->getBody()); |
| 3401 | |
| 3402 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3403 | |
| 3404 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3405 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3406 | if (ISC.CheckInit(Init)) { |
| 3407 | return true; |
| 3408 | } |
| 3409 | |
| 3410 | bool HasErrors = false; |
| 3411 | |
| 3412 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3413 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3414 | |
| 3415 | // OpenMP [2.6, Canonical Loop Form] |
| 3416 | // Var is one of the following: |
| 3417 | // A variable of signed or unsigned integer type. |
| 3418 | // For C++, a variable of a random access iterator type. |
| 3419 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3420 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3421 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3422 | !VarType->isPointerType() && |
| 3423 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3424 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3425 | << SemaRef.getLangOpts().CPlusPlus; |
| 3426 | HasErrors = true; |
| 3427 | } |
| 3428 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3429 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3430 | // Construct |
| 3431 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3432 | // parallel for construct is (are) private. |
| 3433 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3434 | // with just one associated for-loop is linear with a constant-linear-step |
| 3435 | // that is the increment of the associated for-loop. |
| 3436 | // Exclude loop var from the list of variables with implicitly defined data |
| 3437 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3438 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3439 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3440 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3441 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3442 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3443 | // with just one associated for-loop may be listed in a linear clause with a |
| 3444 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3445 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3446 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3447 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3448 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3449 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3450 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3451 | auto PredeterminedCKind = |
| 3452 | isOpenMPSimdDirective(DKind) |
| 3453 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3454 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3455 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3456 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3457 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 3458 | isOpenMPDistributeDirective(DKind)) && |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3459 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3460 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate && |
| 3461 | DVar.CKind != OMPC_threadprivate)) && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3462 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 3463 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3464 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3465 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3466 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3467 | if (DVar.RefExpr == nullptr) |
| 3468 | DVar.CKind = PredeterminedCKind; |
| 3469 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3470 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3471 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3472 | // Make the loop iteration variable private (for worksharing constructs), |
| 3473 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3474 | // lastprivate (for simd directives with several collapsed or ordered |
| 3475 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3476 | if (DVar.CKind == OMPC_unknown) |
| 3477 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3478 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3479 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3480 | } |
| 3481 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3482 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3483 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3484 | // Check test-expr. |
| 3485 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3486 | |
| 3487 | // Check incr-expr. |
| 3488 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3489 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3490 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3491 | return HasErrors; |
| 3492 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3493 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3494 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3495 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3496 | DSA.getCurScope(), (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3497 | isOpenMPTaskLoopDirective(DKind) || |
| 3498 | isOpenMPDistributeDirective(DKind))); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3499 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3500 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3501 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3502 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3503 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3504 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3505 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3506 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3507 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3508 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3509 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3510 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3511 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3512 | ResultIterSpace.CounterInit == nullptr || |
| 3513 | ResultIterSpace.CounterStep == nullptr); |
| 3514 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3515 | return HasErrors; |
| 3516 | } |
| 3517 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3518 | /// \brief Build 'VarRef = Start. |
| 3519 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3520 | ExprResult VarRef, ExprResult Start) { |
| 3521 | TransformToNewDefs Transform(SemaRef); |
| 3522 | // Build 'VarRef = Start. |
| 3523 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3524 | if (NewStart.isInvalid()) |
| 3525 | return ExprError(); |
| 3526 | NewStart = SemaRef.PerformImplicitConversion( |
| 3527 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3528 | Sema::AA_Converting, |
| 3529 | /*AllowExplicit=*/true); |
| 3530 | if (NewStart.isInvalid()) |
| 3531 | return ExprError(); |
| 3532 | NewStart = SemaRef.PerformImplicitConversion( |
| 3533 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3534 | /*AllowExplicit=*/true); |
| 3535 | if (!NewStart.isUsable()) |
| 3536 | return ExprError(); |
| 3537 | |
| 3538 | auto Init = |
| 3539 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3540 | return Init; |
| 3541 | } |
| 3542 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3543 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3544 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3545 | SourceLocation Loc, ExprResult VarRef, |
| 3546 | ExprResult Start, ExprResult Iter, |
| 3547 | ExprResult Step, bool Subtract) { |
| 3548 | // Add parentheses (for debugging purposes only). |
| 3549 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3550 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3551 | !Step.isUsable()) |
| 3552 | return ExprError(); |
| 3553 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3554 | TransformToNewDefs Transform(SemaRef); |
| 3555 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3556 | if (NewStep.isInvalid()) |
| 3557 | return ExprError(); |
| 3558 | NewStep = SemaRef.PerformImplicitConversion( |
| 3559 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3560 | Sema::AA_Converting, |
| 3561 | /*AllowExplicit=*/true); |
| 3562 | if (NewStep.isInvalid()) |
| 3563 | return ExprError(); |
| 3564 | ExprResult Update = |
| 3565 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3566 | if (!Update.isUsable()) |
| 3567 | return ExprError(); |
| 3568 | |
| 3569 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3570 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3571 | if (NewStart.isInvalid()) |
| 3572 | return ExprError(); |
| 3573 | NewStart = SemaRef.PerformImplicitConversion( |
| 3574 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3575 | Sema::AA_Converting, |
| 3576 | /*AllowExplicit=*/true); |
| 3577 | if (NewStart.isInvalid()) |
| 3578 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3579 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3580 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3581 | if (!Update.isUsable()) |
| 3582 | return ExprError(); |
| 3583 | |
| 3584 | Update = SemaRef.PerformImplicitConversion( |
| 3585 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3586 | if (!Update.isUsable()) |
| 3587 | return ExprError(); |
| 3588 | |
| 3589 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3590 | return Update; |
| 3591 | } |
| 3592 | |
| 3593 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3594 | /// bits. |
| 3595 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3596 | Sema &SemaRef) { |
| 3597 | if (E == nullptr) |
| 3598 | return ExprError(); |
| 3599 | auto &C = SemaRef.Context; |
| 3600 | QualType OldType = E->getType(); |
| 3601 | unsigned HasBits = C.getTypeSize(OldType); |
| 3602 | if (HasBits >= Bits) |
| 3603 | return ExprResult(E); |
| 3604 | // OK to convert to signed, because new type has more bits than old. |
| 3605 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3606 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3607 | true); |
| 3608 | } |
| 3609 | |
| 3610 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3611 | /// into \a Bits bits. |
| 3612 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3613 | if (E == nullptr) |
| 3614 | return false; |
| 3615 | llvm::APSInt Result; |
| 3616 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3617 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3618 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | /// \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] | 3622 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3623 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3624 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3625 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3626 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3627 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3628 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3629 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3630 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3631 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3632 | // Found 'collapse' clause - calculate collapse number. |
| 3633 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3634 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3635 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3636 | } |
| 3637 | if (OrderedLoopCountExpr) { |
| 3638 | // Found 'ordered' clause - calculate collapse number. |
| 3639 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3640 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3641 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3642 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3643 | diag::err_omp_wrong_ordered_loop_count) |
| 3644 | << OrderedLoopCountExpr->getSourceRange(); |
| 3645 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3646 | diag::note_collapse_loop_count) |
| 3647 | << CollapseLoopCountExpr->getSourceRange(); |
| 3648 | } |
| 3649 | NestedLoopCount = Result.getLimitedValue(); |
| 3650 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3651 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3652 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3653 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3654 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3655 | IterSpaces.resize(NestedLoopCount); |
| 3656 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3657 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3658 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3659 | NestedLoopCount, CollapseLoopCountExpr, |
| 3660 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3661 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3662 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3663 | // 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] | 3664 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3665 | // All loops associated with the construct must be perfectly nested; that |
| 3666 | // is, there must be no intervening code nor any OpenMP directive between |
| 3667 | // any two loops. |
| 3668 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3671 | Built.clear(/* size */ NestedLoopCount); |
| 3672 | |
| 3673 | if (SemaRef.CurContext->isDependentContext()) |
| 3674 | return NestedLoopCount; |
| 3675 | |
| 3676 | // An example of what is generated for the following code: |
| 3677 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3678 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3679 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3680 | // for (k = 0; k < NK; ++k) |
| 3681 | // for (j = J0; j < NJ; j+=2) { |
| 3682 | // <loop body> |
| 3683 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3684 | // |
| 3685 | // We generate the code below. |
| 3686 | // Note: the loop body may be outlined in CodeGen. |
| 3687 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3688 | // iterations and operator+= to calculate counter value. |
| 3689 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3690 | // or i64 is currently supported). |
| 3691 | // |
| 3692 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3693 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3694 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3695 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3696 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3697 | // <loop body (using local i and j)> |
| 3698 | // } |
| 3699 | // i = NI; // assign final values of counters |
| 3700 | // j = NJ; |
| 3701 | // |
| 3702 | |
| 3703 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3704 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3705 | // Precondition tests if there is at least one iteration (all conditions are |
| 3706 | // true). |
| 3707 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3708 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3709 | ExprResult LastIteration32 = WidenIterationCount( |
| 3710 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3711 | N0->IgnoreImpCasts(), N0->getType(), |
| 3712 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3713 | .get(), |
| 3714 | SemaRef); |
| 3715 | ExprResult LastIteration64 = WidenIterationCount( |
| 3716 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3717 | N0->IgnoreImpCasts(), N0->getType(), |
| 3718 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3719 | .get(), |
| 3720 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3721 | |
| 3722 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3723 | return NestedLoopCount; |
| 3724 | |
| 3725 | auto &C = SemaRef.Context; |
| 3726 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3727 | |
| 3728 | Scope *CurScope = DSA.getCurScope(); |
| 3729 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3730 | if (PreCond.isUsable()) { |
| 3731 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3732 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3733 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3734 | auto N = IterSpaces[Cnt].NumIterations; |
| 3735 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3736 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3737 | LastIteration32 = SemaRef.BuildBinOp( |
| 3738 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3739 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3740 | Sema::AA_Converting, |
| 3741 | /*AllowExplicit=*/true) |
| 3742 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3743 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3744 | LastIteration64 = SemaRef.BuildBinOp( |
| 3745 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3746 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3747 | Sema::AA_Converting, |
| 3748 | /*AllowExplicit=*/true) |
| 3749 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
| 3752 | // Choose either the 32-bit or 64-bit version. |
| 3753 | ExprResult LastIteration = LastIteration64; |
| 3754 | if (LastIteration32.isUsable() && |
| 3755 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3756 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3757 | FitsInto( |
| 3758 | 32 /* Bits */, |
| 3759 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3760 | LastIteration64.get(), SemaRef))) |
| 3761 | LastIteration = LastIteration32; |
| 3762 | |
| 3763 | if (!LastIteration.isUsable()) |
| 3764 | return 0; |
| 3765 | |
| 3766 | // Save the number of iterations. |
| 3767 | ExprResult NumIterations = LastIteration; |
| 3768 | { |
| 3769 | LastIteration = SemaRef.BuildBinOp( |
| 3770 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3771 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3772 | if (!LastIteration.isUsable()) |
| 3773 | return 0; |
| 3774 | } |
| 3775 | |
| 3776 | // Calculate the last iteration number beforehand instead of doing this on |
| 3777 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3778 | llvm::APSInt Result; |
| 3779 | bool IsConstant = |
| 3780 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3781 | ExprResult CalcLastIteration; |
| 3782 | if (!IsConstant) { |
| 3783 | SourceLocation SaveLoc; |
| 3784 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3785 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3786 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3787 | ExprResult SaveRef = buildDeclRefExpr( |
| 3788 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3789 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3790 | SaveRef.get(), LastIteration.get()); |
| 3791 | LastIteration = SaveRef; |
| 3792 | |
| 3793 | // Prepare SaveRef + 1. |
| 3794 | NumIterations = SemaRef.BuildBinOp( |
| 3795 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3796 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3797 | if (!NumIterations.isUsable()) |
| 3798 | return 0; |
| 3799 | } |
| 3800 | |
| 3801 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3802 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3803 | QualType VType = LastIteration.get()->getType(); |
| 3804 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3805 | ExprResult LB, UB, IL, ST, EUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3806 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3807 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3808 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3809 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3810 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3811 | SemaRef.AddInitializerToDecl( |
| 3812 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3813 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3814 | |
| 3815 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3816 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3817 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3818 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3819 | /*DirectInit*/ false, |
| 3820 | /*TypeMayContainAuto*/ false); |
| 3821 | |
| 3822 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3823 | // This will be used to implement clause 'lastprivate'. |
| 3824 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3825 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3826 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3827 | SemaRef.AddInitializerToDecl( |
| 3828 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3829 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3830 | |
| 3831 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3832 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3833 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3834 | SemaRef.AddInitializerToDecl( |
| 3835 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3836 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3837 | |
| 3838 | // Build expression: UB = min(UB, LastIteration) |
| 3839 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3840 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3841 | UB.get(), LastIteration.get()); |
| 3842 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3843 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3844 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3845 | CondOp.get()); |
| 3846 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3847 | } |
| 3848 | |
| 3849 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3850 | ExprResult IV; |
| 3851 | ExprResult Init; |
| 3852 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3853 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3854 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3855 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3856 | isOpenMPTaskLoopDirective(DKind) || |
| 3857 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3858 | ? LB.get() |
| 3859 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3860 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3861 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3862 | } |
| 3863 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3864 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3865 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3866 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3867 | (isOpenMPWorksharingDirective(DKind) || |
| 3868 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3869 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3870 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3871 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3872 | |
| 3873 | // Loop increment (IV = IV + 1) |
| 3874 | SourceLocation IncLoc; |
| 3875 | ExprResult Inc = |
| 3876 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3877 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3878 | if (!Inc.isUsable()) |
| 3879 | return 0; |
| 3880 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3881 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3882 | if (!Inc.isUsable()) |
| 3883 | return 0; |
| 3884 | |
| 3885 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3886 | // Used for directives with static scheduling. |
| 3887 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3888 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 3889 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3890 | // LB + ST |
| 3891 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3892 | if (!NextLB.isUsable()) |
| 3893 | return 0; |
| 3894 | // LB = LB + ST |
| 3895 | NextLB = |
| 3896 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3897 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3898 | if (!NextLB.isUsable()) |
| 3899 | return 0; |
| 3900 | // UB + ST |
| 3901 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3902 | if (!NextUB.isUsable()) |
| 3903 | return 0; |
| 3904 | // UB = UB + ST |
| 3905 | NextUB = |
| 3906 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3907 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3908 | if (!NextUB.isUsable()) |
| 3909 | return 0; |
| 3910 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3911 | |
| 3912 | // Build updates and final values of the loop counters. |
| 3913 | bool HasErrors = false; |
| 3914 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3915 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3916 | Built.Updates.resize(NestedLoopCount); |
| 3917 | Built.Finals.resize(NestedLoopCount); |
| 3918 | { |
| 3919 | ExprResult Div; |
| 3920 | // Go from inner nested loop to outer. |
| 3921 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3922 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3923 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3924 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3925 | // where Div is product of previous iterations' IS.NumIters. |
| 3926 | ExprResult Iter; |
| 3927 | if (Div.isUsable()) { |
| 3928 | Iter = |
| 3929 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3930 | } else { |
| 3931 | Iter = IV; |
| 3932 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3933 | "unusable div expected on first iteration only"); |
| 3934 | } |
| 3935 | |
| 3936 | if (Cnt != 0 && Iter.isUsable()) |
| 3937 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3938 | IS.NumIterations); |
| 3939 | if (!Iter.isUsable()) { |
| 3940 | HasErrors = true; |
| 3941 | break; |
| 3942 | } |
| 3943 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3944 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3945 | auto *CounterVar = buildDeclRefExpr( |
| 3946 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3947 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3948 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3949 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3950 | IS.CounterInit); |
| 3951 | if (!Init.isUsable()) { |
| 3952 | HasErrors = true; |
| 3953 | break; |
| 3954 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3955 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3956 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3957 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3958 | if (!Update.isUsable()) { |
| 3959 | HasErrors = true; |
| 3960 | break; |
| 3961 | } |
| 3962 | |
| 3963 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3964 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3965 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3966 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3967 | if (!Final.isUsable()) { |
| 3968 | HasErrors = true; |
| 3969 | break; |
| 3970 | } |
| 3971 | |
| 3972 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3973 | if (Cnt != 0) { |
| 3974 | if (Div.isUnset()) |
| 3975 | Div = IS.NumIterations; |
| 3976 | else |
| 3977 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3978 | IS.NumIterations); |
| 3979 | |
| 3980 | // Add parentheses (for debugging purposes only). |
| 3981 | if (Div.isUsable()) |
| 3982 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3983 | if (!Div.isUsable()) { |
| 3984 | HasErrors = true; |
| 3985 | break; |
| 3986 | } |
| 3987 | } |
| 3988 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3989 | HasErrors = true; |
| 3990 | break; |
| 3991 | } |
| 3992 | // Save results |
| 3993 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3994 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3995 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3996 | Built.Updates[Cnt] = Update.get(); |
| 3997 | Built.Finals[Cnt] = Final.get(); |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | if (HasErrors) |
| 4002 | return 0; |
| 4003 | |
| 4004 | // Save results |
| 4005 | Built.IterationVarRef = IV.get(); |
| 4006 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4007 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4008 | Built.CalcLastIteration = |
| 4009 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4010 | Built.PreCond = PreCond.get(); |
| 4011 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4012 | Built.Init = Init.get(); |
| 4013 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4014 | Built.LB = LB.get(); |
| 4015 | Built.UB = UB.get(); |
| 4016 | Built.IL = IL.get(); |
| 4017 | Built.ST = ST.get(); |
| 4018 | Built.EUB = EUB.get(); |
| 4019 | Built.NLB = NextLB.get(); |
| 4020 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4021 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4022 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4023 | } |
| 4024 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4025 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4026 | auto CollapseClauses = |
| 4027 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4028 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4029 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4030 | return nullptr; |
| 4031 | } |
| 4032 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4033 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4034 | auto OrderedClauses = |
| 4035 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4036 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4037 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4038 | return nullptr; |
| 4039 | } |
| 4040 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4041 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 4042 | const Expr *Safelen) { |
| 4043 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4044 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 4045 | Simdlen->isInstantiationDependent() || |
| 4046 | Simdlen->containsUnexpandedParameterPack()) |
| 4047 | return false; |
| 4048 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 4049 | Safelen->isInstantiationDependent() || |
| 4050 | Safelen->containsUnexpandedParameterPack()) |
| 4051 | return false; |
| 4052 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 4053 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 4054 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4055 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4056 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4057 | if (SimdlenRes > SafelenRes) { |
| 4058 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 4059 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 4060 | return true; |
| 4061 | } |
| 4062 | return false; |
| 4063 | } |
| 4064 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4065 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4066 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4067 | SourceLocation EndLoc, |
| 4068 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4069 | if (!AStmt) |
| 4070 | return StmtError(); |
| 4071 | |
| 4072 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4073 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4074 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4075 | // define the nested loops number. |
| 4076 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4077 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4078 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4079 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4080 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4081 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4082 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4083 | "omp simd loop exprs were not built"); |
| 4084 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4085 | if (!CurContext->isDependentContext()) { |
| 4086 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4087 | for (auto C : Clauses) { |
| 4088 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4089 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4090 | B.NumIterations, *this, CurScope)) |
| 4091 | return StmtError(); |
| 4092 | } |
| 4093 | } |
| 4094 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4095 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4096 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4097 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4098 | OMPSafelenClause *Safelen = nullptr; |
| 4099 | OMPSimdlenClause *Simdlen = nullptr; |
| 4100 | for (auto *Clause : Clauses) { |
| 4101 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4102 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4103 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4104 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4105 | if (Safelen && Simdlen) |
| 4106 | break; |
| 4107 | } |
| 4108 | if (Simdlen && Safelen && |
| 4109 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4110 | Safelen->getSafelen())) |
| 4111 | return StmtError(); |
| 4112 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4113 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4114 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4115 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4116 | } |
| 4117 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4118 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4119 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4120 | SourceLocation EndLoc, |
| 4121 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4122 | if (!AStmt) |
| 4123 | return StmtError(); |
| 4124 | |
| 4125 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4126 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4127 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4128 | // define the nested loops number. |
| 4129 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4130 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4131 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4132 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4133 | return StmtError(); |
| 4134 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4135 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4136 | "omp for loop exprs were not built"); |
| 4137 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4138 | if (!CurContext->isDependentContext()) { |
| 4139 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4140 | for (auto C : Clauses) { |
| 4141 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4142 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4143 | B.NumIterations, *this, CurScope)) |
| 4144 | return StmtError(); |
| 4145 | } |
| 4146 | } |
| 4147 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4148 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4149 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4150 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4151 | } |
| 4152 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4153 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4154 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4155 | SourceLocation EndLoc, |
| 4156 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4157 | if (!AStmt) |
| 4158 | return StmtError(); |
| 4159 | |
| 4160 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4161 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4162 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4163 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4164 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4165 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4166 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4167 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4168 | if (NestedLoopCount == 0) |
| 4169 | return StmtError(); |
| 4170 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4171 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4172 | "omp for simd loop exprs were not built"); |
| 4173 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4174 | if (!CurContext->isDependentContext()) { |
| 4175 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4176 | for (auto C : Clauses) { |
| 4177 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4178 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4179 | B.NumIterations, *this, CurScope)) |
| 4180 | return StmtError(); |
| 4181 | } |
| 4182 | } |
| 4183 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4184 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4185 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4186 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4187 | OMPSafelenClause *Safelen = nullptr; |
| 4188 | OMPSimdlenClause *Simdlen = nullptr; |
| 4189 | for (auto *Clause : Clauses) { |
| 4190 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4191 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4192 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4193 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4194 | if (Safelen && Simdlen) |
| 4195 | break; |
| 4196 | } |
| 4197 | if (Simdlen && Safelen && |
| 4198 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4199 | Safelen->getSafelen())) |
| 4200 | return StmtError(); |
| 4201 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4202 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4203 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4204 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4207 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4208 | Stmt *AStmt, |
| 4209 | SourceLocation StartLoc, |
| 4210 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4211 | if (!AStmt) |
| 4212 | return StmtError(); |
| 4213 | |
| 4214 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4215 | auto BaseStmt = AStmt; |
| 4216 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4217 | BaseStmt = CS->getCapturedStmt(); |
| 4218 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4219 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4220 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4221 | return StmtError(); |
| 4222 | // All associated statements must be '#pragma omp section' except for |
| 4223 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4224 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4225 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4226 | if (SectionStmt) |
| 4227 | Diag(SectionStmt->getLocStart(), |
| 4228 | diag::err_omp_sections_substmt_not_section); |
| 4229 | return StmtError(); |
| 4230 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4231 | cast<OMPSectionDirective>(SectionStmt) |
| 4232 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4233 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4234 | } else { |
| 4235 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4236 | return StmtError(); |
| 4237 | } |
| 4238 | |
| 4239 | getCurFunction()->setHasBranchProtectedScope(); |
| 4240 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4241 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4242 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4243 | } |
| 4244 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4245 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4246 | SourceLocation StartLoc, |
| 4247 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4248 | if (!AStmt) |
| 4249 | return StmtError(); |
| 4250 | |
| 4251 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4252 | |
| 4253 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4254 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4255 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4256 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4257 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4260 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4261 | 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 | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4268 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4269 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4270 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4271 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4272 | // The copyprivate clause must not be used with the nowait clause. |
| 4273 | OMPClause *Nowait = nullptr; |
| 4274 | OMPClause *Copyprivate = nullptr; |
| 4275 | for (auto *Clause : Clauses) { |
| 4276 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4277 | Nowait = Clause; |
| 4278 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4279 | Copyprivate = Clause; |
| 4280 | if (Copyprivate && Nowait) { |
| 4281 | Diag(Copyprivate->getLocStart(), |
| 4282 | diag::err_omp_single_copyprivate_with_nowait); |
| 4283 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4284 | return StmtError(); |
| 4285 | } |
| 4286 | } |
| 4287 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4288 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4289 | } |
| 4290 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4291 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4292 | SourceLocation StartLoc, |
| 4293 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4294 | if (!AStmt) |
| 4295 | return StmtError(); |
| 4296 | |
| 4297 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4298 | |
| 4299 | getCurFunction()->setHasBranchProtectedScope(); |
| 4300 | |
| 4301 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4302 | } |
| 4303 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4304 | StmtResult |
| 4305 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 4306 | Stmt *AStmt, SourceLocation StartLoc, |
| 4307 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4308 | if (!AStmt) |
| 4309 | return StmtError(); |
| 4310 | |
| 4311 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4312 | |
| 4313 | getCurFunction()->setHasBranchProtectedScope(); |
| 4314 | |
| 4315 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4316 | AStmt); |
| 4317 | } |
| 4318 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4319 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4320 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4321 | SourceLocation EndLoc, |
| 4322 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4323 | if (!AStmt) |
| 4324 | return StmtError(); |
| 4325 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4326 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4327 | // 1.2.2 OpenMP Language Terminology |
| 4328 | // Structured block - An executable statement with a single entry at the |
| 4329 | // top and a single exit at the bottom. |
| 4330 | // The point of exit cannot be a branch out of the structured block. |
| 4331 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4332 | CS->getCapturedDecl()->setNothrow(); |
| 4333 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4334 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4335 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4336 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4337 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4338 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4339 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4340 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4341 | if (NestedLoopCount == 0) |
| 4342 | return StmtError(); |
| 4343 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4344 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4345 | "omp parallel for loop exprs were not built"); |
| 4346 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4347 | if (!CurContext->isDependentContext()) { |
| 4348 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4349 | for (auto C : Clauses) { |
| 4350 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4351 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4352 | B.NumIterations, *this, CurScope)) |
| 4353 | return StmtError(); |
| 4354 | } |
| 4355 | } |
| 4356 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4357 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4358 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4359 | NestedLoopCount, Clauses, AStmt, B, |
| 4360 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4361 | } |
| 4362 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4363 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4364 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4365 | SourceLocation EndLoc, |
| 4366 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4367 | if (!AStmt) |
| 4368 | return StmtError(); |
| 4369 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4370 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4371 | // 1.2.2 OpenMP Language Terminology |
| 4372 | // Structured block - An executable statement with a single entry at the |
| 4373 | // top and a single exit at the bottom. |
| 4374 | // The point of exit cannot be a branch out of the structured block. |
| 4375 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4376 | CS->getCapturedDecl()->setNothrow(); |
| 4377 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4378 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4379 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4380 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4381 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4382 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4383 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4384 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4385 | if (NestedLoopCount == 0) |
| 4386 | return StmtError(); |
| 4387 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4388 | if (!CurContext->isDependentContext()) { |
| 4389 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4390 | for (auto C : Clauses) { |
| 4391 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4392 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4393 | B.NumIterations, *this, CurScope)) |
| 4394 | return StmtError(); |
| 4395 | } |
| 4396 | } |
| 4397 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4398 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4399 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4400 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4401 | OMPSafelenClause *Safelen = nullptr; |
| 4402 | OMPSimdlenClause *Simdlen = nullptr; |
| 4403 | for (auto *Clause : Clauses) { |
| 4404 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4405 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4406 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4407 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4408 | if (Safelen && Simdlen) |
| 4409 | break; |
| 4410 | } |
| 4411 | if (Simdlen && Safelen && |
| 4412 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4413 | Safelen->getSafelen())) |
| 4414 | return StmtError(); |
| 4415 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4416 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4417 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4418 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4419 | } |
| 4420 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4421 | StmtResult |
| 4422 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4423 | Stmt *AStmt, SourceLocation StartLoc, |
| 4424 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4425 | if (!AStmt) |
| 4426 | return StmtError(); |
| 4427 | |
| 4428 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4429 | auto BaseStmt = AStmt; |
| 4430 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4431 | BaseStmt = CS->getCapturedStmt(); |
| 4432 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4433 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4434 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4435 | return StmtError(); |
| 4436 | // All associated statements must be '#pragma omp section' except for |
| 4437 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4438 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4439 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4440 | if (SectionStmt) |
| 4441 | Diag(SectionStmt->getLocStart(), |
| 4442 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4443 | return StmtError(); |
| 4444 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4445 | cast<OMPSectionDirective>(SectionStmt) |
| 4446 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4447 | } |
| 4448 | } else { |
| 4449 | Diag(AStmt->getLocStart(), |
| 4450 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4451 | return StmtError(); |
| 4452 | } |
| 4453 | |
| 4454 | getCurFunction()->setHasBranchProtectedScope(); |
| 4455 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4456 | return OMPParallelSectionsDirective::Create( |
| 4457 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4458 | } |
| 4459 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4460 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4461 | Stmt *AStmt, SourceLocation StartLoc, |
| 4462 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4463 | if (!AStmt) |
| 4464 | return StmtError(); |
| 4465 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4466 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4467 | // 1.2.2 OpenMP Language Terminology |
| 4468 | // Structured block - An executable statement with a single entry at the |
| 4469 | // top and a single exit at the bottom. |
| 4470 | // The point of exit cannot be a branch out of the structured block. |
| 4471 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4472 | CS->getCapturedDecl()->setNothrow(); |
| 4473 | |
| 4474 | getCurFunction()->setHasBranchProtectedScope(); |
| 4475 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4476 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4477 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4478 | } |
| 4479 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4480 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4481 | SourceLocation EndLoc) { |
| 4482 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4483 | } |
| 4484 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4485 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4486 | SourceLocation EndLoc) { |
| 4487 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4488 | } |
| 4489 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4490 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4491 | SourceLocation EndLoc) { |
| 4492 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4493 | } |
| 4494 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4495 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4496 | SourceLocation StartLoc, |
| 4497 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4498 | if (!AStmt) |
| 4499 | return StmtError(); |
| 4500 | |
| 4501 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4502 | |
| 4503 | getCurFunction()->setHasBranchProtectedScope(); |
| 4504 | |
| 4505 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4506 | } |
| 4507 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4508 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4509 | SourceLocation StartLoc, |
| 4510 | SourceLocation EndLoc) { |
| 4511 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4512 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4513 | } |
| 4514 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4515 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4516 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4517 | SourceLocation StartLoc, |
| 4518 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4519 | if (!AStmt) |
| 4520 | return StmtError(); |
| 4521 | |
| 4522 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4523 | |
| 4524 | getCurFunction()->setHasBranchProtectedScope(); |
| 4525 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4526 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4527 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4528 | for (auto *C: Clauses) { |
| 4529 | if (C->getClauseKind() == OMPC_threads) |
| 4530 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4531 | else if (C->getClauseKind() == OMPC_simd) |
| 4532 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | // TODO: this must happen only if 'threads' clause specified or if no clauses |
| 4536 | // is specified. |
| 4537 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4538 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4539 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) << (TC != nullptr); |
| 4540 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4541 | return StmtError(); |
| 4542 | } |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4543 | if (!SC && isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
| 4544 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4545 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4546 | // that can appear in the simd region. |
| 4547 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 4548 | return StmtError(); |
| 4549 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4550 | |
| 4551 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4552 | } |
| 4553 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4554 | namespace { |
| 4555 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4556 | /// construct. |
| 4557 | class OpenMPAtomicUpdateChecker { |
| 4558 | /// \brief Error results for atomic update expressions. |
| 4559 | enum ExprAnalysisErrorCode { |
| 4560 | /// \brief A statement is not an expression statement. |
| 4561 | NotAnExpression, |
| 4562 | /// \brief Expression is not builtin binary or unary operation. |
| 4563 | NotABinaryOrUnaryExpression, |
| 4564 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4565 | NotAnUnaryIncDecExpression, |
| 4566 | /// \brief An expression is not of scalar type. |
| 4567 | NotAScalarType, |
| 4568 | /// \brief A binary operation is not an assignment operation. |
| 4569 | NotAnAssignmentOp, |
| 4570 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4571 | NotABinaryExpression, |
| 4572 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4573 | /// expression. |
| 4574 | NotABinaryOperator, |
| 4575 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4576 | /// part. |
| 4577 | NotAnUpdateExpression, |
| 4578 | /// \brief No errors is found. |
| 4579 | NoError |
| 4580 | }; |
| 4581 | /// \brief Reference to Sema. |
| 4582 | Sema &SemaRef; |
| 4583 | /// \brief A location for note diagnostics (when error is found). |
| 4584 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4585 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4586 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4587 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4588 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4589 | /// \brief Helper expression of the form |
| 4590 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4591 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4592 | Expr *UpdateExpr; |
| 4593 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4594 | /// important for non-associative operations. |
| 4595 | bool IsXLHSInRHSPart; |
| 4596 | BinaryOperatorKind Op; |
| 4597 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4598 | /// \brief true if the source expression is a postfix unary operation, false |
| 4599 | /// if it is a prefix unary operation. |
| 4600 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4601 | |
| 4602 | public: |
| 4603 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4604 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4605 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4606 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4607 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4608 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4609 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4610 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4611 | /// \param NoteId Diagnostic note for the main error message. |
| 4612 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4613 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4614 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4615 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4616 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4617 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4618 | /// \brief Return the update expression used in calculation of the updated |
| 4619 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4620 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4621 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4622 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4623 | /// false otherwise. |
| 4624 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4625 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4626 | /// \brief true if the source expression is a postfix unary operation, false |
| 4627 | /// if it is a prefix unary operation. |
| 4628 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4629 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4630 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4631 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4632 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4633 | }; |
| 4634 | } // namespace |
| 4635 | |
| 4636 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4637 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4638 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4639 | SourceLocation ErrorLoc, NoteLoc; |
| 4640 | SourceRange ErrorRange, NoteRange; |
| 4641 | // Allowed constructs are: |
| 4642 | // x = x binop expr; |
| 4643 | // x = expr binop x; |
| 4644 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4645 | X = AtomicBinOp->getLHS(); |
| 4646 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4647 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4648 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4649 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4650 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4651 | Op = AtomicInnerBinOp->getOpcode(); |
| 4652 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4653 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4654 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4655 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4656 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4657 | /*Canonical=*/true); |
| 4658 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4659 | /*Canonical=*/true); |
| 4660 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4661 | /*Canonical=*/true); |
| 4662 | if (XId == LHSId) { |
| 4663 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4664 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4665 | } else if (XId == RHSId) { |
| 4666 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4667 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4668 | } else { |
| 4669 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4670 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4671 | NoteLoc = X->getExprLoc(); |
| 4672 | NoteRange = X->getSourceRange(); |
| 4673 | ErrorFound = NotAnUpdateExpression; |
| 4674 | } |
| 4675 | } else { |
| 4676 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4677 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4678 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4679 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4680 | ErrorFound = NotABinaryOperator; |
| 4681 | } |
| 4682 | } else { |
| 4683 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4684 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4685 | ErrorFound = NotABinaryExpression; |
| 4686 | } |
| 4687 | } else { |
| 4688 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4689 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4690 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4691 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4692 | ErrorFound = NotAnAssignmentOp; |
| 4693 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4694 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4695 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4696 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4697 | return true; |
| 4698 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4699 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4700 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4701 | } |
| 4702 | |
| 4703 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4704 | unsigned NoteId) { |
| 4705 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4706 | SourceLocation ErrorLoc, NoteLoc; |
| 4707 | SourceRange ErrorRange, NoteRange; |
| 4708 | // Allowed constructs are: |
| 4709 | // x++; |
| 4710 | // x--; |
| 4711 | // ++x; |
| 4712 | // --x; |
| 4713 | // x binop= expr; |
| 4714 | // x = x binop expr; |
| 4715 | // x = expr binop x; |
| 4716 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4717 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4718 | if (AtomicBody->getType()->isScalarType() || |
| 4719 | AtomicBody->isInstantiationDependent()) { |
| 4720 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4721 | AtomicBody->IgnoreParenImpCasts())) { |
| 4722 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4723 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4724 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4725 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4726 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4727 | X = AtomicCompAssignOp->getLHS(); |
| 4728 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4729 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4730 | AtomicBody->IgnoreParenImpCasts())) { |
| 4731 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4732 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4733 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4734 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4735 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4736 | // Check for Unary Operation |
| 4737 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4738 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4739 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4740 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4741 | X = AtomicUnaryOp->getSubExpr(); |
| 4742 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4743 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4744 | } else { |
| 4745 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4746 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4747 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4748 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4749 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4750 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4751 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4752 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4753 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4754 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4755 | } |
| 4756 | } else { |
| 4757 | ErrorFound = NotAScalarType; |
| 4758 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4759 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4760 | } |
| 4761 | } else { |
| 4762 | ErrorFound = NotAnExpression; |
| 4763 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4764 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4765 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4766 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4767 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4768 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4769 | return true; |
| 4770 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4771 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4772 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4773 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4774 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4775 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4776 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4777 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4778 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4779 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4780 | auto Update = |
| 4781 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4782 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4783 | if (Update.isInvalid()) |
| 4784 | return true; |
| 4785 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4786 | Sema::AA_Casting); |
| 4787 | if (Update.isInvalid()) |
| 4788 | return true; |
| 4789 | UpdateExpr = Update.get(); |
| 4790 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4791 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4792 | } |
| 4793 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4794 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4795 | Stmt *AStmt, |
| 4796 | SourceLocation StartLoc, |
| 4797 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4798 | if (!AStmt) |
| 4799 | return StmtError(); |
| 4800 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4801 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4802 | // 1.2.2 OpenMP Language Terminology |
| 4803 | // Structured block - An executable statement with a single entry at the |
| 4804 | // top and a single exit at the bottom. |
| 4805 | // The point of exit cannot be a branch out of the structured block. |
| 4806 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4807 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4808 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4809 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4810 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4811 | C->getClauseKind() == OMPC_update || |
| 4812 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4813 | if (AtomicKind != OMPC_unknown) { |
| 4814 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4815 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4816 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4817 | << getOpenMPClauseName(AtomicKind); |
| 4818 | } else { |
| 4819 | AtomicKind = C->getClauseKind(); |
| 4820 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4821 | } |
| 4822 | } |
| 4823 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4824 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4825 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4826 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4827 | Body = EWC->getSubExpr(); |
| 4828 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4829 | Expr *X = nullptr; |
| 4830 | Expr *V = nullptr; |
| 4831 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4832 | Expr *UE = nullptr; |
| 4833 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4834 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4835 | // OpenMP [2.12.6, atomic Construct] |
| 4836 | // In the next expressions: |
| 4837 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4838 | // * During the execution of an atomic region, multiple syntactic |
| 4839 | // occurrences of x must designate the same storage location. |
| 4840 | // * Neither of v and expr (as applicable) may access the storage location |
| 4841 | // designated by x. |
| 4842 | // * Neither of x and expr (as applicable) may access the storage location |
| 4843 | // designated by v. |
| 4844 | // * expr is an expression with scalar type. |
| 4845 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4846 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4847 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4848 | // (expr). This requirement is satisfied if the operators in expr have |
| 4849 | // precedence greater than binop, or by using parentheses around expr or |
| 4850 | // subexpressions of expr. |
| 4851 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4852 | // binop x. This requirement is satisfied if the operators in expr have |
| 4853 | // precedence equal to or greater than binop, or by using parentheses around |
| 4854 | // expr or subexpressions of expr. |
| 4855 | // * For forms that allow multiple occurrences of x, the number of times |
| 4856 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4857 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4858 | enum { |
| 4859 | NotAnExpression, |
| 4860 | NotAnAssignmentOp, |
| 4861 | NotAScalarType, |
| 4862 | NotAnLValue, |
| 4863 | NoError |
| 4864 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4865 | SourceLocation ErrorLoc, NoteLoc; |
| 4866 | SourceRange ErrorRange, NoteRange; |
| 4867 | // If clause is read: |
| 4868 | // v = x; |
| 4869 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4870 | auto AtomicBinOp = |
| 4871 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4872 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4873 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4874 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4875 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4876 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4877 | if (!X->isLValue() || !V->isLValue()) { |
| 4878 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4879 | ErrorFound = NotAnLValue; |
| 4880 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4881 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4882 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4883 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4884 | } |
| 4885 | } else if (!X->isInstantiationDependent() || |
| 4886 | !V->isInstantiationDependent()) { |
| 4887 | auto NotScalarExpr = |
| 4888 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4889 | ? V |
| 4890 | : X; |
| 4891 | ErrorFound = NotAScalarType; |
| 4892 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4893 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4894 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4895 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4896 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4897 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4898 | ErrorFound = NotAnAssignmentOp; |
| 4899 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4900 | ErrorRange = AtomicBody->getSourceRange(); |
| 4901 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4902 | : AtomicBody->getExprLoc(); |
| 4903 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4904 | : AtomicBody->getSourceRange(); |
| 4905 | } |
| 4906 | } else { |
| 4907 | ErrorFound = NotAnExpression; |
| 4908 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4909 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4910 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4911 | if (ErrorFound != NoError) { |
| 4912 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4913 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4914 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4915 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4916 | return StmtError(); |
| 4917 | } else if (CurContext->isDependentContext()) |
| 4918 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4919 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4920 | enum { |
| 4921 | NotAnExpression, |
| 4922 | NotAnAssignmentOp, |
| 4923 | NotAScalarType, |
| 4924 | NotAnLValue, |
| 4925 | NoError |
| 4926 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4927 | SourceLocation ErrorLoc, NoteLoc; |
| 4928 | SourceRange ErrorRange, NoteRange; |
| 4929 | // If clause is write: |
| 4930 | // x = expr; |
| 4931 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4932 | auto AtomicBinOp = |
| 4933 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4934 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4935 | X = AtomicBinOp->getLHS(); |
| 4936 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4937 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4938 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4939 | if (!X->isLValue()) { |
| 4940 | ErrorFound = NotAnLValue; |
| 4941 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4942 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4943 | NoteLoc = X->getExprLoc(); |
| 4944 | NoteRange = X->getSourceRange(); |
| 4945 | } |
| 4946 | } else if (!X->isInstantiationDependent() || |
| 4947 | !E->isInstantiationDependent()) { |
| 4948 | auto NotScalarExpr = |
| 4949 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4950 | ? E |
| 4951 | : X; |
| 4952 | ErrorFound = NotAScalarType; |
| 4953 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4954 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4955 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4956 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4957 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4958 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4959 | ErrorFound = NotAnAssignmentOp; |
| 4960 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4961 | ErrorRange = AtomicBody->getSourceRange(); |
| 4962 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4963 | : AtomicBody->getExprLoc(); |
| 4964 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4965 | : AtomicBody->getSourceRange(); |
| 4966 | } |
| 4967 | } else { |
| 4968 | ErrorFound = NotAnExpression; |
| 4969 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4970 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4971 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4972 | if (ErrorFound != NoError) { |
| 4973 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4974 | << ErrorRange; |
| 4975 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4976 | << NoteRange; |
| 4977 | return StmtError(); |
| 4978 | } else if (CurContext->isDependentContext()) |
| 4979 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4980 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4981 | // If clause is update: |
| 4982 | // x++; |
| 4983 | // x--; |
| 4984 | // ++x; |
| 4985 | // --x; |
| 4986 | // x binop= expr; |
| 4987 | // x = x binop expr; |
| 4988 | // x = expr binop x; |
| 4989 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4990 | if (Checker.checkStatement( |
| 4991 | Body, (AtomicKind == OMPC_update) |
| 4992 | ? diag::err_omp_atomic_update_not_expression_statement |
| 4993 | : diag::err_omp_atomic_not_expression_statement, |
| 4994 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4995 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4996 | if (!CurContext->isDependentContext()) { |
| 4997 | E = Checker.getExpr(); |
| 4998 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4999 | UE = Checker.getUpdateExpr(); |
| 5000 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5001 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5002 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5003 | enum { |
| 5004 | NotAnAssignmentOp, |
| 5005 | NotACompoundStatement, |
| 5006 | NotTwoSubstatements, |
| 5007 | NotASpecificExpression, |
| 5008 | NoError |
| 5009 | } ErrorFound = NoError; |
| 5010 | SourceLocation ErrorLoc, NoteLoc; |
| 5011 | SourceRange ErrorRange, NoteRange; |
| 5012 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5013 | // If clause is a capture: |
| 5014 | // v = x++; |
| 5015 | // v = x--; |
| 5016 | // v = ++x; |
| 5017 | // v = --x; |
| 5018 | // v = x binop= expr; |
| 5019 | // v = x = x binop expr; |
| 5020 | // v = x = expr binop x; |
| 5021 | auto *AtomicBinOp = |
| 5022 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5023 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5024 | V = AtomicBinOp->getLHS(); |
| 5025 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5026 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5027 | if (Checker.checkStatement( |
| 5028 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5029 | diag::note_omp_atomic_update)) |
| 5030 | return StmtError(); |
| 5031 | E = Checker.getExpr(); |
| 5032 | X = Checker.getX(); |
| 5033 | UE = Checker.getUpdateExpr(); |
| 5034 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5035 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5036 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5037 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5038 | ErrorRange = AtomicBody->getSourceRange(); |
| 5039 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5040 | : AtomicBody->getExprLoc(); |
| 5041 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5042 | : AtomicBody->getSourceRange(); |
| 5043 | ErrorFound = NotAnAssignmentOp; |
| 5044 | } |
| 5045 | if (ErrorFound != NoError) { |
| 5046 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5047 | << ErrorRange; |
| 5048 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5049 | return StmtError(); |
| 5050 | } else if (CurContext->isDependentContext()) { |
| 5051 | UE = V = E = X = nullptr; |
| 5052 | } |
| 5053 | } else { |
| 5054 | // If clause is a capture: |
| 5055 | // { v = x; x = expr; } |
| 5056 | // { v = x; x++; } |
| 5057 | // { v = x; x--; } |
| 5058 | // { v = x; ++x; } |
| 5059 | // { v = x; --x; } |
| 5060 | // { v = x; x binop= expr; } |
| 5061 | // { v = x; x = x binop expr; } |
| 5062 | // { v = x; x = expr binop x; } |
| 5063 | // { x++; v = x; } |
| 5064 | // { x--; v = x; } |
| 5065 | // { ++x; v = x; } |
| 5066 | // { --x; v = x; } |
| 5067 | // { x binop= expr; v = x; } |
| 5068 | // { x = x binop expr; v = x; } |
| 5069 | // { x = expr binop x; v = x; } |
| 5070 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5071 | // Check that this is { expr1; expr2; } |
| 5072 | if (CS->size() == 2) { |
| 5073 | auto *First = CS->body_front(); |
| 5074 | auto *Second = CS->body_back(); |
| 5075 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5076 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5077 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5078 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5079 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5080 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5081 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5082 | BinaryOperator *BinOp = nullptr; |
| 5083 | if (IsUpdateExprFound) { |
| 5084 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5085 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5086 | } |
| 5087 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5088 | // { v = x; x++; } |
| 5089 | // { v = x; x--; } |
| 5090 | // { v = x; ++x; } |
| 5091 | // { v = x; --x; } |
| 5092 | // { v = x; x binop= expr; } |
| 5093 | // { v = x; x = x binop expr; } |
| 5094 | // { v = x; x = expr binop x; } |
| 5095 | // Check that the first expression has form v = x. |
| 5096 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5097 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5098 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5099 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5100 | IsUpdateExprFound = XId == PossibleXId; |
| 5101 | if (IsUpdateExprFound) { |
| 5102 | V = BinOp->getLHS(); |
| 5103 | X = Checker.getX(); |
| 5104 | E = Checker.getExpr(); |
| 5105 | UE = Checker.getUpdateExpr(); |
| 5106 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5107 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5108 | } |
| 5109 | } |
| 5110 | if (!IsUpdateExprFound) { |
| 5111 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5112 | BinOp = nullptr; |
| 5113 | if (IsUpdateExprFound) { |
| 5114 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5115 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5116 | } |
| 5117 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5118 | // { x++; v = x; } |
| 5119 | // { x--; v = x; } |
| 5120 | // { ++x; v = x; } |
| 5121 | // { --x; v = x; } |
| 5122 | // { x binop= expr; v = x; } |
| 5123 | // { x = x binop expr; v = x; } |
| 5124 | // { x = expr binop x; v = x; } |
| 5125 | // Check that the second expression has form v = x. |
| 5126 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5127 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5128 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5129 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5130 | IsUpdateExprFound = XId == PossibleXId; |
| 5131 | if (IsUpdateExprFound) { |
| 5132 | V = BinOp->getLHS(); |
| 5133 | X = Checker.getX(); |
| 5134 | E = Checker.getExpr(); |
| 5135 | UE = Checker.getUpdateExpr(); |
| 5136 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5137 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5138 | } |
| 5139 | } |
| 5140 | } |
| 5141 | if (!IsUpdateExprFound) { |
| 5142 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5143 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5144 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5145 | if (!FirstExpr || !SecondExpr || |
| 5146 | !(FirstExpr->isInstantiationDependent() || |
| 5147 | SecondExpr->isInstantiationDependent())) { |
| 5148 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5149 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5150 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5151 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5152 | : First->getLocStart(); |
| 5153 | NoteRange = ErrorRange = FirstBinOp |
| 5154 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5155 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5156 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5157 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5158 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5159 | ErrorFound = NotAnAssignmentOp; |
| 5160 | NoteLoc = ErrorLoc = SecondBinOp |
| 5161 | ? SecondBinOp->getOperatorLoc() |
| 5162 | : Second->getLocStart(); |
| 5163 | NoteRange = ErrorRange = |
| 5164 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5165 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5166 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5167 | auto *PossibleXRHSInFirst = |
| 5168 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5169 | auto *PossibleXLHSInSecond = |
| 5170 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5171 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5172 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5173 | /*Canonical=*/true); |
| 5174 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5175 | /*Canonical=*/true); |
| 5176 | IsUpdateExprFound = X1Id == X2Id; |
| 5177 | if (IsUpdateExprFound) { |
| 5178 | V = FirstBinOp->getLHS(); |
| 5179 | X = SecondBinOp->getLHS(); |
| 5180 | E = SecondBinOp->getRHS(); |
| 5181 | UE = nullptr; |
| 5182 | IsXLHSInRHSPart = false; |
| 5183 | IsPostfixUpdate = true; |
| 5184 | } else { |
| 5185 | ErrorFound = NotASpecificExpression; |
| 5186 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5187 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5188 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5189 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5190 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5191 | } |
| 5192 | } |
| 5193 | } |
| 5194 | } |
| 5195 | } else { |
| 5196 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5197 | NoteRange = ErrorRange = |
| 5198 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5199 | ErrorFound = NotTwoSubstatements; |
| 5200 | } |
| 5201 | } else { |
| 5202 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5203 | NoteRange = ErrorRange = |
| 5204 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5205 | ErrorFound = NotACompoundStatement; |
| 5206 | } |
| 5207 | if (ErrorFound != NoError) { |
| 5208 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5209 | << ErrorRange; |
| 5210 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5211 | return StmtError(); |
| 5212 | } else if (CurContext->isDependentContext()) { |
| 5213 | UE = V = E = X = nullptr; |
| 5214 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5215 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5216 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5217 | |
| 5218 | getCurFunction()->setHasBranchProtectedScope(); |
| 5219 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5220 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5221 | X, V, E, UE, IsXLHSInRHSPart, |
| 5222 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5223 | } |
| 5224 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5225 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5226 | Stmt *AStmt, |
| 5227 | SourceLocation StartLoc, |
| 5228 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5229 | if (!AStmt) |
| 5230 | return StmtError(); |
| 5231 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5232 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5233 | // 1.2.2 OpenMP Language Terminology |
| 5234 | // Structured block - An executable statement with a single entry at the |
| 5235 | // top and a single exit at the bottom. |
| 5236 | // The point of exit cannot be a branch out of the structured block. |
| 5237 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5238 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5239 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5240 | // OpenMP [2.16, Nesting of Regions] |
| 5241 | // If specified, a teams construct must be contained within a target |
| 5242 | // construct. That target construct must contain no statements or directives |
| 5243 | // outside of the teams construct. |
| 5244 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5245 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5246 | bool OMPTeamsFound = true; |
| 5247 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5248 | auto I = CS->body_begin(); |
| 5249 | while (I != CS->body_end()) { |
| 5250 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5251 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5252 | OMPTeamsFound = false; |
| 5253 | break; |
| 5254 | } |
| 5255 | ++I; |
| 5256 | } |
| 5257 | assert(I != CS->body_end() && "Not found statement"); |
| 5258 | S = *I; |
| 5259 | } |
| 5260 | if (!OMPTeamsFound) { |
| 5261 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5262 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5263 | diag::note_omp_nested_teams_construct_here); |
| 5264 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5265 | << isa<OMPExecutableDirective>(S); |
| 5266 | return StmtError(); |
| 5267 | } |
| 5268 | } |
| 5269 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5270 | getCurFunction()->setHasBranchProtectedScope(); |
| 5271 | |
| 5272 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5273 | } |
| 5274 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5275 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5276 | Stmt *AStmt, |
| 5277 | SourceLocation StartLoc, |
| 5278 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5279 | if (!AStmt) |
| 5280 | return StmtError(); |
| 5281 | |
| 5282 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5283 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5284 | getCurFunction()->setHasBranchProtectedScope(); |
| 5285 | |
| 5286 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5287 | AStmt); |
| 5288 | } |
| 5289 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5290 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5291 | Stmt *AStmt, SourceLocation StartLoc, |
| 5292 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5293 | if (!AStmt) |
| 5294 | return StmtError(); |
| 5295 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5296 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5297 | // 1.2.2 OpenMP Language Terminology |
| 5298 | // Structured block - An executable statement with a single entry at the |
| 5299 | // top and a single exit at the bottom. |
| 5300 | // The point of exit cannot be a branch out of the structured block. |
| 5301 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5302 | CS->getCapturedDecl()->setNothrow(); |
| 5303 | |
| 5304 | getCurFunction()->setHasBranchProtectedScope(); |
| 5305 | |
| 5306 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5307 | } |
| 5308 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5309 | StmtResult |
| 5310 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5311 | SourceLocation EndLoc, |
| 5312 | OpenMPDirectiveKind CancelRegion) { |
| 5313 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5314 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5315 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5316 | << getOpenMPDirectiveName(CancelRegion); |
| 5317 | return StmtError(); |
| 5318 | } |
| 5319 | if (DSAStack->isParentNowaitRegion()) { |
| 5320 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5321 | return StmtError(); |
| 5322 | } |
| 5323 | if (DSAStack->isParentOrderedRegion()) { |
| 5324 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5325 | return StmtError(); |
| 5326 | } |
| 5327 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5328 | CancelRegion); |
| 5329 | } |
| 5330 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5331 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5332 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5333 | SourceLocation EndLoc, |
| 5334 | OpenMPDirectiveKind CancelRegion) { |
| 5335 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5336 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5337 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5338 | << getOpenMPDirectiveName(CancelRegion); |
| 5339 | return StmtError(); |
| 5340 | } |
| 5341 | if (DSAStack->isParentNowaitRegion()) { |
| 5342 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5343 | return StmtError(); |
| 5344 | } |
| 5345 | if (DSAStack->isParentOrderedRegion()) { |
| 5346 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5347 | return StmtError(); |
| 5348 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5349 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5350 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5351 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5352 | } |
| 5353 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5354 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5355 | ArrayRef<OMPClause *> Clauses) { |
| 5356 | OMPClause *PrevClause = nullptr; |
| 5357 | bool ErrorFound = false; |
| 5358 | for (auto *C : Clauses) { |
| 5359 | if (C->getClauseKind() == OMPC_grainsize || |
| 5360 | C->getClauseKind() == OMPC_num_tasks) { |
| 5361 | if (!PrevClause) |
| 5362 | PrevClause = C; |
| 5363 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5364 | S.Diag(C->getLocStart(), |
| 5365 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5366 | << getOpenMPClauseName(C->getClauseKind()) |
| 5367 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5368 | S.Diag(PrevClause->getLocStart(), |
| 5369 | diag::note_omp_previous_grainsize_num_tasks) |
| 5370 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5371 | ErrorFound = true; |
| 5372 | } |
| 5373 | } |
| 5374 | } |
| 5375 | return ErrorFound; |
| 5376 | } |
| 5377 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5378 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5379 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5380 | SourceLocation EndLoc, |
| 5381 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5382 | if (!AStmt) |
| 5383 | return StmtError(); |
| 5384 | |
| 5385 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5386 | OMPLoopDirective::HelperExprs B; |
| 5387 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5388 | // define the nested loops number. |
| 5389 | unsigned NestedLoopCount = |
| 5390 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5391 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5392 | VarsWithImplicitDSA, B); |
| 5393 | if (NestedLoopCount == 0) |
| 5394 | return StmtError(); |
| 5395 | |
| 5396 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5397 | "omp for loop exprs were not built"); |
| 5398 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5399 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5400 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5401 | // not appear on the same taskloop directive. |
| 5402 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5403 | return StmtError(); |
| 5404 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5405 | getCurFunction()->setHasBranchProtectedScope(); |
| 5406 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5407 | NestedLoopCount, Clauses, AStmt, B); |
| 5408 | } |
| 5409 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5410 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5411 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5412 | SourceLocation EndLoc, |
| 5413 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5414 | if (!AStmt) |
| 5415 | return StmtError(); |
| 5416 | |
| 5417 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5418 | OMPLoopDirective::HelperExprs B; |
| 5419 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5420 | // define the nested loops number. |
| 5421 | unsigned NestedLoopCount = |
| 5422 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5423 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5424 | VarsWithImplicitDSA, B); |
| 5425 | if (NestedLoopCount == 0) |
| 5426 | return StmtError(); |
| 5427 | |
| 5428 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5429 | "omp for loop exprs were not built"); |
| 5430 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5431 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5432 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5433 | // not appear on the same taskloop directive. |
| 5434 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5435 | return StmtError(); |
| 5436 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5437 | getCurFunction()->setHasBranchProtectedScope(); |
| 5438 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5439 | NestedLoopCount, Clauses, AStmt, B); |
| 5440 | } |
| 5441 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5442 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5443 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5444 | SourceLocation EndLoc, |
| 5445 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5446 | if (!AStmt) |
| 5447 | return StmtError(); |
| 5448 | |
| 5449 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5450 | OMPLoopDirective::HelperExprs B; |
| 5451 | // In presence of clause 'collapse' with number of loops, it will |
| 5452 | // define the nested loops number. |
| 5453 | unsigned NestedLoopCount = |
| 5454 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5455 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5456 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5457 | if (NestedLoopCount == 0) |
| 5458 | return StmtError(); |
| 5459 | |
| 5460 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5461 | "omp for loop exprs were not built"); |
| 5462 | |
| 5463 | getCurFunction()->setHasBranchProtectedScope(); |
| 5464 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5465 | NestedLoopCount, Clauses, AStmt, B); |
| 5466 | } |
| 5467 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5468 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5469 | SourceLocation StartLoc, |
| 5470 | SourceLocation LParenLoc, |
| 5471 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5472 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5473 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5474 | case OMPC_final: |
| 5475 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5476 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5477 | case OMPC_num_threads: |
| 5478 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5479 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5480 | case OMPC_safelen: |
| 5481 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5482 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5483 | case OMPC_simdlen: |
| 5484 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5485 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5486 | case OMPC_collapse: |
| 5487 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5488 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5489 | case OMPC_ordered: |
| 5490 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5491 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5492 | case OMPC_device: |
| 5493 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5494 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5495 | case OMPC_num_teams: |
| 5496 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5497 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5498 | case OMPC_thread_limit: |
| 5499 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5500 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5501 | case OMPC_priority: |
| 5502 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5503 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5504 | case OMPC_grainsize: |
| 5505 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5506 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5507 | case OMPC_num_tasks: |
| 5508 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5509 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5510 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5511 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5512 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5513 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5514 | case OMPC_private: |
| 5515 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5516 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5517 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5518 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5519 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5520 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5521 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5522 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5523 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5524 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5525 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5526 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5527 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5528 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5529 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5530 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5531 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5532 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5533 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5534 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5535 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5536 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5537 | case OMPC_nogroup: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5538 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5539 | llvm_unreachable("Clause is not allowed."); |
| 5540 | } |
| 5541 | return Res; |
| 5542 | } |
| 5543 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5544 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5545 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5546 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5547 | SourceLocation NameModifierLoc, |
| 5548 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5549 | SourceLocation EndLoc) { |
| 5550 | Expr *ValExpr = Condition; |
| 5551 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5552 | !Condition->isInstantiationDependent() && |
| 5553 | !Condition->containsUnexpandedParameterPack()) { |
| 5554 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5555 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5556 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5557 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5558 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5559 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5562 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5563 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5564 | } |
| 5565 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5566 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5567 | SourceLocation StartLoc, |
| 5568 | SourceLocation LParenLoc, |
| 5569 | SourceLocation EndLoc) { |
| 5570 | Expr *ValExpr = Condition; |
| 5571 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5572 | !Condition->isInstantiationDependent() && |
| 5573 | !Condition->containsUnexpandedParameterPack()) { |
| 5574 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5575 | Condition->getExprLoc(), Condition); |
| 5576 | if (Val.isInvalid()) |
| 5577 | return nullptr; |
| 5578 | |
| 5579 | ValExpr = Val.get(); |
| 5580 | } |
| 5581 | |
| 5582 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5583 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5584 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5585 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5586 | if (!Op) |
| 5587 | return ExprError(); |
| 5588 | |
| 5589 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5590 | public: |
| 5591 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5592 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5593 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5594 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5595 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5596 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5597 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5598 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5599 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5600 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5601 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5602 | QualType T, |
| 5603 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5604 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5605 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5606 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5607 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5608 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5609 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5610 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5611 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5612 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5613 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5614 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5615 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5616 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5617 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5618 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5619 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5620 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5621 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5622 | llvm_unreachable("conversion functions are permitted"); |
| 5623 | } |
| 5624 | } ConvertDiagnoser; |
| 5625 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5626 | } |
| 5627 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5628 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5629 | OpenMPClauseKind CKind, |
| 5630 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5631 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 5632 | !ValExpr->isInstantiationDependent()) { |
| 5633 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 5634 | ExprResult Value = |
| 5635 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 5636 | if (Value.isInvalid()) |
| 5637 | return false; |
| 5638 | |
| 5639 | ValExpr = Value.get(); |
| 5640 | // The expression must evaluate to a non-negative integer value. |
| 5641 | llvm::APSInt Result; |
| 5642 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5643 | Result.isSigned() && |
| 5644 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 5645 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5646 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5647 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5648 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5649 | return false; |
| 5650 | } |
| 5651 | } |
| 5652 | return true; |
| 5653 | } |
| 5654 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5655 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5656 | SourceLocation StartLoc, |
| 5657 | SourceLocation LParenLoc, |
| 5658 | SourceLocation EndLoc) { |
| 5659 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5660 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5661 | // OpenMP [2.5, Restrictions] |
| 5662 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5663 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 5664 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5665 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5666 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5667 | return new (Context) |
| 5668 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5671 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 5672 | OpenMPClauseKind CKind) { |
| 5673 | if (!E) |
| 5674 | return ExprError(); |
| 5675 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5676 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5677 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5678 | llvm::APSInt Result; |
| 5679 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5680 | if (ICE.isInvalid()) |
| 5681 | return ExprError(); |
| 5682 | if (!Result.isStrictlyPositive()) { |
| 5683 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5684 | << getOpenMPClauseName(CKind) << 1 << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5685 | return ExprError(); |
| 5686 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5687 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5688 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5689 | << E->getSourceRange(); |
| 5690 | return ExprError(); |
| 5691 | } |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5692 | if (CKind == OMPC_collapse) |
| 5693 | DSAStack->setCollapseNumber(Result.getExtValue()); |
| 5694 | else if (CKind == OMPC_ordered) |
| 5695 | DSAStack->setCollapseNumber(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5696 | return ICE; |
| 5697 | } |
| 5698 | |
| 5699 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5700 | SourceLocation LParenLoc, |
| 5701 | SourceLocation EndLoc) { |
| 5702 | // OpenMP [2.8.1, simd construct, Description] |
| 5703 | // The parameter of the safelen clause must be a constant |
| 5704 | // positive integer expression. |
| 5705 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5706 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5707 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5708 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5709 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5710 | } |
| 5711 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5712 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5713 | SourceLocation LParenLoc, |
| 5714 | SourceLocation EndLoc) { |
| 5715 | // OpenMP [2.8.1, simd construct, Description] |
| 5716 | // The parameter of the simdlen clause must be a constant |
| 5717 | // positive integer expression. |
| 5718 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5719 | if (Simdlen.isInvalid()) |
| 5720 | return nullptr; |
| 5721 | return new (Context) |
| 5722 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5723 | } |
| 5724 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5725 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5726 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5727 | SourceLocation LParenLoc, |
| 5728 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5729 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5730 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5731 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5732 | // The parameter of the collapse clause must be a constant |
| 5733 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5734 | ExprResult NumForLoopsResult = |
| 5735 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5736 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5737 | return nullptr; |
| 5738 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5739 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5740 | } |
| 5741 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5742 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5743 | SourceLocation EndLoc, |
| 5744 | SourceLocation LParenLoc, |
| 5745 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5746 | // OpenMP [2.7.1, loop construct, Description] |
| 5747 | // OpenMP [2.8.1, simd construct, Description] |
| 5748 | // OpenMP [2.9.6, distribute construct, Description] |
| 5749 | // The parameter of the ordered clause must be a constant |
| 5750 | // positive integer expression if any. |
| 5751 | if (NumForLoops && LParenLoc.isValid()) { |
| 5752 | ExprResult NumForLoopsResult = |
| 5753 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5754 | if (NumForLoopsResult.isInvalid()) |
| 5755 | return nullptr; |
| 5756 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5757 | } else |
| 5758 | NumForLoops = nullptr; |
| 5759 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5760 | return new (Context) |
| 5761 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5762 | } |
| 5763 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5764 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5765 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5766 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5767 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5768 | switch (Kind) { |
| 5769 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5770 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5771 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5772 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5773 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5774 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5775 | Res = ActOnOpenMPProcBindClause( |
| 5776 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5777 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5778 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5779 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5780 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5781 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5782 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5783 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5784 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5785 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5786 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5787 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5788 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5789 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5790 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5791 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5792 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5793 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5794 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5795 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5796 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5797 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5798 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5799 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5800 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5801 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5802 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5803 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5804 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5805 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5806 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5807 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5808 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5809 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5810 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5811 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5812 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5813 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5814 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5815 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5816 | case OMPC_num_tasks: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5817 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5818 | llvm_unreachable("Clause is not allowed."); |
| 5819 | } |
| 5820 | return Res; |
| 5821 | } |
| 5822 | |
| 5823 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 5824 | SourceLocation KindKwLoc, |
| 5825 | SourceLocation StartLoc, |
| 5826 | SourceLocation LParenLoc, |
| 5827 | SourceLocation EndLoc) { |
| 5828 | if (Kind == OMPC_DEFAULT_unknown) { |
| 5829 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5830 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 5831 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 5832 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5833 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5834 | Values += "'"; |
| 5835 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 5836 | Values += "'"; |
| 5837 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5838 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5839 | Values += " or "; |
| 5840 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5841 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5842 | break; |
| 5843 | default: |
| 5844 | Values += Sep; |
| 5845 | break; |
| 5846 | } |
| 5847 | } |
| 5848 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5849 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5850 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5851 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5852 | switch (Kind) { |
| 5853 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5854 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5855 | break; |
| 5856 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5857 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5858 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5859 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5860 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5861 | break; |
| 5862 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5863 | return new (Context) |
| 5864 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5865 | } |
| 5866 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5867 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5868 | SourceLocation KindKwLoc, |
| 5869 | SourceLocation StartLoc, |
| 5870 | SourceLocation LParenLoc, |
| 5871 | SourceLocation EndLoc) { |
| 5872 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5873 | std::string Values; |
| 5874 | std::string Sep(", "); |
| 5875 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 5876 | Values += "'"; |
| 5877 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 5878 | Values += "'"; |
| 5879 | switch (i) { |
| 5880 | case OMPC_PROC_BIND_unknown - 2: |
| 5881 | Values += " or "; |
| 5882 | break; |
| 5883 | case OMPC_PROC_BIND_unknown - 1: |
| 5884 | break; |
| 5885 | default: |
| 5886 | Values += Sep; |
| 5887 | break; |
| 5888 | } |
| 5889 | } |
| 5890 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5891 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5892 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5893 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5894 | return new (Context) |
| 5895 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5896 | } |
| 5897 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5898 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 5899 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 5900 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5901 | SourceLocation ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5902 | SourceLocation EndLoc) { |
| 5903 | OMPClause *Res = nullptr; |
| 5904 | switch (Kind) { |
| 5905 | case OMPC_schedule: |
| 5906 | Res = ActOnOpenMPScheduleClause( |
| 5907 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5908 | LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5909 | break; |
| 5910 | case OMPC_if: |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5911 | Res = |
| 5912 | ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr, |
| 5913 | StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
| 5914 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5915 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5916 | case OMPC_num_threads: |
| 5917 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5918 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5919 | case OMPC_collapse: |
| 5920 | case OMPC_default: |
| 5921 | case OMPC_proc_bind: |
| 5922 | case OMPC_private: |
| 5923 | case OMPC_firstprivate: |
| 5924 | case OMPC_lastprivate: |
| 5925 | case OMPC_shared: |
| 5926 | case OMPC_reduction: |
| 5927 | case OMPC_linear: |
| 5928 | case OMPC_aligned: |
| 5929 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5930 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5931 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5932 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5933 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5934 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5935 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5936 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5937 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5938 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5939 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5940 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5941 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5942 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5943 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5944 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5945 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5946 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5947 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5948 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5949 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 5950 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 5951 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5952 | case OMPC_num_tasks: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5953 | case OMPC_unknown: |
| 5954 | llvm_unreachable("Clause is not allowed."); |
| 5955 | } |
| 5956 | return Res; |
| 5957 | } |
| 5958 | |
| 5959 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 5960 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 5961 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 5962 | SourceLocation EndLoc) { |
| 5963 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 5964 | std::string Values; |
| 5965 | std::string Sep(", "); |
| 5966 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 5967 | Values += "'"; |
| 5968 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 5969 | Values += "'"; |
| 5970 | switch (i) { |
| 5971 | case OMPC_SCHEDULE_unknown - 2: |
| 5972 | Values += " or "; |
| 5973 | break; |
| 5974 | case OMPC_SCHEDULE_unknown - 1: |
| 5975 | break; |
| 5976 | default: |
| 5977 | Values += Sep; |
| 5978 | break; |
| 5979 | } |
| 5980 | } |
| 5981 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 5982 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 5983 | return nullptr; |
| 5984 | } |
| 5985 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5986 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5987 | if (ChunkSize) { |
| 5988 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 5989 | !ChunkSize->isInstantiationDependent() && |
| 5990 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 5991 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 5992 | ExprResult Val = |
| 5993 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 5994 | if (Val.isInvalid()) |
| 5995 | return nullptr; |
| 5996 | |
| 5997 | ValExpr = Val.get(); |
| 5998 | |
| 5999 | // OpenMP [2.7.1, Restrictions] |
| 6000 | // chunk_size must be a loop invariant integer expression with a positive |
| 6001 | // value. |
| 6002 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6003 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 6004 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6005 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6006 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6007 | return nullptr; |
| 6008 | } |
| 6009 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 6010 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 6011 | ChunkSize->getType(), ".chunk."); |
| 6012 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 6013 | ChunkSize->getExprLoc(), |
| 6014 | /*RefersToCapture=*/true); |
| 6015 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6016 | } |
| 6017 | } |
| 6018 | } |
| 6019 | |
| 6020 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 6021 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6022 | } |
| 6023 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6024 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 6025 | SourceLocation StartLoc, |
| 6026 | SourceLocation EndLoc) { |
| 6027 | OMPClause *Res = nullptr; |
| 6028 | switch (Kind) { |
| 6029 | case OMPC_ordered: |
| 6030 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 6031 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6032 | case OMPC_nowait: |
| 6033 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 6034 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6035 | case OMPC_untied: |
| 6036 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 6037 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6038 | case OMPC_mergeable: |
| 6039 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 6040 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6041 | case OMPC_read: |
| 6042 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 6043 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6044 | case OMPC_write: |
| 6045 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 6046 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6047 | case OMPC_update: |
| 6048 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 6049 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6050 | case OMPC_capture: |
| 6051 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 6052 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6053 | case OMPC_seq_cst: |
| 6054 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 6055 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6056 | case OMPC_threads: |
| 6057 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 6058 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6059 | case OMPC_simd: |
| 6060 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 6061 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6062 | case OMPC_nogroup: |
| 6063 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 6064 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6065 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6066 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6067 | case OMPC_num_threads: |
| 6068 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6069 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6070 | case OMPC_collapse: |
| 6071 | case OMPC_schedule: |
| 6072 | case OMPC_private: |
| 6073 | case OMPC_firstprivate: |
| 6074 | case OMPC_lastprivate: |
| 6075 | case OMPC_shared: |
| 6076 | case OMPC_reduction: |
| 6077 | case OMPC_linear: |
| 6078 | case OMPC_aligned: |
| 6079 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6080 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6081 | case OMPC_default: |
| 6082 | case OMPC_proc_bind: |
| 6083 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6084 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6085 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6086 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6087 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6088 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6089 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6090 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6091 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6092 | case OMPC_num_tasks: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6093 | case OMPC_unknown: |
| 6094 | llvm_unreachable("Clause is not allowed."); |
| 6095 | } |
| 6096 | return Res; |
| 6097 | } |
| 6098 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6099 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 6100 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6101 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6102 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 6103 | } |
| 6104 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6105 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 6106 | SourceLocation EndLoc) { |
| 6107 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 6108 | } |
| 6109 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6110 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 6111 | SourceLocation EndLoc) { |
| 6112 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 6113 | } |
| 6114 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6115 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 6116 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6117 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 6118 | } |
| 6119 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6120 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 6121 | SourceLocation EndLoc) { |
| 6122 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 6123 | } |
| 6124 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6125 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 6126 | SourceLocation EndLoc) { |
| 6127 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 6128 | } |
| 6129 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6130 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 6131 | SourceLocation EndLoc) { |
| 6132 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 6133 | } |
| 6134 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6135 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 6136 | SourceLocation EndLoc) { |
| 6137 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 6138 | } |
| 6139 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6140 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 6141 | SourceLocation EndLoc) { |
| 6142 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 6143 | } |
| 6144 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6145 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 6146 | SourceLocation EndLoc) { |
| 6147 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 6148 | } |
| 6149 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6150 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 6151 | SourceLocation EndLoc) { |
| 6152 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 6153 | } |
| 6154 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6155 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 6156 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 6157 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 6158 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6159 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6160 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 6161 | OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6162 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6163 | switch (Kind) { |
| 6164 | case OMPC_private: |
| 6165 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6166 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6167 | case OMPC_firstprivate: |
| 6168 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6169 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6170 | case OMPC_lastprivate: |
| 6171 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6172 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6173 | case OMPC_shared: |
| 6174 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6175 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6176 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6177 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 6178 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6179 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6180 | case OMPC_linear: |
| 6181 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6182 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6183 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6184 | case OMPC_aligned: |
| 6185 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 6186 | ColonLoc, EndLoc); |
| 6187 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6188 | case OMPC_copyin: |
| 6189 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6190 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6191 | case OMPC_copyprivate: |
| 6192 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6193 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6194 | case OMPC_flush: |
| 6195 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 6196 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6197 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6198 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 6199 | StartLoc, LParenLoc, EndLoc); |
| 6200 | break; |
| 6201 | case OMPC_map: |
| 6202 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, DepLinMapLoc, ColonLoc, |
| 6203 | VarList, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6204 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6205 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6206 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6207 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6208 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6209 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6210 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6211 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6212 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6213 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6214 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6215 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6216 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6217 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6218 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6219 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6220 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6221 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6222 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6223 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6224 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6225 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6226 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6227 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6228 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6229 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6230 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6231 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6232 | case OMPC_num_tasks: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6233 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6234 | llvm_unreachable("Clause is not allowed."); |
| 6235 | } |
| 6236 | return Res; |
| 6237 | } |
| 6238 | |
| 6239 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6240 | SourceLocation StartLoc, |
| 6241 | SourceLocation LParenLoc, |
| 6242 | SourceLocation EndLoc) { |
| 6243 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6244 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6245 | for (auto &RefExpr : VarList) { |
| 6246 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 6247 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6248 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6249 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6250 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6251 | continue; |
| 6252 | } |
| 6253 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6254 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6255 | // OpenMP [2.1, C/C++] |
| 6256 | // A list item is a variable name. |
| 6257 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6258 | // A variable that is part of another variable (as an array or |
| 6259 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6260 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6261 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6262 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6263 | continue; |
| 6264 | } |
| 6265 | Decl *D = DE->getDecl(); |
| 6266 | VarDecl *VD = cast<VarDecl>(D); |
| 6267 | |
| 6268 | QualType Type = VD->getType(); |
| 6269 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6270 | // It will be analyzed later. |
| 6271 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6272 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6273 | continue; |
| 6274 | } |
| 6275 | |
| 6276 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6277 | // A variable that appears in a private clause must not have an incomplete |
| 6278 | // type or a reference type. |
| 6279 | if (RequireCompleteType(ELoc, Type, |
| 6280 | diag::err_omp_private_incomplete_type)) { |
| 6281 | continue; |
| 6282 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6283 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6284 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6285 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6286 | // in a Construct] |
| 6287 | // Variables with the predetermined data-sharing attributes may not be |
| 6288 | // listed in data-sharing attributes clauses, except for the cases |
| 6289 | // listed below. For these exceptions only, listing a predetermined |
| 6290 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6291 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6292 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6293 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6294 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6295 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6296 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6297 | continue; |
| 6298 | } |
| 6299 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6300 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6301 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6302 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6303 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6304 | << getOpenMPClauseName(OMPC_private) << Type |
| 6305 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6306 | bool IsDecl = |
| 6307 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6308 | Diag(VD->getLocation(), |
| 6309 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6310 | << VD; |
| 6311 | continue; |
| 6312 | } |
| 6313 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6314 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6315 | // A variable of class type (or array thereof) that appears in a private |
| 6316 | // clause requires an accessible, unambiguous default constructor for the |
| 6317 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6318 | // Generate helper private variable and initialize it with the default |
| 6319 | // value. The address of the original variable is replaced by the address of |
| 6320 | // the new private variable in CodeGen. This new variable is not added to |
| 6321 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6322 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6323 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6324 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 6325 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6326 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6327 | if (VDPrivate->isInvalidDecl()) |
| 6328 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6329 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6330 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6331 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6332 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6333 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6334 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6335 | } |
| 6336 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6337 | if (Vars.empty()) |
| 6338 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6339 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6340 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6341 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6342 | } |
| 6343 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6344 | namespace { |
| 6345 | class DiagsUninitializedSeveretyRAII { |
| 6346 | private: |
| 6347 | DiagnosticsEngine &Diags; |
| 6348 | SourceLocation SavedLoc; |
| 6349 | bool IsIgnored; |
| 6350 | |
| 6351 | public: |
| 6352 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6353 | bool IsIgnored) |
| 6354 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6355 | if (!IsIgnored) { |
| 6356 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6357 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6358 | } |
| 6359 | } |
| 6360 | ~DiagsUninitializedSeveretyRAII() { |
| 6361 | if (!IsIgnored) |
| 6362 | Diags.popMappings(SavedLoc); |
| 6363 | } |
| 6364 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6365 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6366 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6367 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6368 | SourceLocation StartLoc, |
| 6369 | SourceLocation LParenLoc, |
| 6370 | SourceLocation EndLoc) { |
| 6371 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6372 | SmallVector<Expr *, 8> PrivateCopies; |
| 6373 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6374 | bool IsImplicitClause = |
| 6375 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6376 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6377 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6378 | for (auto &RefExpr : VarList) { |
| 6379 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6380 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6381 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6382 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6383 | PrivateCopies.push_back(nullptr); |
| 6384 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6385 | continue; |
| 6386 | } |
| 6387 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6388 | SourceLocation ELoc = |
| 6389 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6390 | // OpenMP [2.1, C/C++] |
| 6391 | // A list item is a variable name. |
| 6392 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6393 | // A variable that is part of another variable (as an array or |
| 6394 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6395 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6396 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6397 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6398 | continue; |
| 6399 | } |
| 6400 | Decl *D = DE->getDecl(); |
| 6401 | VarDecl *VD = cast<VarDecl>(D); |
| 6402 | |
| 6403 | QualType Type = VD->getType(); |
| 6404 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6405 | // It will be analyzed later. |
| 6406 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6407 | PrivateCopies.push_back(nullptr); |
| 6408 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6409 | continue; |
| 6410 | } |
| 6411 | |
| 6412 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6413 | // A variable that appears in a private clause must not have an incomplete |
| 6414 | // type or a reference type. |
| 6415 | if (RequireCompleteType(ELoc, Type, |
| 6416 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6417 | continue; |
| 6418 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6419 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6420 | |
| 6421 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6422 | // 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] | 6423 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6424 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6425 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6426 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6427 | // If an implicit firstprivate variable found it was checked already. |
| 6428 | if (!IsImplicitClause) { |
| 6429 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6430 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6431 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6432 | // A list item that specifies a given variable may not appear in more |
| 6433 | // than one clause on the same directive, except that a variable may be |
| 6434 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6435 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6436 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6437 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6438 | << getOpenMPClauseName(DVar.CKind) |
| 6439 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6440 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6441 | continue; |
| 6442 | } |
| 6443 | |
| 6444 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6445 | // in a Construct] |
| 6446 | // Variables with the predetermined data-sharing attributes may not be |
| 6447 | // listed in data-sharing attributes clauses, except for the cases |
| 6448 | // listed below. For these exceptions only, listing a predetermined |
| 6449 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6450 | // the variable's predetermined data-sharing attributes. |
| 6451 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6452 | // in a Construct, C/C++, p.2] |
| 6453 | // Variables with const-qualified type having no mutable member may be |
| 6454 | // listed in a firstprivate clause, even if they are static data members. |
| 6455 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6456 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6457 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6458 | << getOpenMPClauseName(DVar.CKind) |
| 6459 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6460 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6461 | continue; |
| 6462 | } |
| 6463 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6464 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6465 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6466 | // A list item that is private within a parallel region must not appear |
| 6467 | // in a firstprivate clause on a worksharing construct if any of the |
| 6468 | // worksharing regions arising from the worksharing construct ever bind |
| 6469 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6470 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6471 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6472 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6473 | if (DVar.CKind != OMPC_shared && |
| 6474 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6475 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6476 | Diag(ELoc, diag::err_omp_required_access) |
| 6477 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6478 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6479 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6480 | continue; |
| 6481 | } |
| 6482 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6483 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6484 | // A list item that appears in a reduction clause of a parallel construct |
| 6485 | // must not appear in a firstprivate clause on a worksharing or task |
| 6486 | // construct if any of the worksharing or task regions arising from the |
| 6487 | // worksharing or task construct ever bind to any of the parallel regions |
| 6488 | // arising from the parallel construct. |
| 6489 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6490 | // A list item that appears in a reduction clause in worksharing |
| 6491 | // construct must not appear in a firstprivate clause in a task construct |
| 6492 | // encountered during execution of any of the worksharing regions arising |
| 6493 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6494 | if (CurrDir == OMPD_task) { |
| 6495 | DVar = |
| 6496 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6497 | [](OpenMPDirectiveKind K) -> bool { |
| 6498 | return isOpenMPParallelDirective(K) || |
| 6499 | isOpenMPWorksharingDirective(K); |
| 6500 | }, |
| 6501 | false); |
| 6502 | if (DVar.CKind == OMPC_reduction && |
| 6503 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6504 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6505 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6506 | << getOpenMPDirectiveName(DVar.DKind); |
| 6507 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6508 | continue; |
| 6509 | } |
| 6510 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6511 | |
| 6512 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6513 | // A list item that is private within a teams region must not appear in a |
| 6514 | // firstprivate clause on a distribute construct if any of the distribute |
| 6515 | // regions arising from the distribute construct ever bind to any of the |
| 6516 | // teams regions arising from the teams construct. |
| 6517 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 6518 | // A list item that appears in a reduction clause of a teams construct |
| 6519 | // must not appear in a firstprivate clause on a distribute construct if |
| 6520 | // any of the distribute regions arising from the distribute construct |
| 6521 | // ever bind to any of the teams regions arising from the teams construct. |
| 6522 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6523 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6524 | // both. |
| 6525 | if (CurrDir == OMPD_distribute) { |
| 6526 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_private), |
| 6527 | [](OpenMPDirectiveKind K) -> bool { |
| 6528 | return isOpenMPTeamsDirective(K); |
| 6529 | }, |
| 6530 | false); |
| 6531 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 6532 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
| 6533 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6534 | continue; |
| 6535 | } |
| 6536 | DVar = DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6537 | [](OpenMPDirectiveKind K) -> bool { |
| 6538 | return isOpenMPTeamsDirective(K); |
| 6539 | }, |
| 6540 | false); |
| 6541 | if (DVar.CKind == OMPC_reduction && |
| 6542 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 6543 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
| 6544 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6545 | continue; |
| 6546 | } |
| 6547 | DVar = DSAStack->getTopDSA(VD, false); |
| 6548 | if (DVar.CKind == OMPC_lastprivate) { |
| 6549 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6550 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6551 | continue; |
| 6552 | } |
| 6553 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6554 | } |
| 6555 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6556 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6557 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6558 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6559 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6560 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6561 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6562 | bool IsDecl = |
| 6563 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6564 | Diag(VD->getLocation(), |
| 6565 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6566 | << VD; |
| 6567 | continue; |
| 6568 | } |
| 6569 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6570 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6571 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6572 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6573 | // Generate helper private variable and initialize it with the value of the |
| 6574 | // original variable. The address of the original variable is replaced by |
| 6575 | // the address of the new private variable in the CodeGen. This new variable |
| 6576 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 6577 | // original variable for proper diagnostics and variable capturing. |
| 6578 | Expr *VDInitRefExpr = nullptr; |
| 6579 | // For arrays generate initializer for single element and replace it by the |
| 6580 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6581 | if (Type->isArrayType()) { |
| 6582 | auto VDInit = |
| 6583 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 6584 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6585 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6586 | ElemType = ElemType.getUnqualifiedType(); |
| 6587 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 6588 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6589 | InitializedEntity Entity = |
| 6590 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6591 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 6592 | |
| 6593 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 6594 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 6595 | if (Result.isInvalid()) |
| 6596 | VDPrivate->setInvalidDecl(); |
| 6597 | else |
| 6598 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6599 | // Remove temp variable declaration. |
| 6600 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6601 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6602 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6603 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6604 | VDInitRefExpr = |
| 6605 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6606 | AddInitializerToDecl(VDPrivate, |
| 6607 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 6608 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6609 | } |
| 6610 | if (VDPrivate->isInvalidDecl()) { |
| 6611 | if (IsImplicitClause) { |
| 6612 | Diag(DE->getExprLoc(), |
| 6613 | diag::note_omp_task_predetermined_firstprivate_here); |
| 6614 | } |
| 6615 | continue; |
| 6616 | } |
| 6617 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6618 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6619 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6620 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 6621 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6622 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 6623 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6624 | } |
| 6625 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6626 | if (Vars.empty()) |
| 6627 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6628 | |
| 6629 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6630 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6631 | } |
| 6632 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6633 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6634 | SourceLocation StartLoc, |
| 6635 | SourceLocation LParenLoc, |
| 6636 | SourceLocation EndLoc) { |
| 6637 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6638 | SmallVector<Expr *, 8> SrcExprs; |
| 6639 | SmallVector<Expr *, 8> DstExprs; |
| 6640 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6641 | for (auto &RefExpr : VarList) { |
| 6642 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 6643 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6644 | // It will be analyzed later. |
| 6645 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6646 | SrcExprs.push_back(nullptr); |
| 6647 | DstExprs.push_back(nullptr); |
| 6648 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6649 | continue; |
| 6650 | } |
| 6651 | |
| 6652 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6653 | // OpenMP [2.1, C/C++] |
| 6654 | // A list item is a variable name. |
| 6655 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 6656 | // A variable that is part of another variable (as an array or structure |
| 6657 | // element) cannot appear in a lastprivate clause. |
| 6658 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 6659 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6660 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6661 | continue; |
| 6662 | } |
| 6663 | Decl *D = DE->getDecl(); |
| 6664 | VarDecl *VD = cast<VarDecl>(D); |
| 6665 | |
| 6666 | QualType Type = VD->getType(); |
| 6667 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6668 | // It will be analyzed later. |
| 6669 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6670 | SrcExprs.push_back(nullptr); |
| 6671 | DstExprs.push_back(nullptr); |
| 6672 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6673 | continue; |
| 6674 | } |
| 6675 | |
| 6676 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6677 | // A variable that appears in a lastprivate clause must not have an |
| 6678 | // incomplete type or a reference type. |
| 6679 | if (RequireCompleteType(ELoc, Type, |
| 6680 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6681 | continue; |
| 6682 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6683 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6684 | |
| 6685 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6686 | // in a Construct] |
| 6687 | // Variables with the predetermined data-sharing attributes may not be |
| 6688 | // listed in data-sharing attributes clauses, except for the cases |
| 6689 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6690 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6691 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6692 | DVar.CKind != OMPC_firstprivate && |
| 6693 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6694 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6695 | << getOpenMPClauseName(DVar.CKind) |
| 6696 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6697 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6698 | continue; |
| 6699 | } |
| 6700 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6701 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6702 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6703 | // A list item that is private within a parallel region, or that appears in |
| 6704 | // the reduction clause of a parallel construct, must not appear in a |
| 6705 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6706 | // worksharing regions ever binds to any of the corresponding parallel |
| 6707 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6708 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6709 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6710 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6711 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6712 | if (DVar.CKind != OMPC_shared) { |
| 6713 | Diag(ELoc, diag::err_omp_required_access) |
| 6714 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6715 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6716 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6717 | continue; |
| 6718 | } |
| 6719 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6720 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6721 | // A variable of class type (or array thereof) that appears in a |
| 6722 | // lastprivate clause requires an accessible, unambiguous default |
| 6723 | // constructor for the class type, unless the list item is also specified |
| 6724 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6725 | // A variable of class type (or array thereof) that appears in a |
| 6726 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6727 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6728 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6729 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6730 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6731 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6732 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6733 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6734 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6735 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6736 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6737 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6738 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6739 | // For arrays generate assignment operation for single element and replace |
| 6740 | // it by the original array element in CodeGen. |
| 6741 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6742 | PseudoDstExpr, PseudoSrcExpr); |
| 6743 | if (AssignmentOp.isInvalid()) |
| 6744 | continue; |
| 6745 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6746 | /*DiscardedValue=*/true); |
| 6747 | if (AssignmentOp.isInvalid()) |
| 6748 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6749 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6750 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 6751 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 6752 | // both. |
| 6753 | if (CurrDir == OMPD_distribute) { |
| 6754 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
| 6755 | if (DVar.CKind == OMPC_firstprivate) { |
| 6756 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 6757 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6758 | continue; |
| 6759 | } |
| 6760 | } |
| 6761 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6762 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6763 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6764 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6765 | SrcExprs.push_back(PseudoSrcExpr); |
| 6766 | DstExprs.push_back(PseudoDstExpr); |
| 6767 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6768 | } |
| 6769 | |
| 6770 | if (Vars.empty()) |
| 6771 | return nullptr; |
| 6772 | |
| 6773 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6774 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6775 | } |
| 6776 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6777 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 6778 | SourceLocation StartLoc, |
| 6779 | SourceLocation LParenLoc, |
| 6780 | SourceLocation EndLoc) { |
| 6781 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6782 | for (auto &RefExpr : VarList) { |
| 6783 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6784 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6785 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6786 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6787 | continue; |
| 6788 | } |
| 6789 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6790 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6791 | // OpenMP [2.1, C/C++] |
| 6792 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 6793 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 6794 | // A variable that is part of another variable (as an array or structure |
| 6795 | // element) cannot appear in a shared unless it is a static data member |
| 6796 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6797 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6798 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6799 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6800 | continue; |
| 6801 | } |
| 6802 | Decl *D = DE->getDecl(); |
| 6803 | VarDecl *VD = cast<VarDecl>(D); |
| 6804 | |
| 6805 | QualType Type = VD->getType(); |
| 6806 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6807 | // It will be analyzed later. |
| 6808 | Vars.push_back(DE); |
| 6809 | continue; |
| 6810 | } |
| 6811 | |
| 6812 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6813 | // in a Construct] |
| 6814 | // Variables with the predetermined data-sharing attributes may not be |
| 6815 | // listed in data-sharing attributes clauses, except for the cases |
| 6816 | // listed below. For these exceptions only, listing a predetermined |
| 6817 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6818 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6819 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6820 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 6821 | DVar.RefExpr) { |
| 6822 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6823 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6824 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6825 | continue; |
| 6826 | } |
| 6827 | |
| 6828 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 6829 | Vars.push_back(DE); |
| 6830 | } |
| 6831 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6832 | if (Vars.empty()) |
| 6833 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6834 | |
| 6835 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 6836 | } |
| 6837 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6838 | namespace { |
| 6839 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 6840 | DSAStackTy *Stack; |
| 6841 | |
| 6842 | public: |
| 6843 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 6844 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6845 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6846 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 6847 | return false; |
| 6848 | if (DVar.CKind != OMPC_unknown) |
| 6849 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6850 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6851 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6852 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6853 | return true; |
| 6854 | return false; |
| 6855 | } |
| 6856 | return false; |
| 6857 | } |
| 6858 | bool VisitStmt(Stmt *S) { |
| 6859 | for (auto Child : S->children()) { |
| 6860 | if (Child && Visit(Child)) |
| 6861 | return true; |
| 6862 | } |
| 6863 | return false; |
| 6864 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6865 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6866 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6867 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6868 | |
| 6869 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 6870 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 6871 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 6872 | CXXScopeSpec &ReductionIdScopeSpec, |
| 6873 | const DeclarationNameInfo &ReductionId) { |
| 6874 | // TODO: Allow scope specification search when 'declare reduction' is |
| 6875 | // supported. |
| 6876 | assert(ReductionIdScopeSpec.isEmpty() && |
| 6877 | "No support for scoped reduction identifiers yet."); |
| 6878 | |
| 6879 | auto DN = ReductionId.getName(); |
| 6880 | auto OOK = DN.getCXXOverloadedOperator(); |
| 6881 | BinaryOperatorKind BOK = BO_Comma; |
| 6882 | |
| 6883 | // OpenMP [2.14.3.6, reduction clause] |
| 6884 | // C |
| 6885 | // reduction-identifier is either an identifier or one of the following |
| 6886 | // operators: +, -, *, &, |, ^, && and || |
| 6887 | // C++ |
| 6888 | // reduction-identifier is either an id-expression or one of the following |
| 6889 | // operators: +, -, *, &, |, ^, && and || |
| 6890 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 6891 | switch (OOK) { |
| 6892 | case OO_Plus: |
| 6893 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6894 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6895 | break; |
| 6896 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6897 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6898 | break; |
| 6899 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6900 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6901 | break; |
| 6902 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6903 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6904 | break; |
| 6905 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6906 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6907 | break; |
| 6908 | case OO_AmpAmp: |
| 6909 | BOK = BO_LAnd; |
| 6910 | break; |
| 6911 | case OO_PipePipe: |
| 6912 | BOK = BO_LOr; |
| 6913 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6914 | case OO_New: |
| 6915 | case OO_Delete: |
| 6916 | case OO_Array_New: |
| 6917 | case OO_Array_Delete: |
| 6918 | case OO_Slash: |
| 6919 | case OO_Percent: |
| 6920 | case OO_Tilde: |
| 6921 | case OO_Exclaim: |
| 6922 | case OO_Equal: |
| 6923 | case OO_Less: |
| 6924 | case OO_Greater: |
| 6925 | case OO_LessEqual: |
| 6926 | case OO_GreaterEqual: |
| 6927 | case OO_PlusEqual: |
| 6928 | case OO_MinusEqual: |
| 6929 | case OO_StarEqual: |
| 6930 | case OO_SlashEqual: |
| 6931 | case OO_PercentEqual: |
| 6932 | case OO_CaretEqual: |
| 6933 | case OO_AmpEqual: |
| 6934 | case OO_PipeEqual: |
| 6935 | case OO_LessLess: |
| 6936 | case OO_GreaterGreater: |
| 6937 | case OO_LessLessEqual: |
| 6938 | case OO_GreaterGreaterEqual: |
| 6939 | case OO_EqualEqual: |
| 6940 | case OO_ExclaimEqual: |
| 6941 | case OO_PlusPlus: |
| 6942 | case OO_MinusMinus: |
| 6943 | case OO_Comma: |
| 6944 | case OO_ArrowStar: |
| 6945 | case OO_Arrow: |
| 6946 | case OO_Call: |
| 6947 | case OO_Subscript: |
| 6948 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 6949 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6950 | case NUM_OVERLOADED_OPERATORS: |
| 6951 | llvm_unreachable("Unexpected reduction identifier"); |
| 6952 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6953 | if (auto II = DN.getAsIdentifierInfo()) { |
| 6954 | if (II->isStr("max")) |
| 6955 | BOK = BO_GT; |
| 6956 | else if (II->isStr("min")) |
| 6957 | BOK = BO_LT; |
| 6958 | } |
| 6959 | break; |
| 6960 | } |
| 6961 | SourceRange ReductionIdRange; |
| 6962 | if (ReductionIdScopeSpec.isValid()) { |
| 6963 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 6964 | } |
| 6965 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 6966 | if (BOK == BO_Comma) { |
| 6967 | // Not allowed reduction identifier is found. |
| 6968 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 6969 | << ReductionIdRange; |
| 6970 | return nullptr; |
| 6971 | } |
| 6972 | |
| 6973 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6974 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6975 | SmallVector<Expr *, 8> LHSs; |
| 6976 | SmallVector<Expr *, 8> RHSs; |
| 6977 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6978 | for (auto RefExpr : VarList) { |
| 6979 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 6980 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6981 | // It will be analyzed later. |
| 6982 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6983 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6984 | LHSs.push_back(nullptr); |
| 6985 | RHSs.push_back(nullptr); |
| 6986 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6987 | continue; |
| 6988 | } |
| 6989 | |
| 6990 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6991 | RefExpr->isInstantiationDependent() || |
| 6992 | RefExpr->containsUnexpandedParameterPack()) { |
| 6993 | // It will be analyzed later. |
| 6994 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6995 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6996 | LHSs.push_back(nullptr); |
| 6997 | RHSs.push_back(nullptr); |
| 6998 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6999 | continue; |
| 7000 | } |
| 7001 | |
| 7002 | auto ELoc = RefExpr->getExprLoc(); |
| 7003 | auto ERange = RefExpr->getSourceRange(); |
| 7004 | // OpenMP [2.1, C/C++] |
| 7005 | // A list item is a variable or array section, subject to the restrictions |
| 7006 | // specified in Section 2.4 on page 42 and in each of the sections |
| 7007 | // describing clauses and directives for which a list appears. |
| 7008 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7009 | // A variable that is part of another variable (as an array or |
| 7010 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7011 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7012 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 7013 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 7014 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
| 7015 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7016 | continue; |
| 7017 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7018 | QualType Type; |
| 7019 | VarDecl *VD = nullptr; |
| 7020 | if (DE) { |
| 7021 | auto D = DE->getDecl(); |
| 7022 | VD = cast<VarDecl>(D); |
| 7023 | Type = VD->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7024 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7025 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7026 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7027 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7028 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7029 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7030 | if (DE) |
| 7031 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7032 | if (!VD) { |
| 7033 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7034 | << 0 << Base->getSourceRange(); |
| 7035 | continue; |
| 7036 | } |
| 7037 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7038 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 7039 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 7040 | Type = ATy->getElementType(); |
| 7041 | else |
| 7042 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7043 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7044 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7045 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7046 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7047 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7048 | DE = dyn_cast<DeclRefExpr>(Base); |
| 7049 | if (DE) |
| 7050 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 7051 | if (!VD) { |
| 7052 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 7053 | << 1 << Base->getSourceRange(); |
| 7054 | continue; |
| 7055 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7056 | } |
| 7057 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7058 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7059 | // A variable that appears in a private clause must not have an incomplete |
| 7060 | // type or a reference type. |
| 7061 | if (RequireCompleteType(ELoc, Type, |
| 7062 | diag::err_omp_reduction_incomplete_type)) |
| 7063 | continue; |
| 7064 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7065 | // Arrays may not appear in a reduction clause. |
| 7066 | if (Type.getNonReferenceType()->isArrayType()) { |
| 7067 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
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 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7070 | VarDecl::DeclarationOnly; |
| 7071 | Diag(VD->getLocation(), |
| 7072 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7073 | << VD; |
| 7074 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7075 | continue; |
| 7076 | } |
| 7077 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7078 | // A list item that appears in a reduction clause must not be |
| 7079 | // const-qualified. |
| 7080 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7081 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7082 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7083 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7084 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7085 | VarDecl::DeclarationOnly; |
| 7086 | Diag(VD->getLocation(), |
| 7087 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7088 | << VD; |
| 7089 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7090 | continue; |
| 7091 | } |
| 7092 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 7093 | // If a list-item is a reference type then it must bind to the same object |
| 7094 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7095 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7096 | VarDecl *VDDef = VD->getDefinition(); |
| 7097 | if (Type->isReferenceType() && VDDef) { |
| 7098 | DSARefChecker Check(DSAStack); |
| 7099 | if (Check.Visit(VDDef->getInit())) { |
| 7100 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 7101 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 7102 | continue; |
| 7103 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7104 | } |
| 7105 | } |
| 7106 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 7107 | // The type of a list item that appears in a reduction clause must be valid |
| 7108 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 7109 | // of the list item must be an allowed arithmetic data type: char, int, |
| 7110 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 7111 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 7112 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 7113 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 7114 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 7115 | !(Type->isScalarType() || |
| 7116 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 7117 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 7118 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7119 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7120 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7121 | VarDecl::DeclarationOnly; |
| 7122 | Diag(VD->getLocation(), |
| 7123 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7124 | << VD; |
| 7125 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7126 | continue; |
| 7127 | } |
| 7128 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 7129 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 7130 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7131 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7132 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7133 | VarDecl::DeclarationOnly; |
| 7134 | Diag(VD->getLocation(), |
| 7135 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7136 | << VD; |
| 7137 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7138 | continue; |
| 7139 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7140 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7141 | // in a Construct] |
| 7142 | // Variables with the predetermined data-sharing attributes may not be |
| 7143 | // listed in data-sharing attributes clauses, except for the cases |
| 7144 | // listed below. For these exceptions only, listing a predetermined |
| 7145 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7146 | // the variable's predetermined data-sharing attributes. |
| 7147 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 7148 | // Any number of reduction clauses can be specified on the directive, |
| 7149 | // but a list item can appear only once in the reduction clauses for that |
| 7150 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7151 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7152 | DVar = DSAStack->getTopDSA(VD, false); |
| 7153 | if (DVar.CKind == OMPC_reduction) { |
| 7154 | Diag(ELoc, diag::err_omp_once_referenced) |
| 7155 | << getOpenMPClauseName(OMPC_reduction); |
| 7156 | if (DVar.RefExpr) { |
| 7157 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7158 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7159 | } else if (DVar.CKind != OMPC_unknown) { |
| 7160 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7161 | << getOpenMPClauseName(DVar.CKind) |
| 7162 | << getOpenMPClauseName(OMPC_reduction); |
| 7163 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7164 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7165 | } |
| 7166 | |
| 7167 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 7168 | // A list item that appears in a reduction clause of a worksharing |
| 7169 | // construct must be shared in the parallel regions to which any of the |
| 7170 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7171 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7172 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 7173 | !isOpenMPParallelDirective(CurrDir)) { |
| 7174 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 7175 | if (DVar.CKind != OMPC_shared) { |
| 7176 | Diag(ELoc, diag::err_omp_required_access) |
| 7177 | << getOpenMPClauseName(OMPC_reduction) |
| 7178 | << getOpenMPClauseName(OMPC_shared); |
| 7179 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7180 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7181 | } |
| 7182 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7183 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7184 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7185 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 7186 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7187 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 7188 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 7189 | auto PrivateTy = Type; |
| 7190 | if (OASE) { |
| 7191 | // For array sections only: |
| 7192 | // Create pseudo array type for private copy. The size for this array will |
| 7193 | // be generated during codegen. |
| 7194 | // For array subscripts or single variables Private Ty is the same as Type |
| 7195 | // (type of the variable or single array element). |
| 7196 | PrivateTy = Context.getVariableArrayType( |
| 7197 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 7198 | Context.getSizeType(), VK_RValue), |
| 7199 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| 7200 | } |
| 7201 | // Private copy. |
| 7202 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 7203 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7204 | // Add initializer for private variable. |
| 7205 | Expr *Init = nullptr; |
| 7206 | switch (BOK) { |
| 7207 | case BO_Add: |
| 7208 | case BO_Xor: |
| 7209 | case BO_Or: |
| 7210 | case BO_LOr: |
| 7211 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 7212 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7213 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7214 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7215 | break; |
| 7216 | case BO_Mul: |
| 7217 | case BO_LAnd: |
| 7218 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 7219 | // '*' and '&&' reduction ops - initializer is '1'. |
| 7220 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 7221 | } |
| 7222 | break; |
| 7223 | case BO_And: { |
| 7224 | // '&' reduction op - initializer is '~0'. |
| 7225 | QualType OrigType = Type; |
| 7226 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 7227 | Type = ComplexTy->getElementType(); |
| 7228 | } |
| 7229 | if (Type->isRealFloatingType()) { |
| 7230 | llvm::APFloat InitValue = |
| 7231 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 7232 | /*isIEEE=*/true); |
| 7233 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7234 | Type, ELoc); |
| 7235 | } else if (Type->isScalarType()) { |
| 7236 | auto Size = Context.getTypeSize(Type); |
| 7237 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 7238 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 7239 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7240 | } |
| 7241 | if (Init && OrigType->isAnyComplexType()) { |
| 7242 | // Init = 0xFFFF + 0xFFFFi; |
| 7243 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 7244 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 7245 | } |
| 7246 | Type = OrigType; |
| 7247 | break; |
| 7248 | } |
| 7249 | case BO_LT: |
| 7250 | case BO_GT: { |
| 7251 | // 'min' reduction op - initializer is 'Largest representable number in |
| 7252 | // the reduction list item type'. |
| 7253 | // 'max' reduction op - initializer is 'Least representable number in |
| 7254 | // the reduction list item type'. |
| 7255 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 7256 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 7257 | auto Size = Context.getTypeSize(Type); |
| 7258 | QualType IntTy = |
| 7259 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 7260 | llvm::APInt InitValue = |
| 7261 | (BOK != BO_LT) |
| 7262 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 7263 | : llvm::APInt::getMinValue(Size) |
| 7264 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 7265 | : llvm::APInt::getMaxValue(Size); |
| 7266 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 7267 | if (Type->isPointerType()) { |
| 7268 | // Cast to pointer type. |
| 7269 | auto CastExpr = BuildCStyleCastExpr( |
| 7270 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 7271 | SourceLocation(), Init); |
| 7272 | if (CastExpr.isInvalid()) |
| 7273 | continue; |
| 7274 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7275 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7276 | } else if (Type->isRealFloatingType()) { |
| 7277 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 7278 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 7279 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 7280 | Type, ELoc); |
| 7281 | } |
| 7282 | break; |
| 7283 | } |
| 7284 | case BO_PtrMemD: |
| 7285 | case BO_PtrMemI: |
| 7286 | case BO_MulAssign: |
| 7287 | case BO_Div: |
| 7288 | case BO_Rem: |
| 7289 | case BO_Sub: |
| 7290 | case BO_Shl: |
| 7291 | case BO_Shr: |
| 7292 | case BO_LE: |
| 7293 | case BO_GE: |
| 7294 | case BO_EQ: |
| 7295 | case BO_NE: |
| 7296 | case BO_AndAssign: |
| 7297 | case BO_XorAssign: |
| 7298 | case BO_OrAssign: |
| 7299 | case BO_Assign: |
| 7300 | case BO_AddAssign: |
| 7301 | case BO_SubAssign: |
| 7302 | case BO_DivAssign: |
| 7303 | case BO_RemAssign: |
| 7304 | case BO_ShlAssign: |
| 7305 | case BO_ShrAssign: |
| 7306 | case BO_Comma: |
| 7307 | llvm_unreachable("Unexpected reduction operation"); |
| 7308 | } |
| 7309 | if (Init) { |
| 7310 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7311 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7312 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7313 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7314 | if (!RHSVD->hasInit()) { |
| 7315 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7316 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7317 | if (VD) { |
| 7318 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7319 | VarDecl::DeclarationOnly; |
| 7320 | Diag(VD->getLocation(), |
| 7321 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7322 | << VD; |
| 7323 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7324 | continue; |
| 7325 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7326 | // Store initializer for single element in private copy. Will be used during |
| 7327 | // codegen. |
| 7328 | PrivateVD->setInit(RHSVD->getInit()); |
| 7329 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7330 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7331 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7332 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7333 | ExprResult ReductionOp = |
| 7334 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7335 | LHSDRE, RHSDRE); |
| 7336 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7337 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7338 | ReductionOp = |
| 7339 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7340 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7341 | } else { |
| 7342 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7343 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7344 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7345 | ReductionOp = |
| 7346 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7347 | BO_Assign, LHSDRE, ConditionalOp); |
| 7348 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7349 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7350 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7351 | if (ReductionOp.isInvalid()) |
| 7352 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7353 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7354 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7355 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7356 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7357 | LHSs.push_back(LHSDRE); |
| 7358 | RHSs.push_back(RHSDRE); |
| 7359 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7360 | } |
| 7361 | |
| 7362 | if (Vars.empty()) |
| 7363 | return nullptr; |
| 7364 | |
| 7365 | return OMPReductionClause::Create( |
| 7366 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7367 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7368 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7369 | } |
| 7370 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7371 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7372 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7373 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7374 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7375 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7376 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7377 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7378 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7379 | LinKind == OMPC_LINEAR_unknown) { |
| 7380 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7381 | LinKind = OMPC_LINEAR_val; |
| 7382 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7383 | for (auto &RefExpr : VarList) { |
| 7384 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7385 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7386 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7387 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7388 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7389 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7390 | continue; |
| 7391 | } |
| 7392 | |
| 7393 | // OpenMP [2.14.3.7, linear clause] |
| 7394 | // A list item that appears in a linear clause is subject to the private |
| 7395 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7396 | // noted. In addition, the value of the new list item on each iteration |
| 7397 | // of the associated loop(s) corresponds to the value of the original |
| 7398 | // list item before entering the construct plus the logical number of |
| 7399 | // the iteration times linear-step. |
| 7400 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7401 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7402 | // OpenMP [2.1, C/C++] |
| 7403 | // A list item is a variable name. |
| 7404 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7405 | // A variable that is part of another variable (as an array or |
| 7406 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7407 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7408 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7409 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7410 | continue; |
| 7411 | } |
| 7412 | |
| 7413 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7414 | |
| 7415 | // OpenMP [2.14.3.7, linear clause] |
| 7416 | // A list-item cannot appear in more than one linear clause. |
| 7417 | // A list-item that appears in a linear clause cannot appear in any |
| 7418 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7419 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7420 | if (DVar.RefExpr) { |
| 7421 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7422 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7423 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7424 | continue; |
| 7425 | } |
| 7426 | |
| 7427 | QualType QType = VD->getType(); |
| 7428 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7429 | // It will be analyzed later. |
| 7430 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7431 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7432 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7433 | continue; |
| 7434 | } |
| 7435 | |
| 7436 | // A variable must not have an incomplete type or a reference type. |
| 7437 | if (RequireCompleteType(ELoc, QType, |
| 7438 | diag::err_omp_linear_incomplete_type)) { |
| 7439 | continue; |
| 7440 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7441 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7442 | !QType->isReferenceType()) { |
| 7443 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7444 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7445 | continue; |
| 7446 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7447 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7448 | |
| 7449 | // A list item must not be const-qualified. |
| 7450 | if (QType.isConstant(Context)) { |
| 7451 | Diag(ELoc, diag::err_omp_const_variable) |
| 7452 | << getOpenMPClauseName(OMPC_linear); |
| 7453 | bool IsDecl = |
| 7454 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7455 | Diag(VD->getLocation(), |
| 7456 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7457 | << VD; |
| 7458 | continue; |
| 7459 | } |
| 7460 | |
| 7461 | // A list item must be of integral or pointer type. |
| 7462 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7463 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7464 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7465 | !Ty->isPointerType())) { |
| 7466 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 7467 | bool IsDecl = |
| 7468 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7469 | Diag(VD->getLocation(), |
| 7470 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7471 | << VD; |
| 7472 | continue; |
| 7473 | } |
| 7474 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7475 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7476 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7477 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7478 | auto *PrivateRef = buildDeclRefExpr( |
| 7479 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7480 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7481 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7482 | Expr *InitExpr; |
| 7483 | if (LinKind == OMPC_LINEAR_uval) |
| 7484 | InitExpr = VD->getInit(); |
| 7485 | else |
| 7486 | InitExpr = DE; |
| 7487 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7488 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7489 | auto InitRef = buildDeclRefExpr( |
| 7490 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7491 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7492 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7493 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7494 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7495 | } |
| 7496 | |
| 7497 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7498 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7499 | |
| 7500 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7501 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7502 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7503 | !Step->isInstantiationDependent() && |
| 7504 | !Step->containsUnexpandedParameterPack()) { |
| 7505 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7506 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7507 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7508 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7509 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7510 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7511 | // Build var to save the step value. |
| 7512 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7513 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7514 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7515 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7516 | ExprResult CalcStep = |
| 7517 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7518 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7519 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7520 | // Warn about zero linear step (it would be probably better specified as |
| 7521 | // making corresponding variables 'const'). |
| 7522 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7523 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7524 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7525 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7526 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7527 | if (!IsConstant && CalcStep.isUsable()) { |
| 7528 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7529 | // (This is not used if the number of iterations may be kfold-ed). |
| 7530 | CalcStepExpr = CalcStep.get(); |
| 7531 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7532 | } |
| 7533 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7534 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7535 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7536 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7537 | } |
| 7538 | |
| 7539 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7540 | Expr *NumIterations, Sema &SemaRef, |
| 7541 | Scope *S) { |
| 7542 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7543 | SmallVector<Expr *, 8> Updates; |
| 7544 | SmallVector<Expr *, 8> Finals; |
| 7545 | Expr *Step = Clause.getStep(); |
| 7546 | Expr *CalcStep = Clause.getCalcStep(); |
| 7547 | // OpenMP [2.14.3.7, linear clause] |
| 7548 | // If linear-step is not specified it is assumed to be 1. |
| 7549 | if (Step == nullptr) |
| 7550 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7551 | else if (CalcStep) |
| 7552 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7553 | bool HasErrors = false; |
| 7554 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7555 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7556 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7557 | for (auto &RefExpr : Clause.varlists()) { |
| 7558 | Expr *InitExpr = *CurInit; |
| 7559 | |
| 7560 | // Build privatized reference to the current linear var. |
| 7561 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7562 | Expr *CapturedRef; |
| 7563 | if (LinKind == OMPC_LINEAR_uval) |
| 7564 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 7565 | else |
| 7566 | CapturedRef = |
| 7567 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 7568 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 7569 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7570 | |
| 7571 | // Build update: Var = InitExpr + IV * Step |
| 7572 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7573 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7574 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7575 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 7576 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7577 | |
| 7578 | // Build final: Var = InitExpr + NumIterations * Step |
| 7579 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7580 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7581 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7582 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 7583 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7584 | if (!Update.isUsable() || !Final.isUsable()) { |
| 7585 | Updates.push_back(nullptr); |
| 7586 | Finals.push_back(nullptr); |
| 7587 | HasErrors = true; |
| 7588 | } else { |
| 7589 | Updates.push_back(Update.get()); |
| 7590 | Finals.push_back(Final.get()); |
| 7591 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7592 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7593 | } |
| 7594 | Clause.setUpdates(Updates); |
| 7595 | Clause.setFinals(Finals); |
| 7596 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7597 | } |
| 7598 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7599 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 7600 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 7601 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 7602 | |
| 7603 | SmallVector<Expr *, 8> Vars; |
| 7604 | for (auto &RefExpr : VarList) { |
| 7605 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 7606 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7607 | // It will be analyzed later. |
| 7608 | Vars.push_back(RefExpr); |
| 7609 | continue; |
| 7610 | } |
| 7611 | |
| 7612 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7613 | // OpenMP [2.1, C/C++] |
| 7614 | // A list item is a variable name. |
| 7615 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7616 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7617 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7618 | continue; |
| 7619 | } |
| 7620 | |
| 7621 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7622 | |
| 7623 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7624 | // The type of list items appearing in the aligned clause must be |
| 7625 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7626 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7627 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7628 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7629 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 7630 | !Ty->isPointerType())) { |
| 7631 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 7632 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 7633 | bool IsDecl = |
| 7634 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7635 | Diag(VD->getLocation(), |
| 7636 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7637 | << VD; |
| 7638 | continue; |
| 7639 | } |
| 7640 | |
| 7641 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7642 | // A list-item cannot appear in more than one aligned clause. |
| 7643 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 7644 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 7645 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 7646 | << getOpenMPClauseName(OMPC_aligned); |
| 7647 | continue; |
| 7648 | } |
| 7649 | |
| 7650 | Vars.push_back(DE); |
| 7651 | } |
| 7652 | |
| 7653 | // OpenMP [2.8.1, simd construct, Description] |
| 7654 | // The parameter of the aligned clause, alignment, must be a constant |
| 7655 | // positive integer expression. |
| 7656 | // If no optional parameter is specified, implementation-defined default |
| 7657 | // alignments for SIMD instructions on the target platforms are assumed. |
| 7658 | if (Alignment != nullptr) { |
| 7659 | ExprResult AlignResult = |
| 7660 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 7661 | if (AlignResult.isInvalid()) |
| 7662 | return nullptr; |
| 7663 | Alignment = AlignResult.get(); |
| 7664 | } |
| 7665 | if (Vars.empty()) |
| 7666 | return nullptr; |
| 7667 | |
| 7668 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 7669 | EndLoc, Vars, Alignment); |
| 7670 | } |
| 7671 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7672 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 7673 | SourceLocation StartLoc, |
| 7674 | SourceLocation LParenLoc, |
| 7675 | SourceLocation EndLoc) { |
| 7676 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7677 | SmallVector<Expr *, 8> SrcExprs; |
| 7678 | SmallVector<Expr *, 8> DstExprs; |
| 7679 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7680 | for (auto &RefExpr : VarList) { |
| 7681 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 7682 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7683 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7684 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7685 | SrcExprs.push_back(nullptr); |
| 7686 | DstExprs.push_back(nullptr); |
| 7687 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7688 | continue; |
| 7689 | } |
| 7690 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7691 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7692 | // OpenMP [2.1, C/C++] |
| 7693 | // A list item is a variable name. |
| 7694 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7695 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7696 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7697 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7698 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7699 | continue; |
| 7700 | } |
| 7701 | |
| 7702 | Decl *D = DE->getDecl(); |
| 7703 | VarDecl *VD = cast<VarDecl>(D); |
| 7704 | |
| 7705 | QualType Type = VD->getType(); |
| 7706 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7707 | // It will be analyzed later. |
| 7708 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7709 | SrcExprs.push_back(nullptr); |
| 7710 | DstExprs.push_back(nullptr); |
| 7711 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7712 | continue; |
| 7713 | } |
| 7714 | |
| 7715 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 7716 | // A list item that appears in a copyin clause must be threadprivate. |
| 7717 | if (!DSAStack->isThreadPrivate(VD)) { |
| 7718 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7719 | << getOpenMPClauseName(OMPC_copyin) |
| 7720 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7721 | continue; |
| 7722 | } |
| 7723 | |
| 7724 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7725 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7726 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7727 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7728 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7729 | auto *SrcVD = |
| 7730 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 7731 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7732 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7733 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 7734 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7735 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 7736 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7737 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7738 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7739 | // For arrays generate assignment operation for single element and replace |
| 7740 | // it by the original array element in CodeGen. |
| 7741 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7742 | PseudoDstExpr, PseudoSrcExpr); |
| 7743 | if (AssignmentOp.isInvalid()) |
| 7744 | continue; |
| 7745 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7746 | /*DiscardedValue=*/true); |
| 7747 | if (AssignmentOp.isInvalid()) |
| 7748 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7749 | |
| 7750 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 7751 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7752 | SrcExprs.push_back(PseudoSrcExpr); |
| 7753 | DstExprs.push_back(PseudoDstExpr); |
| 7754 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7755 | } |
| 7756 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7757 | if (Vars.empty()) |
| 7758 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7759 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7760 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7761 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7762 | } |
| 7763 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7764 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7765 | SourceLocation StartLoc, |
| 7766 | SourceLocation LParenLoc, |
| 7767 | SourceLocation EndLoc) { |
| 7768 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7769 | SmallVector<Expr *, 8> SrcExprs; |
| 7770 | SmallVector<Expr *, 8> DstExprs; |
| 7771 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7772 | for (auto &RefExpr : VarList) { |
| 7773 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7774 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7775 | // It will be analyzed later. |
| 7776 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7777 | SrcExprs.push_back(nullptr); |
| 7778 | DstExprs.push_back(nullptr); |
| 7779 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7780 | continue; |
| 7781 | } |
| 7782 | |
| 7783 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7784 | // OpenMP [2.1, C/C++] |
| 7785 | // A list item is a variable name. |
| 7786 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7787 | // A list item that appears in a copyin clause must be threadprivate. |
| 7788 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7789 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7790 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7791 | continue; |
| 7792 | } |
| 7793 | |
| 7794 | Decl *D = DE->getDecl(); |
| 7795 | VarDecl *VD = cast<VarDecl>(D); |
| 7796 | |
| 7797 | QualType Type = VD->getType(); |
| 7798 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7799 | // It will be analyzed later. |
| 7800 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7801 | SrcExprs.push_back(nullptr); |
| 7802 | DstExprs.push_back(nullptr); |
| 7803 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7804 | continue; |
| 7805 | } |
| 7806 | |
| 7807 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 7808 | // A list item that appears in a copyprivate clause may not appear in a |
| 7809 | // private or firstprivate clause on the single construct. |
| 7810 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7811 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7812 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 7813 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7814 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7815 | << getOpenMPClauseName(DVar.CKind) |
| 7816 | << getOpenMPClauseName(OMPC_copyprivate); |
| 7817 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7818 | continue; |
| 7819 | } |
| 7820 | |
| 7821 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 7822 | // All list items that appear in a copyprivate clause must be either |
| 7823 | // threadprivate or private in the enclosing context. |
| 7824 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7825 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7826 | if (DVar.CKind == OMPC_shared) { |
| 7827 | Diag(ELoc, diag::err_omp_required_access) |
| 7828 | << getOpenMPClauseName(OMPC_copyprivate) |
| 7829 | << "threadprivate or private in the enclosing context"; |
| 7830 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7831 | continue; |
| 7832 | } |
| 7833 | } |
| 7834 | } |
| 7835 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7836 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7837 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7838 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7839 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 7840 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7841 | bool IsDecl = |
| 7842 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7843 | Diag(VD->getLocation(), |
| 7844 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7845 | << VD; |
| 7846 | continue; |
| 7847 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7848 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7849 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7850 | // A variable of class type (or array thereof) that appears in a |
| 7851 | // copyin clause requires an accessible, unambiguous copy assignment |
| 7852 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7853 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 7854 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7855 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7856 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 7857 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7858 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7859 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7860 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7861 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 7862 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7863 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7864 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7865 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7866 | PseudoDstExpr, PseudoSrcExpr); |
| 7867 | if (AssignmentOp.isInvalid()) |
| 7868 | continue; |
| 7869 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7870 | /*DiscardedValue=*/true); |
| 7871 | if (AssignmentOp.isInvalid()) |
| 7872 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7873 | |
| 7874 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 7875 | // implicitly private. |
| 7876 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7877 | SrcExprs.push_back(PseudoSrcExpr); |
| 7878 | DstExprs.push_back(PseudoDstExpr); |
| 7879 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7880 | } |
| 7881 | |
| 7882 | if (Vars.empty()) |
| 7883 | return nullptr; |
| 7884 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7885 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 7886 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7887 | } |
| 7888 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7889 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 7890 | SourceLocation StartLoc, |
| 7891 | SourceLocation LParenLoc, |
| 7892 | SourceLocation EndLoc) { |
| 7893 | if (VarList.empty()) |
| 7894 | return nullptr; |
| 7895 | |
| 7896 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 7897 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7898 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7899 | OMPClause * |
| 7900 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 7901 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 7902 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 7903 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7904 | if (DepKind == OMPC_DEPEND_unknown) { |
| 7905 | std::string Values; |
| 7906 | std::string Sep(", "); |
| 7907 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 7908 | Values += "'"; |
| 7909 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 7910 | Values += "'"; |
| 7911 | switch (i) { |
| 7912 | case OMPC_DEPEND_unknown - 2: |
| 7913 | Values += " or "; |
| 7914 | break; |
| 7915 | case OMPC_DEPEND_unknown - 1: |
| 7916 | break; |
| 7917 | default: |
| 7918 | Values += Sep; |
| 7919 | break; |
| 7920 | } |
| 7921 | } |
| 7922 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 7923 | << Values << getOpenMPClauseName(OMPC_depend); |
| 7924 | return nullptr; |
| 7925 | } |
| 7926 | SmallVector<Expr *, 8> Vars; |
| 7927 | for (auto &RefExpr : VarList) { |
| 7928 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7929 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7930 | // It will be analyzed later. |
| 7931 | Vars.push_back(RefExpr); |
| 7932 | continue; |
| 7933 | } |
| 7934 | |
| 7935 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7936 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 7937 | // A variable that is part of another variable (such as a field of a |
| 7938 | // structure) but is not an array element or an array section cannot appear |
| 7939 | // in a depend clause. |
| 7940 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7941 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7942 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7943 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7944 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 7945 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7946 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7947 | !ASE->getBase()->getType()->isArrayType())) { |
| 7948 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7949 | << RefExpr->getSourceRange(); |
| 7950 | continue; |
| 7951 | } |
| 7952 | |
| 7953 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 7954 | } |
| 7955 | |
| 7956 | if (Vars.empty()) |
| 7957 | return nullptr; |
| 7958 | |
| 7959 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 7960 | DepLoc, ColonLoc, Vars); |
| 7961 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7962 | |
| 7963 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 7964 | SourceLocation LParenLoc, |
| 7965 | SourceLocation EndLoc) { |
| 7966 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7967 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7968 | // OpenMP [2.9.1, Restrictions] |
| 7969 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7970 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 7971 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7972 | return nullptr; |
| 7973 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7974 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7975 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7976 | |
| 7977 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 7978 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 7979 | if (!RD || RD->isInvalidDecl()) |
| 7980 | return true; |
| 7981 | |
| 7982 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 7983 | if (RD->isDynamicClass()) { |
| 7984 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7985 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 7986 | return false; |
| 7987 | } |
| 7988 | auto *DC = RD; |
| 7989 | bool IsCorrect = true; |
| 7990 | for (auto *I : DC->decls()) { |
| 7991 | if (I) { |
| 7992 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 7993 | if (MD->isStatic()) { |
| 7994 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7995 | SemaRef.Diag(MD->getLocation(), |
| 7996 | diag::note_omp_static_member_in_target); |
| 7997 | IsCorrect = false; |
| 7998 | } |
| 7999 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 8000 | if (VD->isStaticDataMember()) { |
| 8001 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 8002 | SemaRef.Diag(VD->getLocation(), |
| 8003 | diag::note_omp_static_member_in_target); |
| 8004 | IsCorrect = false; |
| 8005 | } |
| 8006 | } |
| 8007 | } |
| 8008 | } |
| 8009 | |
| 8010 | for (auto &I : RD->bases()) { |
| 8011 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 8012 | I.getType()->getAsCXXRecordDecl())) |
| 8013 | IsCorrect = false; |
| 8014 | } |
| 8015 | return IsCorrect; |
| 8016 | } |
| 8017 | |
| 8018 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 8019 | DSAStackTy *Stack, QualType QTy) { |
| 8020 | NamedDecl *ND; |
| 8021 | if (QTy->isIncompleteType(&ND)) { |
| 8022 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 8023 | return false; |
| 8024 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 8025 | if (!RD->isInvalidDecl() && |
| 8026 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 8027 | return false; |
| 8028 | } |
| 8029 | return true; |
| 8030 | } |
| 8031 | |
| 8032 | OMPClause *Sema::ActOnOpenMPMapClause( |
| 8033 | OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, |
| 8034 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 8035 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 8036 | SmallVector<Expr *, 4> Vars; |
| 8037 | |
| 8038 | for (auto &RE : VarList) { |
| 8039 | assert(RE && "Null expr in omp map"); |
| 8040 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 8041 | // It will be analyzed later. |
| 8042 | Vars.push_back(RE); |
| 8043 | continue; |
| 8044 | } |
| 8045 | SourceLocation ELoc = RE->getExprLoc(); |
| 8046 | |
| 8047 | // OpenMP [2.14.5, Restrictions] |
| 8048 | // A variable that is part of another variable (such as field of a |
| 8049 | // structure) but is not an array element or an array section cannot appear |
| 8050 | // in a map clause. |
| 8051 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 8052 | |
| 8053 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 8054 | VE->isInstantiationDependent() || |
| 8055 | VE->containsUnexpandedParameterPack()) { |
| 8056 | // It will be analyzed later. |
| 8057 | Vars.push_back(RE); |
| 8058 | continue; |
| 8059 | } |
| 8060 | |
| 8061 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
| 8062 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 8063 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 8064 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 8065 | |
| 8066 | if (!RE->IgnoreParenImpCasts()->isLValue() || |
| 8067 | (!OASE && !ASE && !DE) || |
| 8068 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 8069 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 8070 | !ASE->getBase()->getType()->isArrayType())) { |
| 8071 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 8072 | << RE->getSourceRange(); |
| 8073 | continue; |
| 8074 | } |
| 8075 | |
| 8076 | Decl *D = nullptr; |
| 8077 | if (DE) { |
| 8078 | D = DE->getDecl(); |
| 8079 | } else if (ASE) { |
| 8080 | auto *B = ASE->getBase()->IgnoreParenCasts(); |
| 8081 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8082 | } else if (OASE) { |
| 8083 | auto *B = OASE->getBase(); |
| 8084 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 8085 | } |
| 8086 | assert(D && "Null decl on map clause."); |
| 8087 | auto *VD = cast<VarDecl>(D); |
| 8088 | |
| 8089 | // OpenMP [2.14.5, Restrictions, p.8] |
| 8090 | // threadprivate variables cannot appear in a map clause. |
| 8091 | if (DSAStack->isThreadPrivate(VD)) { |
| 8092 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 8093 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 8094 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 8095 | continue; |
| 8096 | } |
| 8097 | |
| 8098 | // OpenMP [2.14.5, Restrictions, p.2] |
| 8099 | // At most one list item can be an array item derived from a given variable |
| 8100 | // in map clauses of the same construct. |
| 8101 | // OpenMP [2.14.5, Restrictions, p.3] |
| 8102 | // List items of map clauses in the same construct must not share original |
| 8103 | // storage. |
| 8104 | // OpenMP [2.14.5, Restrictions, C/C++, p.2] |
| 8105 | // A variable for which the type is pointer, reference to array, or |
| 8106 | // reference to pointer and an array section derived from that variable |
| 8107 | // must not appear as list items of map clauses of the same construct. |
| 8108 | DSAStackTy::MapInfo MI = DSAStack->IsMappedInCurrentRegion(VD); |
| 8109 | if (MI.RefExpr) { |
| 8110 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8111 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8112 | << MI.RefExpr->getSourceRange(); |
| 8113 | continue; |
| 8114 | } |
| 8115 | |
| 8116 | // OpenMP [2.14.5, Restrictions, C/C++, p.3,4] |
| 8117 | // A variable for which the type is pointer, reference to array, or |
| 8118 | // reference to pointer must not appear as a list item if the enclosing |
| 8119 | // device data environment already contains an array section derived from |
| 8120 | // that variable. |
| 8121 | // An array section derived from a variable for which the type is pointer, |
| 8122 | // reference to array, or reference to pointer must not appear as a list |
| 8123 | // item if the enclosing device data environment already contains that |
| 8124 | // variable. |
| 8125 | QualType Type = VD->getType(); |
| 8126 | MI = DSAStack->getMapInfoForVar(VD); |
| 8127 | if (MI.RefExpr && (isa<DeclRefExpr>(MI.RefExpr->IgnoreParenLValueCasts()) != |
| 8128 | isa<DeclRefExpr>(VE)) && |
| 8129 | (Type->isPointerType() || Type->isReferenceType())) { |
| 8130 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 8131 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 8132 | << MI.RefExpr->getSourceRange(); |
| 8133 | continue; |
| 8134 | } |
| 8135 | |
| 8136 | // OpenMP [2.14.5, Restrictions, C/C++, p.7] |
| 8137 | // A list item must have a mappable type. |
| 8138 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 8139 | DSAStack, Type)) |
| 8140 | continue; |
| 8141 | |
| 8142 | Vars.push_back(RE); |
| 8143 | MI.RefExpr = RE; |
| 8144 | DSAStack->addMapInfoForVar(VD, MI); |
| 8145 | } |
| 8146 | if (Vars.empty()) |
| 8147 | return nullptr; |
| 8148 | |
| 8149 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8150 | MapTypeModifier, MapType, MapLoc); |
| 8151 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8152 | |
| 8153 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 8154 | SourceLocation StartLoc, |
| 8155 | SourceLocation LParenLoc, |
| 8156 | SourceLocation EndLoc) { |
| 8157 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8158 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8159 | // OpenMP [teams Constrcut, Restrictions] |
| 8160 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8161 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 8162 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8163 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8164 | |
| 8165 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8166 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8167 | |
| 8168 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 8169 | SourceLocation StartLoc, |
| 8170 | SourceLocation LParenLoc, |
| 8171 | SourceLocation EndLoc) { |
| 8172 | Expr *ValExpr = ThreadLimit; |
| 8173 | |
| 8174 | // OpenMP [teams Constrcut, Restrictions] |
| 8175 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8176 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 8177 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8178 | return nullptr; |
| 8179 | |
| 8180 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 8181 | EndLoc); |
| 8182 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8183 | |
| 8184 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 8185 | SourceLocation StartLoc, |
| 8186 | SourceLocation LParenLoc, |
| 8187 | SourceLocation EndLoc) { |
| 8188 | Expr *ValExpr = Priority; |
| 8189 | |
| 8190 | // OpenMP [2.9.1, task Constrcut] |
| 8191 | // The priority-value is a non-negative numerical scalar expression. |
| 8192 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 8193 | /*StrictlyPositive=*/false)) |
| 8194 | return nullptr; |
| 8195 | |
| 8196 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8197 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8198 | |
| 8199 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 8200 | SourceLocation StartLoc, |
| 8201 | SourceLocation LParenLoc, |
| 8202 | SourceLocation EndLoc) { |
| 8203 | Expr *ValExpr = Grainsize; |
| 8204 | |
| 8205 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8206 | // The parameter of the grainsize clause must be a positive integer |
| 8207 | // expression. |
| 8208 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 8209 | /*StrictlyPositive=*/true)) |
| 8210 | return nullptr; |
| 8211 | |
| 8212 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8213 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8214 | |
| 8215 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 8216 | SourceLocation StartLoc, |
| 8217 | SourceLocation LParenLoc, |
| 8218 | SourceLocation EndLoc) { |
| 8219 | Expr *ValExpr = NumTasks; |
| 8220 | |
| 8221 | // OpenMP [2.9.2, taskloop Constrcut] |
| 8222 | // The parameter of the num_tasks clause must be a positive integer |
| 8223 | // expression. |
| 8224 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 8225 | /*StrictlyPositive=*/true)) |
| 8226 | return nullptr; |
| 8227 | |
| 8228 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 8229 | } |
| 8230 | |