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 || |
| 349 | DKind == OMPD_taskloop; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 350 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 351 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 352 | |
| 353 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 354 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 355 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 356 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 357 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 358 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 359 | // in a region but not in construct] |
| 360 | // File-scope or namespace-scope variables referenced in called routines |
| 361 | // in the region are shared unless they appear in a threadprivate |
| 362 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 363 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 364 | DVar.CKind = OMPC_shared; |
| 365 | |
| 366 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 367 | // in a region but not in construct] |
| 368 | // Variables with static storage duration that are declared in called |
| 369 | // routines in the region are shared. |
| 370 | if (D->hasGlobalStorage()) |
| 371 | DVar.CKind = OMPC_shared; |
| 372 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 373 | return DVar; |
| 374 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 375 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 376 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 377 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 378 | // in a Construct, C/C++, predetermined, p.1] |
| 379 | // Variables with automatic storage duration that are declared in a scope |
| 380 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 381 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 382 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 383 | DVar.CKind = OMPC_private; |
| 384 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 385 | } |
| 386 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 387 | // Explicitly specified attributes and local variables with predetermined |
| 388 | // attributes. |
| 389 | if (Iter->SharingMap.count(D)) { |
| 390 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 391 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 392 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 393 | return DVar; |
| 394 | } |
| 395 | |
| 396 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 397 | // in a Construct, C/C++, implicitly determined, p.1] |
| 398 | // In a parallel or task construct, the data-sharing attributes of these |
| 399 | // variables are determined by the default clause, if present. |
| 400 | switch (Iter->DefaultAttr) { |
| 401 | case DSA_shared: |
| 402 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 403 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 404 | return DVar; |
| 405 | case DSA_none: |
| 406 | return DVar; |
| 407 | case DSA_unspecified: |
| 408 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 409 | // in a Construct, implicitly determined, p.2] |
| 410 | // In a parallel construct, if no default clause is present, these |
| 411 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 412 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 413 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 414 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 415 | DVar.CKind = OMPC_shared; |
| 416 | return DVar; |
| 417 | } |
| 418 | |
| 419 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 420 | // in a Construct, implicitly determined, p.4] |
| 421 | // In a task construct, if no default clause is present, a variable that in |
| 422 | // the enclosing context is determined to be shared by all implicit tasks |
| 423 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 424 | if (DVar.DKind == OMPD_task) { |
| 425 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 426 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 427 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 428 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 429 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 430 | // in a Construct, implicitly determined, p.6] |
| 431 | // In a task construct, if no default clause is present, a variable |
| 432 | // whose data-sharing attribute is not determined by the rules above is |
| 433 | // firstprivate. |
| 434 | DVarTemp = getDSA(I, D); |
| 435 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 436 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 437 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 438 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 439 | return DVar; |
| 440 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 441 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 442 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 443 | } |
| 444 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 445 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 446 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 447 | return DVar; |
| 448 | } |
| 449 | } |
| 450 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 451 | // in a Construct, implicitly determined, p.3] |
| 452 | // For constructs other than task, if no default clause is present, these |
| 453 | // variables inherit their data-sharing attributes from the enclosing |
| 454 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 455 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 458 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 459 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 460 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 461 | auto It = Stack.back().AlignedMap.find(D); |
| 462 | if (It == Stack.back().AlignedMap.end()) { |
| 463 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 464 | Stack.back().AlignedMap[D] = NewDE; |
| 465 | return nullptr; |
| 466 | } else { |
| 467 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 468 | return It->second; |
| 469 | } |
| 470 | return nullptr; |
| 471 | } |
| 472 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 473 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 474 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 475 | D = D->getCanonicalDecl(); |
| 476 | Stack.back().LCVSet.insert(D); |
| 477 | } |
| 478 | |
| 479 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 480 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 481 | D = D->getCanonicalDecl(); |
| 482 | return Stack.back().LCVSet.count(D) > 0; |
| 483 | } |
| 484 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 485 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 486 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 487 | if (A == OMPC_threadprivate) { |
| 488 | Stack[0].SharingMap[D].Attributes = A; |
| 489 | Stack[0].SharingMap[D].RefExpr = E; |
| 490 | } else { |
| 491 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 492 | Stack.back().SharingMap[D].Attributes = A; |
| 493 | Stack.back().SharingMap[D].RefExpr = E; |
| 494 | } |
| 495 | } |
| 496 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 497 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 498 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 499 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 500 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 501 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 502 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 503 | ++I; |
| 504 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 505 | if (I == E) |
| 506 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 507 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 508 | Scope *CurScope = getCurScope(); |
| 509 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 510 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 511 | } |
| 512 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 513 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 514 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 515 | } |
| 516 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 517 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 518 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 519 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 520 | DeclContext *DC = SemaRef.CurContext; |
| 521 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 522 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 523 | VarDecl *Decl = |
| 524 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 525 | if (Attrs) { |
| 526 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 527 | I != E; ++I) |
| 528 | Decl->addAttr(*I); |
| 529 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 530 | Decl->setImplicit(); |
| 531 | return Decl; |
| 532 | } |
| 533 | |
| 534 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 535 | SourceLocation Loc, |
| 536 | bool RefersToCapture = false) { |
| 537 | D->setReferenced(); |
| 538 | D->markUsed(S.Context); |
| 539 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 540 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 541 | VK_LValue); |
| 542 | } |
| 543 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 544 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 545 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 546 | DSAVarData DVar; |
| 547 | |
| 548 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 549 | // in a Construct, C/C++, predetermined, p.1] |
| 550 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 551 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 552 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 553 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 554 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 555 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 556 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 557 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 558 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 559 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 560 | } |
| 561 | if (Stack[0].SharingMap.count(D)) { |
| 562 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 563 | DVar.CKind = OMPC_threadprivate; |
| 564 | return DVar; |
| 565 | } |
| 566 | |
| 567 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 568 | // in a Construct, C/C++, predetermined, p.1] |
| 569 | // Variables with automatic storage duration that are declared in a scope |
| 570 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 571 | OpenMPDirectiveKind Kind = |
| 572 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 573 | auto StartI = std::next(Stack.rbegin()); |
| 574 | auto EndI = std::prev(Stack.rend()); |
| 575 | if (FromParent && StartI != EndI) { |
| 576 | StartI = std::next(StartI); |
| 577 | } |
| 578 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 579 | if (isOpenMPLocal(D, StartI) && |
| 580 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 581 | D->getStorageClass() == SC_None)) || |
| 582 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 583 | DVar.CKind = OMPC_private; |
| 584 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 585 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 586 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 587 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 588 | // in a Construct, C/C++, predetermined, p.4] |
| 589 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 590 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 591 | // in a Construct, C/C++, predetermined, p.7] |
| 592 | // Variables with static storage duration that are declared in a scope |
| 593 | // inside the construct are shared. |
Kelvin Li | 4eea8c6 | 2015-09-15 18:56:58 +0000 | [diff] [blame] | 594 | if (D->isStaticDataMember()) { |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 595 | DSAVarData DVarTemp = |
| 596 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 597 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 598 | return DVar; |
| 599 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 600 | DVar.CKind = OMPC_shared; |
| 601 | return DVar; |
| 602 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 606 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 607 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 608 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 609 | // in a Construct, C/C++, predetermined, p.6] |
| 610 | // Variables with const qualified type having no mutable member are |
| 611 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 612 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 613 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 614 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 615 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 616 | // Variables with const-qualified type having no mutable member may be |
| 617 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 618 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 619 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 620 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 621 | return DVar; |
| 622 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 623 | DVar.CKind = OMPC_shared; |
| 624 | return DVar; |
| 625 | } |
| 626 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 627 | // Explicitly specified attributes and local variables with predetermined |
| 628 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 629 | auto I = std::prev(StartI); |
| 630 | if (I->SharingMap.count(D)) { |
| 631 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 632 | DVar.CKind = I->SharingMap[D].Attributes; |
| 633 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | return DVar; |
| 637 | } |
| 638 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 639 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 640 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 641 | auto StartI = Stack.rbegin(); |
| 642 | auto EndI = std::prev(Stack.rend()); |
| 643 | if (FromParent && StartI != EndI) { |
| 644 | StartI = std::next(StartI); |
| 645 | } |
| 646 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 647 | } |
| 648 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 649 | template <class ClausesPredicate, class DirectivesPredicate> |
| 650 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 651 | DirectivesPredicate DPred, |
| 652 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 653 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 654 | auto StartI = std::next(Stack.rbegin()); |
| 655 | auto EndI = std::prev(Stack.rend()); |
| 656 | if (FromParent && StartI != EndI) { |
| 657 | StartI = std::next(StartI); |
| 658 | } |
| 659 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 660 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 661 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 662 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 663 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 664 | return DVar; |
| 665 | } |
| 666 | return DSAVarData(); |
| 667 | } |
| 668 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 669 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 670 | DSAStackTy::DSAVarData |
| 671 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 672 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 673 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 674 | auto StartI = std::next(Stack.rbegin()); |
| 675 | auto EndI = std::prev(Stack.rend()); |
| 676 | if (FromParent && StartI != EndI) { |
| 677 | StartI = std::next(StartI); |
| 678 | } |
| 679 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 680 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 681 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 682 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 683 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 684 | return DVar; |
| 685 | return DSAVarData(); |
| 686 | } |
| 687 | return DSAVarData(); |
| 688 | } |
| 689 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 690 | bool DSAStackTy::hasExplicitDSA( |
| 691 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 692 | unsigned Level) { |
| 693 | if (CPred(ClauseKindMode)) |
| 694 | return true; |
| 695 | if (isClauseParsingMode()) |
| 696 | ++Level; |
| 697 | D = D->getCanonicalDecl(); |
| 698 | auto StartI = Stack.rbegin(); |
| 699 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 700 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 701 | return false; |
| 702 | std::advance(StartI, Level); |
| 703 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 704 | CPred(StartI->SharingMap[D].Attributes); |
| 705 | } |
| 706 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 707 | bool DSAStackTy::hasExplicitDirective( |
| 708 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 709 | unsigned Level) { |
| 710 | if (isClauseParsingMode()) |
| 711 | ++Level; |
| 712 | auto StartI = Stack.rbegin(); |
| 713 | auto EndI = std::prev(Stack.rend()); |
| 714 | if (std::distance(StartI, EndI) <= (int)Level) |
| 715 | return false; |
| 716 | std::advance(StartI, Level); |
| 717 | return DPred(StartI->Directive); |
| 718 | } |
| 719 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 720 | template <class NamedDirectivesPredicate> |
| 721 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 722 | auto StartI = std::next(Stack.rbegin()); |
| 723 | auto EndI = std::prev(Stack.rend()); |
| 724 | if (FromParent && StartI != EndI) { |
| 725 | StartI = std::next(StartI); |
| 726 | } |
| 727 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 728 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 729 | return true; |
| 730 | } |
| 731 | return false; |
| 732 | } |
| 733 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame^] | 734 | OpenMPDirectiveKind DSAStackTy::getDirectiveForScope(const Scope *S) const { |
| 735 | for (auto I = Stack.rbegin(), EE = Stack.rend(); I != EE; ++I) |
| 736 | if (I->CurScope == S) |
| 737 | return I->Directive; |
| 738 | return OMPD_unknown; |
| 739 | } |
| 740 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 741 | void Sema::InitDataSharingAttributesStack() { |
| 742 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 743 | } |
| 744 | |
| 745 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 746 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame^] | 747 | bool Sema::IsOpenMPCapturedByRef(VarDecl *VD, |
| 748 | const CapturedRegionScopeInfo *RSI) { |
| 749 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 750 | |
| 751 | auto &Ctx = getASTContext(); |
| 752 | bool IsByRef = true; |
| 753 | |
| 754 | // Find the directive that is associated with the provided scope. |
| 755 | auto DKind = DSAStack->getDirectiveForScope(RSI->TheScope); |
| 756 | auto Ty = VD->getType(); |
| 757 | |
| 758 | if (isOpenMPTargetDirective(DKind)) { |
| 759 | // This table summarizes how a given variable should be passed to the device |
| 760 | // given its type and the clauses where it appears. This table is based on |
| 761 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 762 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 763 | // |
| 764 | // ========================================================================= |
| 765 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 766 | // | |(tofrom:scalar)| | pvt | | | | |
| 767 | // ========================================================================= |
| 768 | // | scl | | | | - | | bycopy| |
| 769 | // | scl | | - | x | - | - | bycopy| |
| 770 | // | scl | | x | - | - | - | null | |
| 771 | // | scl | x | | | - | | byref | |
| 772 | // | scl | x | - | x | - | - | bycopy| |
| 773 | // | scl | x | x | - | - | - | null | |
| 774 | // | scl | | - | - | - | x | byref | |
| 775 | // | scl | x | - | - | - | x | byref | |
| 776 | // |
| 777 | // | agg | n.a. | | | - | | byref | |
| 778 | // | agg | n.a. | - | x | - | - | byref | |
| 779 | // | agg | n.a. | x | - | - | - | null | |
| 780 | // | agg | n.a. | - | - | - | x | byref | |
| 781 | // | agg | n.a. | - | - | - | x[] | byref | |
| 782 | // |
| 783 | // | ptr | n.a. | | | - | | bycopy| |
| 784 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 785 | // | ptr | n.a. | x | - | - | - | null | |
| 786 | // | ptr | n.a. | - | - | - | x | byref | |
| 787 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 788 | // | ptr | n.a. | - | - | x | | bycopy| |
| 789 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 790 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 791 | // ========================================================================= |
| 792 | // Legend: |
| 793 | // scl - scalar |
| 794 | // ptr - pointer |
| 795 | // agg - aggregate |
| 796 | // x - applies |
| 797 | // - - invalid in this combination |
| 798 | // [] - mapped with an array section |
| 799 | // byref - should be mapped by reference |
| 800 | // byval - should be mapped by value |
| 801 | // null - initialize a local variable to null on the device |
| 802 | // |
| 803 | // Observations: |
| 804 | // - All scalar declarations that show up in a map clause have to be passed |
| 805 | // by reference, because they may have been mapped in the enclosing data |
| 806 | // environment. |
| 807 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 808 | // passed by reference, regardless the result in the table above. |
| 809 | // - For pointers mapped by value that have either an implicit map or an |
| 810 | // array section, the runtime library may pass the NULL value to the |
| 811 | // device instead of the value passed to it by the compiler. |
| 812 | |
| 813 | // FIXME: Right now, only implicit maps are implemented. Properly mapping |
| 814 | // values requires having the map, private, and firstprivate clauses SEMA |
| 815 | // and parsing in place, which we don't yet. |
| 816 | |
| 817 | if (Ty->isReferenceType()) |
| 818 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
| 819 | IsByRef = !Ty->isScalarType(); |
| 820 | } |
| 821 | |
| 822 | // When passing data by value, we need to make sure it fits the uintptr size |
| 823 | // and alignment, because the runtime library only deals with uintptr types. |
| 824 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 825 | // instead. |
| 826 | if (!IsByRef && |
| 827 | (Ctx.getTypeSizeInChars(Ty) > |
| 828 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
| 829 | Ctx.getDeclAlign(VD) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) |
| 830 | IsByRef = true; |
| 831 | |
| 832 | return IsByRef; |
| 833 | } |
| 834 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 835 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 836 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 837 | VD = VD->getCanonicalDecl(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 838 | |
| 839 | // If we are attempting to capture a global variable in a directive with |
| 840 | // 'target' we return true so that this global is also mapped to the device. |
| 841 | // |
| 842 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 843 | // then it should not be captured. Therefore, an extra check has to be |
| 844 | // inserted here once support for 'declare target' is added. |
| 845 | // |
| 846 | if (!VD->hasLocalStorage()) { |
| 847 | if (DSAStack->getCurrentDirective() == OMPD_target && |
| 848 | !DSAStack->isClauseParsingMode()) { |
| 849 | return true; |
| 850 | } |
| 851 | if (DSAStack->getCurScope() && |
| 852 | DSAStack->hasDirective( |
| 853 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &DNI, |
| 854 | SourceLocation Loc) -> bool { |
| 855 | return isOpenMPTargetDirective(K); |
| 856 | }, |
| 857 | false)) { |
| 858 | return true; |
| 859 | } |
| 860 | } |
| 861 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 862 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 863 | (!DSAStack->isClauseParsingMode() || |
| 864 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 865 | if (DSAStack->isLoopControlVariable(VD) || |
| 866 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 867 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 868 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 869 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 870 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 871 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 872 | return true; |
| 873 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 874 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 875 | return DVarPrivate.CKind != OMPC_unknown; |
| 876 | } |
| 877 | return false; |
| 878 | } |
| 879 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 880 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 881 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 882 | return DSAStack->hasExplicitDSA( |
| 883 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 884 | } |
| 885 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 886 | bool Sema::isOpenMPTargetCapturedVar(VarDecl *VD, unsigned Level) { |
| 887 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 888 | // Return true if the current level is no longer enclosed in a target region. |
| 889 | |
| 890 | return !VD->hasLocalStorage() && |
| 891 | DSAStack->hasExplicitDirective(isOpenMPTargetDirective, Level); |
| 892 | } |
| 893 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 894 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 895 | |
| 896 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 897 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 898 | Scope *CurScope, SourceLocation Loc) { |
| 899 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 900 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 901 | } |
| 902 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 903 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 904 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 905 | } |
| 906 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 907 | void Sema::EndOpenMPClause() { |
| 908 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 911 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 912 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 913 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 914 | // clause requires an accessible, unambiguous default constructor for the |
| 915 | // class type, unless the list item is also specified in a firstprivate |
| 916 | // clause. |
| 917 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 918 | for (auto *C : D->clauses()) { |
| 919 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 920 | SmallVector<Expr *, 8> PrivateCopies; |
| 921 | for (auto *DE : Clause->varlists()) { |
| 922 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 923 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 924 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 925 | } |
| 926 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 927 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 928 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 929 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 930 | // Generate helper private variable and initialize it with the |
| 931 | // default value. The address of the original variable is replaced |
| 932 | // by the address of the new private variable in CodeGen. This new |
| 933 | // variable is not added to IdResolver, so the code in the OpenMP |
| 934 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 935 | auto *VDPrivate = buildVarDecl( |
| 936 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 937 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 938 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 939 | if (VDPrivate->isInvalidDecl()) |
| 940 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 941 | PrivateCopies.push_back(buildDeclRefExpr( |
| 942 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 943 | } else { |
| 944 | // The variable is also a firstprivate, so initialization sequence |
| 945 | // for private copy is generated already. |
| 946 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 947 | } |
| 948 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 949 | // Set initializers to private copies if no errors were found. |
| 950 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 951 | Clause->setPrivateCopies(PrivateCopies); |
| 952 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | } |
| 956 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 957 | DSAStack->pop(); |
| 958 | DiscardCleanupsInEvaluationContext(); |
| 959 | PopExpressionEvaluationContext(); |
| 960 | } |
| 961 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 962 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 963 | Expr *NumIterations, Sema &SemaRef, |
| 964 | Scope *S); |
| 965 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 966 | namespace { |
| 967 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 968 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 969 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 970 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 971 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 972 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 973 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 974 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 975 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 976 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 977 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 978 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 979 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 980 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 981 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 982 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 983 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 984 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 985 | |
| 986 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 987 | CXXScopeSpec &ScopeSpec, |
| 988 | const DeclarationNameInfo &Id) { |
| 989 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 990 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 991 | |
| 992 | if (Lookup.isAmbiguous()) |
| 993 | return ExprError(); |
| 994 | |
| 995 | VarDecl *VD; |
| 996 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 997 | if (TypoCorrection Corrected = CorrectTypo( |
| 998 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 999 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1000 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1001 | PDiag(Lookup.empty() |
| 1002 | ? diag::err_undeclared_var_use_suggest |
| 1003 | : diag::err_omp_expected_var_arg_suggest) |
| 1004 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1005 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1006 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1007 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1008 | : diag::err_omp_expected_var_arg) |
| 1009 | << Id.getName(); |
| 1010 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1011 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1012 | } else { |
| 1013 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1014 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1015 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1016 | return ExprError(); |
| 1017 | } |
| 1018 | } |
| 1019 | Lookup.suppressDiagnostics(); |
| 1020 | |
| 1021 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1022 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1023 | if (!VD->hasGlobalStorage()) { |
| 1024 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1025 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1026 | bool IsDecl = |
| 1027 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1028 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1029 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1030 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1031 | return ExprError(); |
| 1032 | } |
| 1033 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1034 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1035 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1036 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1037 | // A threadprivate directive for file-scope variables must appear outside |
| 1038 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1039 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1040 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1041 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1042 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1043 | bool IsDecl = |
| 1044 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1045 | Diag(VD->getLocation(), |
| 1046 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1047 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1048 | return ExprError(); |
| 1049 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1050 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1051 | // A threadprivate directive for static class member variables must appear |
| 1052 | // in the class definition, in the same scope in which the member |
| 1053 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1054 | if (CanonicalVD->isStaticDataMember() && |
| 1055 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1056 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1057 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1058 | bool IsDecl = |
| 1059 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1060 | Diag(VD->getLocation(), |
| 1061 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1062 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1063 | return ExprError(); |
| 1064 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1065 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1066 | // A threadprivate directive for namespace-scope variables must appear |
| 1067 | // outside any definition or declaration other than the namespace |
| 1068 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1069 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1070 | (!getCurLexicalContext()->isFileContext() || |
| 1071 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1072 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1073 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1074 | bool IsDecl = |
| 1075 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1076 | Diag(VD->getLocation(), |
| 1077 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1078 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1079 | return ExprError(); |
| 1080 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1081 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1082 | // A threadprivate directive for static block-scope variables must appear |
| 1083 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1084 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1085 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1086 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1087 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1088 | bool IsDecl = |
| 1089 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1090 | Diag(VD->getLocation(), |
| 1091 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1092 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1093 | return ExprError(); |
| 1094 | } |
| 1095 | |
| 1096 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1097 | // A threadprivate directive must lexically precede all references to any |
| 1098 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1099 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1100 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1101 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1102 | return ExprError(); |
| 1103 | } |
| 1104 | |
| 1105 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1106 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1107 | return DE; |
| 1108 | } |
| 1109 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1110 | Sema::DeclGroupPtrTy |
| 1111 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1112 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1113 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1114 | CurContext->addDecl(D); |
| 1115 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1116 | } |
| 1117 | return DeclGroupPtrTy(); |
| 1118 | } |
| 1119 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1120 | namespace { |
| 1121 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1122 | Sema &SemaRef; |
| 1123 | |
| 1124 | public: |
| 1125 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1126 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1127 | if (VD->hasLocalStorage()) { |
| 1128 | SemaRef.Diag(E->getLocStart(), |
| 1129 | diag::err_omp_local_var_in_threadprivate_init) |
| 1130 | << E->getSourceRange(); |
| 1131 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1132 | << VD << VD->getSourceRange(); |
| 1133 | return true; |
| 1134 | } |
| 1135 | } |
| 1136 | return false; |
| 1137 | } |
| 1138 | bool VisitStmt(const Stmt *S) { |
| 1139 | for (auto Child : S->children()) { |
| 1140 | if (Child && Visit(Child)) |
| 1141 | return true; |
| 1142 | } |
| 1143 | return false; |
| 1144 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1145 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1146 | }; |
| 1147 | } // namespace |
| 1148 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1149 | OMPThreadPrivateDecl * |
| 1150 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1151 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1152 | for (auto &RefExpr : VarList) { |
| 1153 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1154 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1155 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1156 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1157 | QualType QType = VD->getType(); |
| 1158 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1159 | // It will be analyzed later. |
| 1160 | Vars.push_back(DE); |
| 1161 | continue; |
| 1162 | } |
| 1163 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1164 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1165 | // A threadprivate variable must not have an incomplete type. |
| 1166 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1167 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1168 | continue; |
| 1169 | } |
| 1170 | |
| 1171 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1172 | // A threadprivate variable must not have a reference type. |
| 1173 | if (VD->getType()->isReferenceType()) { |
| 1174 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1175 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1176 | bool IsDecl = |
| 1177 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1178 | Diag(VD->getLocation(), |
| 1179 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1180 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1181 | continue; |
| 1182 | } |
| 1183 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1184 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1185 | // the corresponding diagnostic. |
| 1186 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1187 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1188 | getLangOpts().OpenMPUseTLS && |
| 1189 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1190 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1191 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1192 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1193 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1194 | bool IsDecl = |
| 1195 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1196 | Diag(VD->getLocation(), |
| 1197 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1198 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1199 | continue; |
| 1200 | } |
| 1201 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1202 | // Check if initial value of threadprivate variable reference variable with |
| 1203 | // local storage (it is not supported by runtime). |
| 1204 | if (auto Init = VD->getAnyInitializer()) { |
| 1205 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1206 | if (Checker.Visit(Init)) |
| 1207 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1210 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1211 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1212 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1213 | Context, SourceRange(Loc, Loc))); |
| 1214 | if (auto *ML = Context.getASTMutationListener()) |
| 1215 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1216 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1217 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1218 | if (!Vars.empty()) { |
| 1219 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1220 | Vars); |
| 1221 | D->setAccess(AS_public); |
| 1222 | } |
| 1223 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1224 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1225 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1226 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1227 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1228 | bool IsLoopIterVar = false) { |
| 1229 | if (DVar.RefExpr) { |
| 1230 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1231 | << getOpenMPClauseName(DVar.CKind); |
| 1232 | return; |
| 1233 | } |
| 1234 | enum { |
| 1235 | PDSA_StaticMemberShared, |
| 1236 | PDSA_StaticLocalVarShared, |
| 1237 | PDSA_LoopIterVarPrivate, |
| 1238 | PDSA_LoopIterVarLinear, |
| 1239 | PDSA_LoopIterVarLastprivate, |
| 1240 | PDSA_ConstVarShared, |
| 1241 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1242 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1243 | PDSA_LocalVarPrivate, |
| 1244 | PDSA_Implicit |
| 1245 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1246 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1247 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1248 | if (IsLoopIterVar) { |
| 1249 | if (DVar.CKind == OMPC_private) |
| 1250 | Reason = PDSA_LoopIterVarPrivate; |
| 1251 | else if (DVar.CKind == OMPC_lastprivate) |
| 1252 | Reason = PDSA_LoopIterVarLastprivate; |
| 1253 | else |
| 1254 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1255 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1256 | Reason = PDSA_TaskVarFirstprivate; |
| 1257 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1258 | } else if (VD->isStaticLocal()) |
| 1259 | Reason = PDSA_StaticLocalVarShared; |
| 1260 | else if (VD->isStaticDataMember()) |
| 1261 | Reason = PDSA_StaticMemberShared; |
| 1262 | else if (VD->isFileVarDecl()) |
| 1263 | Reason = PDSA_GlobalVarShared; |
| 1264 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1265 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1266 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1267 | ReportHint = true; |
| 1268 | Reason = PDSA_LocalVarPrivate; |
| 1269 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1270 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1271 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1272 | << Reason << ReportHint |
| 1273 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1274 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1275 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1276 | << getOpenMPClauseName(DVar.CKind); |
| 1277 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1280 | namespace { |
| 1281 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1282 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1283 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1284 | bool ErrorFound; |
| 1285 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1286 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1287 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1288 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1289 | public: |
| 1290 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1291 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1292 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1293 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1294 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1295 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1296 | auto DVar = Stack->getTopDSA(VD, false); |
| 1297 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1298 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1299 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1300 | auto ELoc = E->getExprLoc(); |
| 1301 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1302 | // The default(none) clause requires that each variable that is referenced |
| 1303 | // in the construct, and does not have a predetermined data-sharing |
| 1304 | // attribute, must have its data-sharing attribute explicitly determined |
| 1305 | // by being listed in a data-sharing attribute clause. |
| 1306 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1307 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1308 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1309 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1310 | return; |
| 1311 | } |
| 1312 | |
| 1313 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1314 | // A list item that appears in a reduction clause of the innermost |
| 1315 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1316 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1317 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1318 | [](OpenMPDirectiveKind K) -> bool { |
| 1319 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1320 | isOpenMPWorksharingDirective(K) || |
| 1321 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1322 | }, |
| 1323 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1324 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1325 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1326 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1327 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1328 | return; |
| 1329 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1330 | |
| 1331 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1332 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1333 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1334 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1338 | for (auto *C : S->clauses()) { |
| 1339 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1340 | // for task directives. |
| 1341 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1342 | for (auto *CC : C->children()) { |
| 1343 | if (CC) |
| 1344 | Visit(CC); |
| 1345 | } |
| 1346 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1347 | } |
| 1348 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1349 | for (auto *C : S->children()) { |
| 1350 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1351 | Visit(C); |
| 1352 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1353 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1354 | |
| 1355 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1356 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1357 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1358 | return VarsWithInheritedDSA; |
| 1359 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1360 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1361 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1362 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1363 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1364 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1365 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1366 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1367 | switch (DKind) { |
| 1368 | case OMPD_parallel: { |
| 1369 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1370 | QualType KmpInt32PtrTy = |
| 1371 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1372 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1373 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1374 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1375 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1376 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1377 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1378 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | } |
| 1381 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1382 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1383 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1384 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1385 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1386 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1387 | break; |
| 1388 | } |
| 1389 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1390 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1391 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1392 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1393 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1394 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1395 | break; |
| 1396 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1397 | case OMPD_for_simd: { |
| 1398 | Sema::CapturedParamNameType Params[] = { |
| 1399 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1400 | }; |
| 1401 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1402 | Params); |
| 1403 | break; |
| 1404 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1405 | case OMPD_sections: { |
| 1406 | Sema::CapturedParamNameType Params[] = { |
| 1407 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1408 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1409 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1410 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1411 | break; |
| 1412 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1413 | case OMPD_section: { |
| 1414 | Sema::CapturedParamNameType Params[] = { |
| 1415 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1416 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1417 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1418 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1419 | break; |
| 1420 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1421 | case OMPD_single: { |
| 1422 | Sema::CapturedParamNameType Params[] = { |
| 1423 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1424 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1425 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1426 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1429 | case OMPD_master: { |
| 1430 | Sema::CapturedParamNameType Params[] = { |
| 1431 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1432 | }; |
| 1433 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1434 | Params); |
| 1435 | break; |
| 1436 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1437 | case OMPD_critical: { |
| 1438 | Sema::CapturedParamNameType Params[] = { |
| 1439 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1440 | }; |
| 1441 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1442 | Params); |
| 1443 | break; |
| 1444 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1445 | case OMPD_parallel_for: { |
| 1446 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1447 | QualType KmpInt32PtrTy = |
| 1448 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1449 | Sema::CapturedParamNameType Params[] = { |
| 1450 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1451 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1452 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1453 | }; |
| 1454 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1455 | Params); |
| 1456 | break; |
| 1457 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1458 | case OMPD_parallel_for_simd: { |
| 1459 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1460 | QualType KmpInt32PtrTy = |
| 1461 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1462 | Sema::CapturedParamNameType Params[] = { |
| 1463 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1464 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1465 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1466 | }; |
| 1467 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1468 | Params); |
| 1469 | break; |
| 1470 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1471 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1472 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1473 | QualType KmpInt32PtrTy = |
| 1474 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1475 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1476 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1477 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1478 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1479 | }; |
| 1480 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1481 | Params); |
| 1482 | break; |
| 1483 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1484 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1485 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1486 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1487 | FunctionProtoType::ExtProtoInfo EPI; |
| 1488 | EPI.Variadic = true; |
| 1489 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1490 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1491 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1492 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1493 | std::make_pair(".privates.", |
| 1494 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1495 | std::make_pair( |
| 1496 | ".copy_fn.", |
| 1497 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1498 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1499 | }; |
| 1500 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1501 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1502 | // Mark this captured region as inlined, because we don't use outlined |
| 1503 | // function directly. |
| 1504 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1505 | AlwaysInlineAttr::CreateImplicit( |
| 1506 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1507 | break; |
| 1508 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1509 | case OMPD_ordered: { |
| 1510 | Sema::CapturedParamNameType Params[] = { |
| 1511 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1512 | }; |
| 1513 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1514 | Params); |
| 1515 | break; |
| 1516 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1517 | case OMPD_atomic: { |
| 1518 | Sema::CapturedParamNameType Params[] = { |
| 1519 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1520 | }; |
| 1521 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1522 | Params); |
| 1523 | break; |
| 1524 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1525 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1526 | case OMPD_target: { |
| 1527 | Sema::CapturedParamNameType Params[] = { |
| 1528 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1529 | }; |
| 1530 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1531 | Params); |
| 1532 | break; |
| 1533 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1534 | case OMPD_teams: { |
| 1535 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1536 | QualType KmpInt32PtrTy = |
| 1537 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1538 | Sema::CapturedParamNameType Params[] = { |
| 1539 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1540 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1541 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1542 | }; |
| 1543 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1544 | Params); |
| 1545 | break; |
| 1546 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1547 | case OMPD_taskgroup: { |
| 1548 | Sema::CapturedParamNameType Params[] = { |
| 1549 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1550 | }; |
| 1551 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1552 | Params); |
| 1553 | break; |
| 1554 | } |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1555 | case OMPD_taskloop: { |
| 1556 | Sema::CapturedParamNameType Params[] = { |
| 1557 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1558 | }; |
| 1559 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1560 | Params); |
| 1561 | break; |
| 1562 | } |
Alexey Bataev | 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 | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1646 | // +------------------+-----------------+------------------------------------+ |
| 1647 | // | for | parallel | * | |
| 1648 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1649 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1650 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1651 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1652 | // | for | simd | * | |
| 1653 | // | for | sections | + | |
| 1654 | // | for | section | + | |
| 1655 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1656 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1657 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1658 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1659 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1660 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1661 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1662 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1663 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1664 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1665 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1666 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1667 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1668 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1669 | // | for | cancellation | | |
| 1670 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1671 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1672 | // | for | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1673 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1674 | // | master | parallel | * | |
| 1675 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1676 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1677 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1678 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1679 | // | master | simd | * | |
| 1680 | // | master | sections | + | |
| 1681 | // | master | section | + | |
| 1682 | // | master | single | + | |
| 1683 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1684 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1685 | // | master |parallel sections| * | |
| 1686 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1687 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1688 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1689 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1690 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1691 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1692 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1693 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1694 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1695 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1696 | // | master | cancellation | | |
| 1697 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1698 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1699 | // | master | taskloop | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1700 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1701 | // | critical | parallel | * | |
| 1702 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1703 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1704 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1705 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1706 | // | critical | simd | * | |
| 1707 | // | critical | sections | + | |
| 1708 | // | critical | section | + | |
| 1709 | // | critical | single | + | |
| 1710 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1711 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1712 | // | critical |parallel sections| * | |
| 1713 | // | critical | task | * | |
| 1714 | // | critical | taskyield | * | |
| 1715 | // | critical | barrier | + | |
| 1716 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1717 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1718 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1719 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1720 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1721 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1722 | // | critical | cancellation | | |
| 1723 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1724 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1725 | // | critical | taskloop | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1726 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1727 | // | simd | parallel | | |
| 1728 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1729 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1730 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1731 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1732 | // | simd | simd | | |
| 1733 | // | simd | sections | | |
| 1734 | // | simd | section | | |
| 1735 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1736 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1737 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1738 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1739 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1740 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1741 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1742 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1743 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1744 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1745 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1746 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1747 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1748 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1749 | // | simd | cancellation | | |
| 1750 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1751 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1752 | // | simd | taskloop | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1753 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1754 | // | for simd | parallel | | |
| 1755 | // | for simd | for | | |
| 1756 | // | for simd | for simd | | |
| 1757 | // | for simd | master | | |
| 1758 | // | for simd | critical | | |
| 1759 | // | for simd | simd | | |
| 1760 | // | for simd | sections | | |
| 1761 | // | for simd | section | | |
| 1762 | // | for simd | single | | |
| 1763 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1764 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1765 | // | for simd |parallel sections| | |
| 1766 | // | for simd | task | | |
| 1767 | // | for simd | taskyield | | |
| 1768 | // | for simd | barrier | | |
| 1769 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1770 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1771 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1772 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1773 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1774 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1775 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1776 | // | for simd | cancellation | | |
| 1777 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1778 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1779 | // | for simd | taskloop | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1780 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1781 | // | parallel for simd| parallel | | |
| 1782 | // | parallel for simd| for | | |
| 1783 | // | parallel for simd| for simd | | |
| 1784 | // | parallel for simd| master | | |
| 1785 | // | parallel for simd| critical | | |
| 1786 | // | parallel for simd| simd | | |
| 1787 | // | parallel for simd| sections | | |
| 1788 | // | parallel for simd| section | | |
| 1789 | // | parallel for simd| single | | |
| 1790 | // | parallel for simd| parallel for | | |
| 1791 | // | parallel for simd|parallel for simd| | |
| 1792 | // | parallel for simd|parallel sections| | |
| 1793 | // | parallel for simd| task | | |
| 1794 | // | parallel for simd| taskyield | | |
| 1795 | // | parallel for simd| barrier | | |
| 1796 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1797 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1798 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1799 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1800 | // | parallel for simd| atomic | | |
| 1801 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1802 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1803 | // | parallel for simd| cancellation | | |
| 1804 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1805 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1806 | // | parallel for simd| taskloop | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1807 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1808 | // | sections | parallel | * | |
| 1809 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1810 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1811 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1812 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1813 | // | sections | simd | * | |
| 1814 | // | sections | sections | + | |
| 1815 | // | sections | section | * | |
| 1816 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1817 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1818 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1819 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1820 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1821 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1822 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1823 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1824 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1825 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1826 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1827 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1828 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1829 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1830 | // | sections | cancellation | | |
| 1831 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1832 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1833 | // | sections | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1834 | // +------------------+-----------------+------------------------------------+ |
| 1835 | // | section | parallel | * | |
| 1836 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1837 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1838 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1839 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1840 | // | section | simd | * | |
| 1841 | // | section | sections | + | |
| 1842 | // | section | section | + | |
| 1843 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1844 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1845 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1846 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1847 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1848 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1849 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1850 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1851 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1852 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1853 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1854 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1855 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1856 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1857 | // | section | cancellation | | |
| 1858 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1859 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1860 | // | section | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1861 | // +------------------+-----------------+------------------------------------+ |
| 1862 | // | single | parallel | * | |
| 1863 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1864 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1865 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1866 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1867 | // | single | simd | * | |
| 1868 | // | single | sections | + | |
| 1869 | // | single | section | + | |
| 1870 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1871 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1872 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1873 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1874 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1875 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1876 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1877 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1878 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1879 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1880 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1881 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1882 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1883 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1884 | // | single | cancellation | | |
| 1885 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1886 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1887 | // | single | taskloop | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1888 | // +------------------+-----------------+------------------------------------+ |
| 1889 | // | parallel for | parallel | * | |
| 1890 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1891 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1892 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1893 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1894 | // | parallel for | simd | * | |
| 1895 | // | parallel for | sections | + | |
| 1896 | // | parallel for | section | + | |
| 1897 | // | parallel for | single | + | |
| 1898 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1899 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1900 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1901 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1902 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1903 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1904 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1905 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1906 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1907 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1908 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1909 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1910 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1911 | // | parallel for | cancellation | | |
| 1912 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1913 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1914 | // | parallel for | taskloop | * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1915 | // +------------------+-----------------+------------------------------------+ |
| 1916 | // | parallel sections| parallel | * | |
| 1917 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1918 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1919 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1920 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1921 | // | parallel sections| simd | * | |
| 1922 | // | parallel sections| sections | + | |
| 1923 | // | parallel sections| section | * | |
| 1924 | // | parallel sections| single | + | |
| 1925 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1926 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1927 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1928 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1929 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1930 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1931 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1932 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1933 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1934 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1935 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1936 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1937 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1938 | // | parallel sections| cancellation | | |
| 1939 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1940 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1941 | // | parallel sections| taskloop | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1942 | // +------------------+-----------------+------------------------------------+ |
| 1943 | // | task | parallel | * | |
| 1944 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1945 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1946 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1947 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1948 | // | task | simd | * | |
| 1949 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1950 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1951 | // | task | single | + | |
| 1952 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1953 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1954 | // | task |parallel sections| * | |
| 1955 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1956 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1957 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1958 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1959 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1960 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1961 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1962 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1963 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1964 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1965 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1966 | // | | point | ! | |
| 1967 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1968 | // | task | taskloop | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1969 | // +------------------+-----------------+------------------------------------+ |
| 1970 | // | ordered | parallel | * | |
| 1971 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1972 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1973 | // | ordered | master | * | |
| 1974 | // | ordered | critical | * | |
| 1975 | // | ordered | simd | * | |
| 1976 | // | ordered | sections | + | |
| 1977 | // | ordered | section | + | |
| 1978 | // | ordered | single | + | |
| 1979 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1980 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1981 | // | ordered |parallel sections| * | |
| 1982 | // | ordered | task | * | |
| 1983 | // | ordered | taskyield | * | |
| 1984 | // | ordered | barrier | + | |
| 1985 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1986 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1987 | // | ordered | flush | * | |
| 1988 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1989 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1990 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1991 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1992 | // | ordered | cancellation | | |
| 1993 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1994 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1995 | // | ordered | taskloop | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1996 | // +------------------+-----------------+------------------------------------+ |
| 1997 | // | atomic | parallel | | |
| 1998 | // | atomic | for | | |
| 1999 | // | atomic | for simd | | |
| 2000 | // | atomic | master | | |
| 2001 | // | atomic | critical | | |
| 2002 | // | atomic | simd | | |
| 2003 | // | atomic | sections | | |
| 2004 | // | atomic | section | | |
| 2005 | // | atomic | single | | |
| 2006 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2007 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2008 | // | atomic |parallel sections| | |
| 2009 | // | atomic | task | | |
| 2010 | // | atomic | taskyield | | |
| 2011 | // | atomic | barrier | | |
| 2012 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2013 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2014 | // | atomic | flush | | |
| 2015 | // | atomic | ordered | | |
| 2016 | // | atomic | atomic | | |
| 2017 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2018 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2019 | // | atomic | cancellation | | |
| 2020 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2021 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2022 | // | atomic | taskloop | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2023 | // +------------------+-----------------+------------------------------------+ |
| 2024 | // | target | parallel | * | |
| 2025 | // | target | for | * | |
| 2026 | // | target | for simd | * | |
| 2027 | // | target | master | * | |
| 2028 | // | target | critical | * | |
| 2029 | // | target | simd | * | |
| 2030 | // | target | sections | * | |
| 2031 | // | target | section | * | |
| 2032 | // | target | single | * | |
| 2033 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2034 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2035 | // | target |parallel sections| * | |
| 2036 | // | target | task | * | |
| 2037 | // | target | taskyield | * | |
| 2038 | // | target | barrier | * | |
| 2039 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2040 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2041 | // | target | flush | * | |
| 2042 | // | target | ordered | * | |
| 2043 | // | target | atomic | * | |
| 2044 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2045 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2046 | // | target | cancellation | | |
| 2047 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2048 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2049 | // | target | taskloop | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2050 | // +------------------+-----------------+------------------------------------+ |
| 2051 | // | teams | parallel | * | |
| 2052 | // | teams | for | + | |
| 2053 | // | teams | for simd | + | |
| 2054 | // | teams | master | + | |
| 2055 | // | teams | critical | + | |
| 2056 | // | teams | simd | + | |
| 2057 | // | teams | sections | + | |
| 2058 | // | teams | section | + | |
| 2059 | // | teams | single | + | |
| 2060 | // | teams | parallel for | * | |
| 2061 | // | teams |parallel for simd| * | |
| 2062 | // | teams |parallel sections| * | |
| 2063 | // | teams | task | + | |
| 2064 | // | teams | taskyield | + | |
| 2065 | // | teams | barrier | + | |
| 2066 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2067 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2068 | // | teams | flush | + | |
| 2069 | // | teams | ordered | + | |
| 2070 | // | teams | atomic | + | |
| 2071 | // | teams | target | + | |
| 2072 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2073 | // | teams | cancellation | | |
| 2074 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2075 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2076 | // | teams | taskloop | + | |
| 2077 | // +------------------+-----------------+------------------------------------+ |
| 2078 | // | taskloop | parallel | * | |
| 2079 | // | taskloop | for | + | |
| 2080 | // | taskloop | for simd | + | |
| 2081 | // | taskloop | master | + | |
| 2082 | // | taskloop | critical | * | |
| 2083 | // | taskloop | simd | * | |
| 2084 | // | taskloop | sections | + | |
| 2085 | // | taskloop | section | + | |
| 2086 | // | taskloop | single | + | |
| 2087 | // | taskloop | parallel for | * | |
| 2088 | // | taskloop |parallel for simd| * | |
| 2089 | // | taskloop |parallel sections| * | |
| 2090 | // | taskloop | task | * | |
| 2091 | // | taskloop | taskyield | * | |
| 2092 | // | taskloop | barrier | + | |
| 2093 | // | taskloop | taskwait | * | |
| 2094 | // | taskloop | taskgroup | * | |
| 2095 | // | taskloop | flush | * | |
| 2096 | // | taskloop | ordered | + | |
| 2097 | // | taskloop | atomic | * | |
| 2098 | // | taskloop | target | * | |
| 2099 | // | taskloop | teams | + | |
| 2100 | // | taskloop | cancellation | | |
| 2101 | // | | point | | |
| 2102 | // | taskloop | cancel | | |
| 2103 | // | taskloop | taskloop | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2104 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2105 | if (Stack->getCurScope()) { |
| 2106 | auto ParentRegion = Stack->getParentDirective(); |
| 2107 | bool NestingProhibited = false; |
| 2108 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2109 | enum { |
| 2110 | NoRecommend, |
| 2111 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2112 | ShouldBeInOrderedRegion, |
| 2113 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2114 | } Recommend = NoRecommend; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2115 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2116 | // OpenMP [2.16, Nesting of Regions] |
| 2117 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2118 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2119 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2120 | // that can appear in the simd region. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2121 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 2122 | return true; |
| 2123 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2124 | if (ParentRegion == OMPD_atomic) { |
| 2125 | // OpenMP [2.16, Nesting of Regions] |
| 2126 | // OpenMP constructs may not be nested inside an atomic region. |
| 2127 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2128 | return true; |
| 2129 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2130 | if (CurrentRegion == OMPD_section) { |
| 2131 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2132 | // Orphaned section directives are prohibited. That is, the section |
| 2133 | // directives must appear within the sections construct and must not be |
| 2134 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2135 | if (ParentRegion != OMPD_sections && |
| 2136 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2137 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2138 | << (ParentRegion != OMPD_unknown) |
| 2139 | << getOpenMPDirectiveName(ParentRegion); |
| 2140 | return true; |
| 2141 | } |
| 2142 | return false; |
| 2143 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2144 | // Allow some constructs to be orphaned (they could be used in functions, |
| 2145 | // called from OpenMP regions with the required preconditions). |
| 2146 | if (ParentRegion == OMPD_unknown) |
| 2147 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2148 | if (CurrentRegion == OMPD_cancellation_point || |
| 2149 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2150 | // OpenMP [2.16, Nesting of Regions] |
| 2151 | // A cancellation point construct for which construct-type-clause is |
| 2152 | // taskgroup must be nested inside a task construct. A cancellation |
| 2153 | // point construct for which construct-type-clause is not taskgroup must |
| 2154 | // be closely nested inside an OpenMP construct that matches the type |
| 2155 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2156 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2157 | // nested inside a task construct. A cancel construct for which |
| 2158 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2159 | // OpenMP construct that matches the type specified in |
| 2160 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2161 | NestingProhibited = |
| 2162 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2163 | (CancelRegion == OMPD_for && |
| 2164 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2165 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2166 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2167 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2168 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2169 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2170 | // OpenMP [2.16, Nesting of Regions] |
| 2171 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2172 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2173 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2174 | ParentRegion == OMPD_task || |
| 2175 | ParentRegion == OMPD_taskloop; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2176 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2177 | // OpenMP [2.16, Nesting of Regions] |
| 2178 | // A critical region may not be nested (closely or otherwise) inside a |
| 2179 | // critical region with the same name. Note that this restriction is not |
| 2180 | // sufficient to prevent deadlock. |
| 2181 | SourceLocation PreviousCriticalLoc; |
| 2182 | bool DeadLock = |
| 2183 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 2184 | OpenMPDirectiveKind K, |
| 2185 | const DeclarationNameInfo &DNI, |
| 2186 | SourceLocation Loc) |
| 2187 | ->bool { |
| 2188 | if (K == OMPD_critical && |
| 2189 | DNI.getName() == CurrentName.getName()) { |
| 2190 | PreviousCriticalLoc = Loc; |
| 2191 | return true; |
| 2192 | } else |
| 2193 | return false; |
| 2194 | }, |
| 2195 | false /* skip top directive */); |
| 2196 | if (DeadLock) { |
| 2197 | SemaRef.Diag(StartLoc, |
| 2198 | diag::err_omp_prohibited_region_critical_same_name) |
| 2199 | << CurrentName.getName(); |
| 2200 | if (PreviousCriticalLoc.isValid()) |
| 2201 | SemaRef.Diag(PreviousCriticalLoc, |
| 2202 | diag::note_omp_previous_critical_region); |
| 2203 | return true; |
| 2204 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2205 | } else if (CurrentRegion == OMPD_barrier) { |
| 2206 | // OpenMP [2.16, Nesting of Regions] |
| 2207 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2208 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2209 | NestingProhibited = |
| 2210 | isOpenMPWorksharingDirective(ParentRegion) || |
| 2211 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2212 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
| 2213 | ParentRegion == OMPD_taskloop; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2214 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2215 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2216 | // OpenMP [2.16, Nesting of Regions] |
| 2217 | // A worksharing region may not be closely nested inside a worksharing, |
| 2218 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2219 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2220 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2221 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2222 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered || |
| 2223 | ParentRegion == OMPD_taskloop; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2224 | Recommend = ShouldBeInParallelRegion; |
| 2225 | } else if (CurrentRegion == OMPD_ordered) { |
| 2226 | // OpenMP [2.16, Nesting of Regions] |
| 2227 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2228 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2229 | // An ordered region must be closely nested inside a loop region (or |
| 2230 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2231 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2232 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2233 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2234 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2235 | ParentRegion == OMPD_task || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2236 | ParentRegion == OMPD_taskloop || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2237 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2238 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2239 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2240 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 2241 | // OpenMP [2.16, Nesting of Regions] |
| 2242 | // If specified, a teams construct must be contained within a target |
| 2243 | // construct. |
| 2244 | NestingProhibited = ParentRegion != OMPD_target; |
| 2245 | Recommend = ShouldBeInTargetRegion; |
| 2246 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2247 | } |
| 2248 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 2249 | // OpenMP [2.16, Nesting of Regions] |
| 2250 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2251 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2252 | // constructs that can be closely nested in the teams region. |
| 2253 | // TODO: add distribute directive. |
| 2254 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 2255 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2256 | } |
| 2257 | if (NestingProhibited) { |
| 2258 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2259 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2260 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2261 | return true; |
| 2262 | } |
| 2263 | } |
| 2264 | return false; |
| 2265 | } |
| 2266 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2267 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2268 | ArrayRef<OMPClause *> Clauses, |
| 2269 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2270 | bool ErrorFound = false; |
| 2271 | unsigned NamedModifiersNumber = 0; |
| 2272 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2273 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2274 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2275 | for (const auto *C : Clauses) { |
| 2276 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2277 | // At most one if clause without a directive-name-modifier can appear on |
| 2278 | // the directive. |
| 2279 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2280 | if (FoundNameModifiers[CurNM]) { |
| 2281 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2282 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2283 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2284 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2285 | } else if (CurNM != OMPD_unknown) { |
| 2286 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2287 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2288 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2289 | FoundNameModifiers[CurNM] = IC; |
| 2290 | if (CurNM == OMPD_unknown) |
| 2291 | continue; |
| 2292 | // Check if the specified name modifier is allowed for the current |
| 2293 | // directive. |
| 2294 | // At most one if clause with the particular directive-name-modifier can |
| 2295 | // appear on the directive. |
| 2296 | bool MatchFound = false; |
| 2297 | for (auto NM : AllowedNameModifiers) { |
| 2298 | if (CurNM == NM) { |
| 2299 | MatchFound = true; |
| 2300 | break; |
| 2301 | } |
| 2302 | } |
| 2303 | if (!MatchFound) { |
| 2304 | S.Diag(IC->getNameModifierLoc(), |
| 2305 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2306 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2307 | ErrorFound = true; |
| 2308 | } |
| 2309 | } |
| 2310 | } |
| 2311 | // If any if clause on the directive includes a directive-name-modifier then |
| 2312 | // all if clauses on the directive must include a directive-name-modifier. |
| 2313 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2314 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2315 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2316 | diag::err_omp_no_more_if_clause); |
| 2317 | } else { |
| 2318 | std::string Values; |
| 2319 | std::string Sep(", "); |
| 2320 | unsigned AllowedCnt = 0; |
| 2321 | unsigned TotalAllowedNum = |
| 2322 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2323 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2324 | ++Cnt) { |
| 2325 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2326 | if (!FoundNameModifiers[NM]) { |
| 2327 | Values += "'"; |
| 2328 | Values += getOpenMPDirectiveName(NM); |
| 2329 | Values += "'"; |
| 2330 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2331 | Values += " or "; |
| 2332 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2333 | Values += Sep; |
| 2334 | ++AllowedCnt; |
| 2335 | } |
| 2336 | } |
| 2337 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2338 | diag::err_omp_unnamed_if_clause) |
| 2339 | << (TotalAllowedNum > 1) << Values; |
| 2340 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2341 | for (auto Loc : NameModifierLoc) { |
| 2342 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2343 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2344 | ErrorFound = true; |
| 2345 | } |
| 2346 | return ErrorFound; |
| 2347 | } |
| 2348 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2349 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2350 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2351 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2352 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2353 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2354 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2355 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2356 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2357 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2358 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2359 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2360 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2361 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2362 | if (AStmt) { |
| 2363 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2364 | |
| 2365 | // Check default data sharing attributes for referenced variables. |
| 2366 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2367 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2368 | if (DSAChecker.isErrorFound()) |
| 2369 | return StmtError(); |
| 2370 | // Generate list of implicitly defined firstprivate variables. |
| 2371 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2372 | |
| 2373 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2374 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2375 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2376 | SourceLocation(), SourceLocation())) { |
| 2377 | ClausesWithImplicit.push_back(Implicit); |
| 2378 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2379 | DSAChecker.getImplicitFirstprivate().size(); |
| 2380 | } else |
| 2381 | ErrorFound = true; |
| 2382 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2383 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2384 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2385 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2386 | switch (Kind) { |
| 2387 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2388 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2389 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2390 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2391 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2392 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2393 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2394 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2395 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2396 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2397 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2398 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2399 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2400 | case OMPD_for_simd: |
| 2401 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2402 | EndLoc, VarsWithInheritedDSA); |
| 2403 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2404 | case OMPD_sections: |
| 2405 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2406 | EndLoc); |
| 2407 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2408 | case OMPD_section: |
| 2409 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2410 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2411 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2412 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2413 | case OMPD_single: |
| 2414 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2415 | EndLoc); |
| 2416 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2417 | case OMPD_master: |
| 2418 | assert(ClausesWithImplicit.empty() && |
| 2419 | "No clauses are allowed for 'omp master' directive"); |
| 2420 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2421 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2422 | case OMPD_critical: |
| 2423 | assert(ClausesWithImplicit.empty() && |
| 2424 | "No clauses are allowed for 'omp critical' directive"); |
| 2425 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2426 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2427 | case OMPD_parallel_for: |
| 2428 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2429 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2430 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2431 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2432 | case OMPD_parallel_for_simd: |
| 2433 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2434 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2435 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2436 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2437 | case OMPD_parallel_sections: |
| 2438 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2439 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2440 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2441 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2442 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2443 | Res = |
| 2444 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2445 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2446 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2447 | case OMPD_taskyield: |
| 2448 | assert(ClausesWithImplicit.empty() && |
| 2449 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2450 | assert(AStmt == nullptr && |
| 2451 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2452 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2453 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2454 | case OMPD_barrier: |
| 2455 | assert(ClausesWithImplicit.empty() && |
| 2456 | "No clauses are allowed for 'omp barrier' directive"); |
| 2457 | assert(AStmt == nullptr && |
| 2458 | "No associated statement allowed for 'omp barrier' directive"); |
| 2459 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2460 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2461 | case OMPD_taskwait: |
| 2462 | assert(ClausesWithImplicit.empty() && |
| 2463 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2464 | assert(AStmt == nullptr && |
| 2465 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2466 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2467 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2468 | case OMPD_taskgroup: |
| 2469 | assert(ClausesWithImplicit.empty() && |
| 2470 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2471 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2472 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2473 | case OMPD_flush: |
| 2474 | assert(AStmt == nullptr && |
| 2475 | "No associated statement allowed for 'omp flush' directive"); |
| 2476 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2477 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2478 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2479 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2480 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2481 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2482 | case OMPD_atomic: |
| 2483 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2484 | EndLoc); |
| 2485 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2486 | case OMPD_teams: |
| 2487 | Res = |
| 2488 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2489 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2490 | case OMPD_target: |
| 2491 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2492 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2493 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2494 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2495 | case OMPD_cancellation_point: |
| 2496 | assert(ClausesWithImplicit.empty() && |
| 2497 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2498 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2499 | "cancellation point' directive"); |
| 2500 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2501 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2502 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2503 | assert(AStmt == nullptr && |
| 2504 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2505 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2506 | CancelRegion); |
| 2507 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2508 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2509 | case OMPD_target_data: |
| 2510 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2511 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2512 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2513 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2514 | case OMPD_taskloop: |
| 2515 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2516 | EndLoc, VarsWithInheritedDSA); |
| 2517 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2518 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2519 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2520 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2521 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2522 | llvm_unreachable("Unknown OpenMP directive"); |
| 2523 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2524 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2525 | for (auto P : VarsWithInheritedDSA) { |
| 2526 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2527 | << P.first << P.second->getSourceRange(); |
| 2528 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2529 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2530 | |
| 2531 | if (!AllowedNameModifiers.empty()) |
| 2532 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2533 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2534 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2535 | if (ErrorFound) |
| 2536 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2537 | return Res; |
| 2538 | } |
| 2539 | |
| 2540 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2541 | Stmt *AStmt, |
| 2542 | SourceLocation StartLoc, |
| 2543 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2544 | if (!AStmt) |
| 2545 | return StmtError(); |
| 2546 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2547 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2548 | // 1.2.2 OpenMP Language Terminology |
| 2549 | // Structured block - An executable statement with a single entry at the |
| 2550 | // top and a single exit at the bottom. |
| 2551 | // The point of exit cannot be a branch out of the structured block. |
| 2552 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2553 | CS->getCapturedDecl()->setNothrow(); |
| 2554 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2555 | getCurFunction()->setHasBranchProtectedScope(); |
| 2556 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2557 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2558 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2559 | } |
| 2560 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2561 | namespace { |
| 2562 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2563 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2564 | /// for IR generation. |
| 2565 | class OpenMPIterationSpaceChecker { |
| 2566 | /// \brief Reference to Sema. |
| 2567 | Sema &SemaRef; |
| 2568 | /// \brief A location for diagnostics (when there is no some better location). |
| 2569 | SourceLocation DefaultLoc; |
| 2570 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2571 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2572 | /// \brief A source location for referring to loop init later. |
| 2573 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2574 | /// \brief A source location for referring to condition later. |
| 2575 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2576 | /// \brief A source location for referring to increment later. |
| 2577 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2578 | /// \brief Loop variable. |
| 2579 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2580 | /// \brief Reference to loop variable. |
| 2581 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2582 | /// \brief Lower bound (initializer for the var). |
| 2583 | Expr *LB; |
| 2584 | /// \brief Upper bound. |
| 2585 | Expr *UB; |
| 2586 | /// \brief Loop step (increment). |
| 2587 | Expr *Step; |
| 2588 | /// \brief This flag is true when condition is one of: |
| 2589 | /// Var < UB |
| 2590 | /// Var <= UB |
| 2591 | /// UB > Var |
| 2592 | /// UB >= Var |
| 2593 | bool TestIsLessOp; |
| 2594 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2595 | bool TestIsStrictOp; |
| 2596 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2597 | bool SubtractStep; |
| 2598 | |
| 2599 | public: |
| 2600 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2601 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2602 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2603 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2604 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2605 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2606 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2607 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2608 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2609 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2610 | /// for less/greater and for strict/non-strict comparison. |
| 2611 | bool CheckCond(Expr *S); |
| 2612 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2613 | /// does not conform, otherwise save loop step (#Step). |
| 2614 | bool CheckInc(Expr *S); |
| 2615 | /// \brief Return the loop counter variable. |
| 2616 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2617 | /// \brief Return the reference expression to loop counter variable. |
| 2618 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2619 | /// \brief Source range of the loop init. |
| 2620 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2621 | /// \brief Source range of the loop condition. |
| 2622 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2623 | /// \brief Source range of the loop increment. |
| 2624 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2625 | /// \brief True if the step should be subtracted. |
| 2626 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2627 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2628 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2629 | /// \brief Build the precondition expression for the loops. |
| 2630 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2631 | /// \brief Build reference expression to the counter be used for codegen. |
| 2632 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2633 | /// \brief Build reference expression to the private counter be used for |
| 2634 | /// codegen. |
| 2635 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2636 | /// \brief Build initization of the counter be used for codegen. |
| 2637 | Expr *BuildCounterInit() const; |
| 2638 | /// \brief Build step of the counter be used for codegen. |
| 2639 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2640 | /// \brief Return true if any expression is dependent. |
| 2641 | bool Dependent() const; |
| 2642 | |
| 2643 | private: |
| 2644 | /// \brief Check the right-hand side of an assignment in the increment |
| 2645 | /// expression. |
| 2646 | bool CheckIncRHS(Expr *RHS); |
| 2647 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2648 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2649 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2650 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2651 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2652 | /// \brief Helper to set loop increment. |
| 2653 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2654 | }; |
| 2655 | |
| 2656 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2657 | if (!Var) { |
| 2658 | assert(!LB && !UB && !Step); |
| 2659 | return false; |
| 2660 | } |
| 2661 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2662 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2663 | } |
| 2664 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2665 | template <typename T> |
| 2666 | static T *getExprAsWritten(T *E) { |
| 2667 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2668 | E = ExprTemp->getSubExpr(); |
| 2669 | |
| 2670 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2671 | E = MTE->GetTemporaryExpr(); |
| 2672 | |
| 2673 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2674 | E = Binder->getSubExpr(); |
| 2675 | |
| 2676 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2677 | E = ICE->getSubExprAsWritten(); |
| 2678 | return E->IgnoreParens(); |
| 2679 | } |
| 2680 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2681 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2682 | DeclRefExpr *NewVarRefExpr, |
| 2683 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2684 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2685 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2686 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2687 | if (!NewVar || !NewLB) |
| 2688 | return true; |
| 2689 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2690 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2691 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2692 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2693 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2694 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2695 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2696 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2697 | LB = NewLB; |
| 2698 | return false; |
| 2699 | } |
| 2700 | |
| 2701 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2702 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2703 | // State consistency checking to ensure correct usage. |
| 2704 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2705 | !TestIsLessOp && !TestIsStrictOp); |
| 2706 | if (!NewUB) |
| 2707 | return true; |
| 2708 | UB = NewUB; |
| 2709 | TestIsLessOp = LessOp; |
| 2710 | TestIsStrictOp = StrictOp; |
| 2711 | ConditionSrcRange = SR; |
| 2712 | ConditionLoc = SL; |
| 2713 | return false; |
| 2714 | } |
| 2715 | |
| 2716 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2717 | // State consistency checking to ensure correct usage. |
| 2718 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2719 | if (!NewStep) |
| 2720 | return true; |
| 2721 | if (!NewStep->isValueDependent()) { |
| 2722 | // Check that the step is integer expression. |
| 2723 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2724 | ExprResult Val = |
| 2725 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2726 | if (Val.isInvalid()) |
| 2727 | return true; |
| 2728 | NewStep = Val.get(); |
| 2729 | |
| 2730 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2731 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2732 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2733 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2734 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2735 | // the loop. |
| 2736 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2737 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2738 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2739 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2740 | // the loop. |
| 2741 | llvm::APSInt Result; |
| 2742 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2743 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2744 | bool IsConstNeg = |
| 2745 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2746 | bool IsConstPos = |
| 2747 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2748 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2749 | if (UB && (IsConstZero || |
| 2750 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2751 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2752 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2753 | diag::err_omp_loop_incr_not_compatible) |
| 2754 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2755 | SemaRef.Diag(ConditionLoc, |
| 2756 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2757 | << TestIsLessOp << ConditionSrcRange; |
| 2758 | return true; |
| 2759 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2760 | if (TestIsLessOp == Subtract) { |
| 2761 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2762 | NewStep).get(); |
| 2763 | Subtract = !Subtract; |
| 2764 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
| 2767 | Step = NewStep; |
| 2768 | SubtractStep = Subtract; |
| 2769 | return false; |
| 2770 | } |
| 2771 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2772 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2773 | // Check init-expr for canonical loop form and save loop counter |
| 2774 | // variable - #Var and its initialization value - #LB. |
| 2775 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2776 | // var = lb |
| 2777 | // integer-type var = lb |
| 2778 | // random-access-iterator-type var = lb |
| 2779 | // pointer-type var = lb |
| 2780 | // |
| 2781 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2782 | if (EmitDiags) { |
| 2783 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2784 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2785 | return true; |
| 2786 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2787 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2788 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2789 | S = E->IgnoreParens(); |
| 2790 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2791 | if (BO->getOpcode() == BO_Assign) |
| 2792 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2793 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2794 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2795 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2796 | if (DS->isSingleDecl()) { |
| 2797 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2798 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2799 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2800 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2801 | SemaRef.Diag(S->getLocStart(), |
| 2802 | diag::ext_omp_loop_not_canonical_init) |
| 2803 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2804 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2805 | } |
| 2806 | } |
| 2807 | } |
| 2808 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2809 | if (CE->getOperator() == OO_Equal) |
| 2810 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2811 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2812 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2813 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2814 | if (EmitDiags) { |
| 2815 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2816 | << S->getSourceRange(); |
| 2817 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2818 | return true; |
| 2819 | } |
| 2820 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2821 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2822 | /// variable (which may be the loop variable) if possible. |
| 2823 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2824 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2825 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2826 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2827 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2828 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2829 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2830 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2831 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2832 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2833 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2834 | if (!DRE) |
| 2835 | return nullptr; |
| 2836 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2837 | } |
| 2838 | |
| 2839 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2840 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2841 | // less/greater and for strict/non-strict comparison. |
| 2842 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2843 | // var relational-op b |
| 2844 | // b relational-op var |
| 2845 | // |
| 2846 | if (!S) { |
| 2847 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2848 | return true; |
| 2849 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2850 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2851 | SourceLocation CondLoc = S->getLocStart(); |
| 2852 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2853 | if (BO->isRelationalOp()) { |
| 2854 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2855 | return SetUB(BO->getRHS(), |
| 2856 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2857 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2858 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2859 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2860 | return SetUB(BO->getLHS(), |
| 2861 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2862 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2863 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2864 | } |
| 2865 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2866 | if (CE->getNumArgs() == 2) { |
| 2867 | auto Op = CE->getOperator(); |
| 2868 | switch (Op) { |
| 2869 | case OO_Greater: |
| 2870 | case OO_GreaterEqual: |
| 2871 | case OO_Less: |
| 2872 | case OO_LessEqual: |
| 2873 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2874 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2875 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2876 | CE->getOperatorLoc()); |
| 2877 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2878 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2879 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2880 | CE->getOperatorLoc()); |
| 2881 | break; |
| 2882 | default: |
| 2883 | break; |
| 2884 | } |
| 2885 | } |
| 2886 | } |
| 2887 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2888 | << S->getSourceRange() << Var; |
| 2889 | return true; |
| 2890 | } |
| 2891 | |
| 2892 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2893 | // RHS of canonical loop form increment can be: |
| 2894 | // var + incr |
| 2895 | // incr + var |
| 2896 | // var - incr |
| 2897 | // |
| 2898 | RHS = RHS->IgnoreParenImpCasts(); |
| 2899 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2900 | if (BO->isAdditiveOp()) { |
| 2901 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2902 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2903 | return SetStep(BO->getRHS(), !IsAdd); |
| 2904 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2905 | return SetStep(BO->getLHS(), false); |
| 2906 | } |
| 2907 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2908 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2909 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2910 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2911 | return SetStep(CE->getArg(1), !IsAdd); |
| 2912 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2913 | return SetStep(CE->getArg(0), false); |
| 2914 | } |
| 2915 | } |
| 2916 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2917 | << RHS->getSourceRange() << Var; |
| 2918 | return true; |
| 2919 | } |
| 2920 | |
| 2921 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2922 | // Check incr-expr for canonical loop form and return true if it |
| 2923 | // does not conform. |
| 2924 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2925 | // ++var |
| 2926 | // var++ |
| 2927 | // --var |
| 2928 | // var-- |
| 2929 | // var += incr |
| 2930 | // var -= incr |
| 2931 | // var = var + incr |
| 2932 | // var = incr + var |
| 2933 | // var = var - incr |
| 2934 | // |
| 2935 | if (!S) { |
| 2936 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2937 | return true; |
| 2938 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2939 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2940 | S = S->IgnoreParens(); |
| 2941 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2942 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2943 | return SetStep( |
| 2944 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2945 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2946 | false); |
| 2947 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2948 | switch (BO->getOpcode()) { |
| 2949 | case BO_AddAssign: |
| 2950 | case BO_SubAssign: |
| 2951 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2952 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2953 | break; |
| 2954 | case BO_Assign: |
| 2955 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2956 | return CheckIncRHS(BO->getRHS()); |
| 2957 | break; |
| 2958 | default: |
| 2959 | break; |
| 2960 | } |
| 2961 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2962 | switch (CE->getOperator()) { |
| 2963 | case OO_PlusPlus: |
| 2964 | case OO_MinusMinus: |
| 2965 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2966 | return SetStep( |
| 2967 | SemaRef.ActOnIntegerConstant( |
| 2968 | CE->getLocStart(), |
| 2969 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2970 | false); |
| 2971 | break; |
| 2972 | case OO_PlusEqual: |
| 2973 | case OO_MinusEqual: |
| 2974 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2975 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2976 | break; |
| 2977 | case OO_Equal: |
| 2978 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2979 | return CheckIncRHS(CE->getArg(1)); |
| 2980 | break; |
| 2981 | default: |
| 2982 | break; |
| 2983 | } |
| 2984 | } |
| 2985 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2986 | << S->getSourceRange() << Var; |
| 2987 | return true; |
| 2988 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2989 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2990 | namespace { |
| 2991 | // Transform variables declared in GNU statement expressions to new ones to |
| 2992 | // avoid crash on codegen. |
| 2993 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 2994 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 2995 | |
| 2996 | public: |
| 2997 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 2998 | |
| 2999 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 3000 | if (auto *VD = cast<VarDecl>(D)) |
| 3001 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 3002 | !isa<ImplicitParamDecl>(D)) { |
| 3003 | auto *NewVD = VarDecl::Create( |
| 3004 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 3005 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 3006 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 3007 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 3008 | NewVD->setInit(VD->getInit()); |
| 3009 | NewVD->setInitStyle(VD->getInitStyle()); |
| 3010 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 3011 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 3012 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 3013 | NewVD->setConstexpr(VD->isConstexpr()); |
| 3014 | NewVD->setInitCapture(VD->isInitCapture()); |
| 3015 | NewVD->setPreviousDeclInSameBlockScope( |
| 3016 | VD->isPreviousDeclInSameBlockScope()); |
| 3017 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3018 | if (VD->hasAttrs()) |
| 3019 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3020 | transformedLocalDecl(VD, NewVD); |
| 3021 | return NewVD; |
| 3022 | } |
| 3023 | return BaseTransform::TransformDefinition(Loc, D); |
| 3024 | } |
| 3025 | |
| 3026 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 3027 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 3028 | if (E->getDecl() != NewD) { |
| 3029 | NewD->setReferenced(); |
| 3030 | NewD->markUsed(SemaRef.Context); |
| 3031 | return DeclRefExpr::Create( |
| 3032 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 3033 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 3034 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 3035 | } |
| 3036 | return BaseTransform::TransformDeclRefExpr(E); |
| 3037 | } |
| 3038 | }; |
| 3039 | } |
| 3040 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3041 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3042 | Expr * |
| 3043 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 3044 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3045 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3046 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3047 | auto VarType = Var->getType().getNonReferenceType(); |
| 3048 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3049 | SemaRef.getLangOpts().CPlusPlus) { |
| 3050 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3051 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3052 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 3053 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 3054 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 3055 | if (!Upper || !Lower) |
| 3056 | return nullptr; |
| 3057 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 3058 | Sema::AA_Converting, |
| 3059 | /*AllowExplicit=*/true) |
| 3060 | .get(); |
| 3061 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 3062 | Sema::AA_Converting, |
| 3063 | /*AllowExplicit=*/true) |
| 3064 | .get(); |
| 3065 | if (!Upper || !Lower) |
| 3066 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3067 | |
| 3068 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3069 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3070 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3071 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3072 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3073 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3074 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3075 | return nullptr; |
| 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | if (!Diff.isUsable()) |
| 3080 | return nullptr; |
| 3081 | |
| 3082 | // Upper - Lower [- 1] |
| 3083 | if (TestIsStrictOp) |
| 3084 | Diff = SemaRef.BuildBinOp( |
| 3085 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3086 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3087 | if (!Diff.isUsable()) |
| 3088 | return nullptr; |
| 3089 | |
| 3090 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3091 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3092 | if (NewStep.isInvalid()) |
| 3093 | return nullptr; |
| 3094 | NewStep = SemaRef.PerformImplicitConversion( |
| 3095 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3096 | /*AllowExplicit=*/true); |
| 3097 | if (NewStep.isInvalid()) |
| 3098 | return nullptr; |
| 3099 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3100 | if (!Diff.isUsable()) |
| 3101 | return nullptr; |
| 3102 | |
| 3103 | // Parentheses (for dumping/debugging purposes only). |
| 3104 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3105 | if (!Diff.isUsable()) |
| 3106 | return nullptr; |
| 3107 | |
| 3108 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3109 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 3110 | if (NewStep.isInvalid()) |
| 3111 | return nullptr; |
| 3112 | NewStep = SemaRef.PerformImplicitConversion( |
| 3113 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 3114 | /*AllowExplicit=*/true); |
| 3115 | if (NewStep.isInvalid()) |
| 3116 | return nullptr; |
| 3117 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3118 | if (!Diff.isUsable()) |
| 3119 | return nullptr; |
| 3120 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3121 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3122 | QualType Type = Diff.get()->getType(); |
| 3123 | auto &C = SemaRef.Context; |
| 3124 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3125 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3126 | if (!Type->isIntegerType() || UseVarType) { |
| 3127 | unsigned NewSize = |
| 3128 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3129 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3130 | : Type->hasSignedIntegerRepresentation(); |
| 3131 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 3132 | Diff = SemaRef.PerformImplicitConversion( |
| 3133 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3134 | if (!Diff.isUsable()) |
| 3135 | return nullptr; |
| 3136 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3137 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3138 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3139 | if (NewSize != C.getTypeSize(Type)) { |
| 3140 | if (NewSize < C.getTypeSize(Type)) { |
| 3141 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3142 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3143 | << InitSrcRange << ConditionSrcRange; |
| 3144 | } |
| 3145 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3146 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3147 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3148 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3149 | Sema::AA_Converting, true); |
| 3150 | if (!Diff.isUsable()) |
| 3151 | return nullptr; |
| 3152 | } |
| 3153 | } |
| 3154 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3155 | return Diff.get(); |
| 3156 | } |
| 3157 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3158 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 3159 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3160 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3161 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3162 | TransformToNewDefs Transform(SemaRef); |
| 3163 | |
| 3164 | auto NewLB = Transform.TransformExpr(LB); |
| 3165 | auto NewUB = Transform.TransformExpr(UB); |
| 3166 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3167 | return Cond; |
| 3168 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 3169 | Sema::AA_Converting, |
| 3170 | /*AllowExplicit=*/true); |
| 3171 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 3172 | Sema::AA_Converting, |
| 3173 | /*AllowExplicit=*/true); |
| 3174 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 3175 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3176 | auto CondExpr = SemaRef.BuildBinOp( |
| 3177 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3178 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3179 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3180 | if (CondExpr.isUsable()) { |
| 3181 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3182 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3183 | /*AllowExplicit=*/true); |
| 3184 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3185 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3186 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3187 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3188 | } |
| 3189 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3190 | /// \brief Build reference expression to the counter be used for codegen. |
| 3191 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3192 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 3193 | DefaultLoc); |
| 3194 | } |
| 3195 | |
| 3196 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 3197 | if (Var && !Var->isInvalidDecl()) { |
| 3198 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3199 | auto *PrivateVar = |
| 3200 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 3201 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3202 | if (PrivateVar->isInvalidDecl()) |
| 3203 | return nullptr; |
| 3204 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3205 | } |
| 3206 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3207 | } |
| 3208 | |
| 3209 | /// \brief Build initization of the counter be used for codegen. |
| 3210 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3211 | |
| 3212 | /// \brief Build step of the counter be used for codegen. |
| 3213 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3214 | |
| 3215 | /// \brief Iteration space of a single for loop. |
| 3216 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3217 | /// \brief Condition of the loop. |
| 3218 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3219 | /// \brief This expression calculates the number of iterations in the loop. |
| 3220 | /// It is always possible to calculate it before starting the loop. |
| 3221 | Expr *NumIterations; |
| 3222 | /// \brief The loop counter variable. |
| 3223 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3224 | /// \brief Private loop counter variable. |
| 3225 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3226 | /// \brief This is initializer for the initial value of #CounterVar. |
| 3227 | Expr *CounterInit; |
| 3228 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3229 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 3230 | Expr *CounterStep; |
| 3231 | /// \brief Should step be subtracted? |
| 3232 | bool Subtract; |
| 3233 | /// \brief Source range of the loop init. |
| 3234 | SourceRange InitSrcRange; |
| 3235 | /// \brief Source range of the loop condition. |
| 3236 | SourceRange CondSrcRange; |
| 3237 | /// \brief Source range of the loop increment. |
| 3238 | SourceRange IncSrcRange; |
| 3239 | }; |
| 3240 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3241 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3242 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3243 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3244 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3245 | assert(Init && "Expected loop in canonical form."); |
| 3246 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 3247 | if (CollapseIteration > 0 && |
| 3248 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3249 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 3250 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3251 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 3252 | } |
| 3253 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 3254 | } |
| 3255 | } |
| 3256 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3257 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3258 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3259 | static bool CheckOpenMPIterationSpace( |
| 3260 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3261 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3262 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3263 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3264 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3265 | // OpenMP [2.6, Canonical Loop Form] |
| 3266 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3267 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3268 | if (!For) { |
| 3269 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3270 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3271 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3272 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3273 | if (NestedLoopCount > 1) { |
| 3274 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3275 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3276 | diag::note_omp_collapse_ordered_expr) |
| 3277 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3278 | << OrderedLoopCountExpr->getSourceRange(); |
| 3279 | else if (CollapseLoopCountExpr) |
| 3280 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3281 | diag::note_omp_collapse_ordered_expr) |
| 3282 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3283 | else |
| 3284 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3285 | diag::note_omp_collapse_ordered_expr) |
| 3286 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3287 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3288 | return true; |
| 3289 | } |
| 3290 | assert(For->getBody()); |
| 3291 | |
| 3292 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3293 | |
| 3294 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3295 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3296 | if (ISC.CheckInit(Init)) { |
| 3297 | return true; |
| 3298 | } |
| 3299 | |
| 3300 | bool HasErrors = false; |
| 3301 | |
| 3302 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3303 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3304 | |
| 3305 | // OpenMP [2.6, Canonical Loop Form] |
| 3306 | // Var is one of the following: |
| 3307 | // A variable of signed or unsigned integer type. |
| 3308 | // For C++, a variable of a random access iterator type. |
| 3309 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3310 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3311 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3312 | !VarType->isPointerType() && |
| 3313 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3314 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3315 | << SemaRef.getLangOpts().CPlusPlus; |
| 3316 | HasErrors = true; |
| 3317 | } |
| 3318 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3319 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3320 | // Construct |
| 3321 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3322 | // parallel for construct is (are) private. |
| 3323 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3324 | // with just one associated for-loop is linear with a constant-linear-step |
| 3325 | // that is the increment of the associated for-loop. |
| 3326 | // Exclude loop var from the list of variables with implicitly defined data |
| 3327 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3328 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3329 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3330 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3331 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3332 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3333 | // with just one associated for-loop may be listed in a linear clause with a |
| 3334 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3335 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3336 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3337 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3338 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3339 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3340 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3341 | auto PredeterminedCKind = |
| 3342 | isOpenMPSimdDirective(DKind) |
| 3343 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3344 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3345 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3346 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3347 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) && |
| 3348 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3349 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate && |
| 3350 | DVar.CKind != OMPC_threadprivate)) && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3351 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 3352 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3353 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3354 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3355 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3356 | if (DVar.RefExpr == nullptr) |
| 3357 | DVar.CKind = PredeterminedCKind; |
| 3358 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3359 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3360 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3361 | // Make the loop iteration variable private (for worksharing constructs), |
| 3362 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3363 | // lastprivate (for simd directives with several collapsed or ordered |
| 3364 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3365 | if (DVar.CKind == OMPC_unknown) |
| 3366 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3367 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3368 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3369 | } |
| 3370 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3371 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3372 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3373 | // Check test-expr. |
| 3374 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3375 | |
| 3376 | // Check incr-expr. |
| 3377 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3378 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3379 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3380 | return HasErrors; |
| 3381 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3382 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3383 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3384 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3385 | DSA.getCurScope(), |
| 3386 | (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3387 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3388 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3389 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3390 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3391 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3392 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3393 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3394 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3395 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3396 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3397 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3398 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3399 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3400 | ResultIterSpace.CounterInit == nullptr || |
| 3401 | ResultIterSpace.CounterStep == nullptr); |
| 3402 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3403 | return HasErrors; |
| 3404 | } |
| 3405 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3406 | /// \brief Build 'VarRef = Start. |
| 3407 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3408 | ExprResult VarRef, ExprResult Start) { |
| 3409 | TransformToNewDefs Transform(SemaRef); |
| 3410 | // Build 'VarRef = Start. |
| 3411 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3412 | if (NewStart.isInvalid()) |
| 3413 | return ExprError(); |
| 3414 | NewStart = SemaRef.PerformImplicitConversion( |
| 3415 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3416 | Sema::AA_Converting, |
| 3417 | /*AllowExplicit=*/true); |
| 3418 | if (NewStart.isInvalid()) |
| 3419 | return ExprError(); |
| 3420 | NewStart = SemaRef.PerformImplicitConversion( |
| 3421 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3422 | /*AllowExplicit=*/true); |
| 3423 | if (!NewStart.isUsable()) |
| 3424 | return ExprError(); |
| 3425 | |
| 3426 | auto Init = |
| 3427 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3428 | return Init; |
| 3429 | } |
| 3430 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3431 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3432 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3433 | SourceLocation Loc, ExprResult VarRef, |
| 3434 | ExprResult Start, ExprResult Iter, |
| 3435 | ExprResult Step, bool Subtract) { |
| 3436 | // Add parentheses (for debugging purposes only). |
| 3437 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3438 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3439 | !Step.isUsable()) |
| 3440 | return ExprError(); |
| 3441 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3442 | TransformToNewDefs Transform(SemaRef); |
| 3443 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3444 | if (NewStep.isInvalid()) |
| 3445 | return ExprError(); |
| 3446 | NewStep = SemaRef.PerformImplicitConversion( |
| 3447 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3448 | Sema::AA_Converting, |
| 3449 | /*AllowExplicit=*/true); |
| 3450 | if (NewStep.isInvalid()) |
| 3451 | return ExprError(); |
| 3452 | ExprResult Update = |
| 3453 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3454 | if (!Update.isUsable()) |
| 3455 | return ExprError(); |
| 3456 | |
| 3457 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3458 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3459 | if (NewStart.isInvalid()) |
| 3460 | return ExprError(); |
| 3461 | NewStart = SemaRef.PerformImplicitConversion( |
| 3462 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3463 | Sema::AA_Converting, |
| 3464 | /*AllowExplicit=*/true); |
| 3465 | if (NewStart.isInvalid()) |
| 3466 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3467 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3468 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3469 | if (!Update.isUsable()) |
| 3470 | return ExprError(); |
| 3471 | |
| 3472 | Update = SemaRef.PerformImplicitConversion( |
| 3473 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3474 | if (!Update.isUsable()) |
| 3475 | return ExprError(); |
| 3476 | |
| 3477 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3478 | return Update; |
| 3479 | } |
| 3480 | |
| 3481 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3482 | /// bits. |
| 3483 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3484 | Sema &SemaRef) { |
| 3485 | if (E == nullptr) |
| 3486 | return ExprError(); |
| 3487 | auto &C = SemaRef.Context; |
| 3488 | QualType OldType = E->getType(); |
| 3489 | unsigned HasBits = C.getTypeSize(OldType); |
| 3490 | if (HasBits >= Bits) |
| 3491 | return ExprResult(E); |
| 3492 | // OK to convert to signed, because new type has more bits than old. |
| 3493 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3494 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3495 | true); |
| 3496 | } |
| 3497 | |
| 3498 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3499 | /// into \a Bits bits. |
| 3500 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3501 | if (E == nullptr) |
| 3502 | return false; |
| 3503 | llvm::APSInt Result; |
| 3504 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3505 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3506 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | /// \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] | 3510 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3511 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3512 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3513 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3514 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3515 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3516 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3517 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3518 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3519 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3520 | // Found 'collapse' clause - calculate collapse number. |
| 3521 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3522 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3523 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3524 | } |
| 3525 | if (OrderedLoopCountExpr) { |
| 3526 | // Found 'ordered' clause - calculate collapse number. |
| 3527 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3528 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3529 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3530 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3531 | diag::err_omp_wrong_ordered_loop_count) |
| 3532 | << OrderedLoopCountExpr->getSourceRange(); |
| 3533 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3534 | diag::note_collapse_loop_count) |
| 3535 | << CollapseLoopCountExpr->getSourceRange(); |
| 3536 | } |
| 3537 | NestedLoopCount = Result.getLimitedValue(); |
| 3538 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3539 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3540 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3541 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3542 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3543 | IterSpaces.resize(NestedLoopCount); |
| 3544 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3545 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3546 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3547 | NestedLoopCount, CollapseLoopCountExpr, |
| 3548 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3549 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3550 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3551 | // 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] | 3552 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3553 | // All loops associated with the construct must be perfectly nested; that |
| 3554 | // is, there must be no intervening code nor any OpenMP directive between |
| 3555 | // any two loops. |
| 3556 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3557 | } |
| 3558 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3559 | Built.clear(/* size */ NestedLoopCount); |
| 3560 | |
| 3561 | if (SemaRef.CurContext->isDependentContext()) |
| 3562 | return NestedLoopCount; |
| 3563 | |
| 3564 | // An example of what is generated for the following code: |
| 3565 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3566 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3567 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3568 | // for (k = 0; k < NK; ++k) |
| 3569 | // for (j = J0; j < NJ; j+=2) { |
| 3570 | // <loop body> |
| 3571 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3572 | // |
| 3573 | // We generate the code below. |
| 3574 | // Note: the loop body may be outlined in CodeGen. |
| 3575 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3576 | // iterations and operator+= to calculate counter value. |
| 3577 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3578 | // or i64 is currently supported). |
| 3579 | // |
| 3580 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3581 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3582 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3583 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3584 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3585 | // <loop body (using local i and j)> |
| 3586 | // } |
| 3587 | // i = NI; // assign final values of counters |
| 3588 | // j = NJ; |
| 3589 | // |
| 3590 | |
| 3591 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3592 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3593 | // Precondition tests if there is at least one iteration (all conditions are |
| 3594 | // true). |
| 3595 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3596 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3597 | ExprResult LastIteration32 = WidenIterationCount( |
| 3598 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3599 | N0->IgnoreImpCasts(), N0->getType(), |
| 3600 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3601 | .get(), |
| 3602 | SemaRef); |
| 3603 | ExprResult LastIteration64 = WidenIterationCount( |
| 3604 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3605 | N0->IgnoreImpCasts(), N0->getType(), |
| 3606 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3607 | .get(), |
| 3608 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3609 | |
| 3610 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3611 | return NestedLoopCount; |
| 3612 | |
| 3613 | auto &C = SemaRef.Context; |
| 3614 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3615 | |
| 3616 | Scope *CurScope = DSA.getCurScope(); |
| 3617 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3618 | if (PreCond.isUsable()) { |
| 3619 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3620 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3621 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3622 | auto N = IterSpaces[Cnt].NumIterations; |
| 3623 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3624 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3625 | LastIteration32 = SemaRef.BuildBinOp( |
| 3626 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3627 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3628 | Sema::AA_Converting, |
| 3629 | /*AllowExplicit=*/true) |
| 3630 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3631 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3632 | LastIteration64 = SemaRef.BuildBinOp( |
| 3633 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3634 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3635 | Sema::AA_Converting, |
| 3636 | /*AllowExplicit=*/true) |
| 3637 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | // Choose either the 32-bit or 64-bit version. |
| 3641 | ExprResult LastIteration = LastIteration64; |
| 3642 | if (LastIteration32.isUsable() && |
| 3643 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3644 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3645 | FitsInto( |
| 3646 | 32 /* Bits */, |
| 3647 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3648 | LastIteration64.get(), SemaRef))) |
| 3649 | LastIteration = LastIteration32; |
| 3650 | |
| 3651 | if (!LastIteration.isUsable()) |
| 3652 | return 0; |
| 3653 | |
| 3654 | // Save the number of iterations. |
| 3655 | ExprResult NumIterations = LastIteration; |
| 3656 | { |
| 3657 | LastIteration = SemaRef.BuildBinOp( |
| 3658 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3659 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3660 | if (!LastIteration.isUsable()) |
| 3661 | return 0; |
| 3662 | } |
| 3663 | |
| 3664 | // Calculate the last iteration number beforehand instead of doing this on |
| 3665 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3666 | llvm::APSInt Result; |
| 3667 | bool IsConstant = |
| 3668 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3669 | ExprResult CalcLastIteration; |
| 3670 | if (!IsConstant) { |
| 3671 | SourceLocation SaveLoc; |
| 3672 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3673 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3674 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3675 | ExprResult SaveRef = buildDeclRefExpr( |
| 3676 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3677 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3678 | SaveRef.get(), LastIteration.get()); |
| 3679 | LastIteration = SaveRef; |
| 3680 | |
| 3681 | // Prepare SaveRef + 1. |
| 3682 | NumIterations = SemaRef.BuildBinOp( |
| 3683 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3684 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3685 | if (!NumIterations.isUsable()) |
| 3686 | return 0; |
| 3687 | } |
| 3688 | |
| 3689 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3690 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3691 | QualType VType = LastIteration.get()->getType(); |
| 3692 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3693 | ExprResult LB, UB, IL, ST, EUB; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3694 | if ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3695 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3696 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3697 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3698 | SemaRef.AddInitializerToDecl( |
| 3699 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3700 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3701 | |
| 3702 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3703 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3704 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3705 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3706 | /*DirectInit*/ false, |
| 3707 | /*TypeMayContainAuto*/ false); |
| 3708 | |
| 3709 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3710 | // This will be used to implement clause 'lastprivate'. |
| 3711 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3712 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3713 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3714 | SemaRef.AddInitializerToDecl( |
| 3715 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3716 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3717 | |
| 3718 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3719 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3720 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3721 | SemaRef.AddInitializerToDecl( |
| 3722 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3723 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3724 | |
| 3725 | // Build expression: UB = min(UB, LastIteration) |
| 3726 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3727 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3728 | UB.get(), LastIteration.get()); |
| 3729 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3730 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3731 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3732 | CondOp.get()); |
| 3733 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3734 | } |
| 3735 | |
| 3736 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3737 | ExprResult IV; |
| 3738 | ExprResult Init; |
| 3739 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3740 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3741 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3742 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3743 | ? LB.get() |
| 3744 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3745 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3746 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3747 | } |
| 3748 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3749 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3750 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3751 | ExprResult Cond = |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3752 | (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3753 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3754 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3755 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3756 | |
| 3757 | // Loop increment (IV = IV + 1) |
| 3758 | SourceLocation IncLoc; |
| 3759 | ExprResult Inc = |
| 3760 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3761 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3762 | if (!Inc.isUsable()) |
| 3763 | return 0; |
| 3764 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3765 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3766 | if (!Inc.isUsable()) |
| 3767 | return 0; |
| 3768 | |
| 3769 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3770 | // Used for directives with static scheduling. |
| 3771 | ExprResult NextLB, NextUB; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3772 | if (isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3773 | // LB + ST |
| 3774 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3775 | if (!NextLB.isUsable()) |
| 3776 | return 0; |
| 3777 | // LB = LB + ST |
| 3778 | NextLB = |
| 3779 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3780 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3781 | if (!NextLB.isUsable()) |
| 3782 | return 0; |
| 3783 | // UB + ST |
| 3784 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3785 | if (!NextUB.isUsable()) |
| 3786 | return 0; |
| 3787 | // UB = UB + ST |
| 3788 | NextUB = |
| 3789 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3790 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3791 | if (!NextUB.isUsable()) |
| 3792 | return 0; |
| 3793 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3794 | |
| 3795 | // Build updates and final values of the loop counters. |
| 3796 | bool HasErrors = false; |
| 3797 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3798 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3799 | Built.Updates.resize(NestedLoopCount); |
| 3800 | Built.Finals.resize(NestedLoopCount); |
| 3801 | { |
| 3802 | ExprResult Div; |
| 3803 | // Go from inner nested loop to outer. |
| 3804 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3805 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3806 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3807 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3808 | // where Div is product of previous iterations' IS.NumIters. |
| 3809 | ExprResult Iter; |
| 3810 | if (Div.isUsable()) { |
| 3811 | Iter = |
| 3812 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3813 | } else { |
| 3814 | Iter = IV; |
| 3815 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3816 | "unusable div expected on first iteration only"); |
| 3817 | } |
| 3818 | |
| 3819 | if (Cnt != 0 && Iter.isUsable()) |
| 3820 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3821 | IS.NumIterations); |
| 3822 | if (!Iter.isUsable()) { |
| 3823 | HasErrors = true; |
| 3824 | break; |
| 3825 | } |
| 3826 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3827 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3828 | auto *CounterVar = buildDeclRefExpr( |
| 3829 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3830 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3831 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3832 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3833 | IS.CounterInit); |
| 3834 | if (!Init.isUsable()) { |
| 3835 | HasErrors = true; |
| 3836 | break; |
| 3837 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3838 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3839 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3840 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3841 | if (!Update.isUsable()) { |
| 3842 | HasErrors = true; |
| 3843 | break; |
| 3844 | } |
| 3845 | |
| 3846 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3847 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3848 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3849 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3850 | if (!Final.isUsable()) { |
| 3851 | HasErrors = true; |
| 3852 | break; |
| 3853 | } |
| 3854 | |
| 3855 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3856 | if (Cnt != 0) { |
| 3857 | if (Div.isUnset()) |
| 3858 | Div = IS.NumIterations; |
| 3859 | else |
| 3860 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3861 | IS.NumIterations); |
| 3862 | |
| 3863 | // Add parentheses (for debugging purposes only). |
| 3864 | if (Div.isUsable()) |
| 3865 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3866 | if (!Div.isUsable()) { |
| 3867 | HasErrors = true; |
| 3868 | break; |
| 3869 | } |
| 3870 | } |
| 3871 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3872 | HasErrors = true; |
| 3873 | break; |
| 3874 | } |
| 3875 | // Save results |
| 3876 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3877 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3878 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3879 | Built.Updates[Cnt] = Update.get(); |
| 3880 | Built.Finals[Cnt] = Final.get(); |
| 3881 | } |
| 3882 | } |
| 3883 | |
| 3884 | if (HasErrors) |
| 3885 | return 0; |
| 3886 | |
| 3887 | // Save results |
| 3888 | Built.IterationVarRef = IV.get(); |
| 3889 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3890 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3891 | Built.CalcLastIteration = |
| 3892 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3893 | Built.PreCond = PreCond.get(); |
| 3894 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3895 | Built.Init = Init.get(); |
| 3896 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3897 | Built.LB = LB.get(); |
| 3898 | Built.UB = UB.get(); |
| 3899 | Built.IL = IL.get(); |
| 3900 | Built.ST = ST.get(); |
| 3901 | Built.EUB = EUB.get(); |
| 3902 | Built.NLB = NextLB.get(); |
| 3903 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3904 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3905 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3906 | } |
| 3907 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3908 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3909 | auto CollapseClauses = |
| 3910 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 3911 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 3912 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3913 | return nullptr; |
| 3914 | } |
| 3915 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3916 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3917 | auto OrderedClauses = |
| 3918 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 3919 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 3920 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3921 | return nullptr; |
| 3922 | } |
| 3923 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3924 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 3925 | const Expr *Safelen) { |
| 3926 | llvm::APSInt SimdlenRes, SafelenRes; |
| 3927 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 3928 | Simdlen->isInstantiationDependent() || |
| 3929 | Simdlen->containsUnexpandedParameterPack()) |
| 3930 | return false; |
| 3931 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 3932 | Safelen->isInstantiationDependent() || |
| 3933 | Safelen->containsUnexpandedParameterPack()) |
| 3934 | return false; |
| 3935 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 3936 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 3937 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3938 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3939 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3940 | if (SimdlenRes > SafelenRes) { |
| 3941 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 3942 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 3943 | return true; |
| 3944 | } |
| 3945 | return false; |
| 3946 | } |
| 3947 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3948 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3949 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3950 | SourceLocation EndLoc, |
| 3951 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3952 | if (!AStmt) |
| 3953 | return StmtError(); |
| 3954 | |
| 3955 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3956 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3957 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3958 | // define the nested loops number. |
| 3959 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3960 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3961 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3962 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3963 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3964 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3965 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3966 | "omp simd loop exprs were not built"); |
| 3967 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3968 | if (!CurContext->isDependentContext()) { |
| 3969 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3970 | for (auto C : Clauses) { |
| 3971 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3972 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3973 | B.NumIterations, *this, CurScope)) |
| 3974 | return StmtError(); |
| 3975 | } |
| 3976 | } |
| 3977 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3978 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3979 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3980 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3981 | OMPSafelenClause *Safelen = nullptr; |
| 3982 | OMPSimdlenClause *Simdlen = nullptr; |
| 3983 | for (auto *Clause : Clauses) { |
| 3984 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3985 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3986 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3987 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3988 | if (Safelen && Simdlen) |
| 3989 | break; |
| 3990 | } |
| 3991 | if (Simdlen && Safelen && |
| 3992 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3993 | Safelen->getSafelen())) |
| 3994 | return StmtError(); |
| 3995 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3996 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3997 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3998 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3999 | } |
| 4000 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4001 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4002 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4003 | SourceLocation EndLoc, |
| 4004 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4005 | if (!AStmt) |
| 4006 | return StmtError(); |
| 4007 | |
| 4008 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4009 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4010 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4011 | // define the nested loops number. |
| 4012 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4013 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4014 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4015 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4016 | return StmtError(); |
| 4017 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4018 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4019 | "omp for loop exprs were not built"); |
| 4020 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4021 | if (!CurContext->isDependentContext()) { |
| 4022 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4023 | for (auto C : Clauses) { |
| 4024 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4025 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4026 | B.NumIterations, *this, CurScope)) |
| 4027 | return StmtError(); |
| 4028 | } |
| 4029 | } |
| 4030 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4031 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4032 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4033 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4034 | } |
| 4035 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4036 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4037 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4038 | SourceLocation EndLoc, |
| 4039 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4040 | if (!AStmt) |
| 4041 | return StmtError(); |
| 4042 | |
| 4043 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4044 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4045 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4046 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4047 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4048 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4049 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4050 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4051 | if (NestedLoopCount == 0) |
| 4052 | return StmtError(); |
| 4053 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4054 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4055 | "omp for simd loop exprs were not built"); |
| 4056 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4057 | if (!CurContext->isDependentContext()) { |
| 4058 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4059 | for (auto C : Clauses) { |
| 4060 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4061 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4062 | B.NumIterations, *this, CurScope)) |
| 4063 | return StmtError(); |
| 4064 | } |
| 4065 | } |
| 4066 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4067 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4068 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4069 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4070 | OMPSafelenClause *Safelen = nullptr; |
| 4071 | OMPSimdlenClause *Simdlen = nullptr; |
| 4072 | for (auto *Clause : Clauses) { |
| 4073 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4074 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4075 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4076 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4077 | if (Safelen && Simdlen) |
| 4078 | break; |
| 4079 | } |
| 4080 | if (Simdlen && Safelen && |
| 4081 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4082 | Safelen->getSafelen())) |
| 4083 | return StmtError(); |
| 4084 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4085 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4086 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4087 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4090 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4091 | Stmt *AStmt, |
| 4092 | SourceLocation StartLoc, |
| 4093 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4094 | if (!AStmt) |
| 4095 | return StmtError(); |
| 4096 | |
| 4097 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4098 | auto BaseStmt = AStmt; |
| 4099 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4100 | BaseStmt = CS->getCapturedStmt(); |
| 4101 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4102 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4103 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4104 | return StmtError(); |
| 4105 | // All associated statements must be '#pragma omp section' except for |
| 4106 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4107 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4108 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4109 | if (SectionStmt) |
| 4110 | Diag(SectionStmt->getLocStart(), |
| 4111 | diag::err_omp_sections_substmt_not_section); |
| 4112 | return StmtError(); |
| 4113 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4114 | cast<OMPSectionDirective>(SectionStmt) |
| 4115 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4116 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4117 | } else { |
| 4118 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4119 | return StmtError(); |
| 4120 | } |
| 4121 | |
| 4122 | getCurFunction()->setHasBranchProtectedScope(); |
| 4123 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4124 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4125 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4126 | } |
| 4127 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4128 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4129 | SourceLocation StartLoc, |
| 4130 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4131 | if (!AStmt) |
| 4132 | return StmtError(); |
| 4133 | |
| 4134 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4135 | |
| 4136 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4137 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4138 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4139 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4140 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4141 | } |
| 4142 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4143 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4144 | Stmt *AStmt, |
| 4145 | SourceLocation StartLoc, |
| 4146 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4147 | if (!AStmt) |
| 4148 | return StmtError(); |
| 4149 | |
| 4150 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4151 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4152 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4153 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4154 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4155 | // The copyprivate clause must not be used with the nowait clause. |
| 4156 | OMPClause *Nowait = nullptr; |
| 4157 | OMPClause *Copyprivate = nullptr; |
| 4158 | for (auto *Clause : Clauses) { |
| 4159 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4160 | Nowait = Clause; |
| 4161 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4162 | Copyprivate = Clause; |
| 4163 | if (Copyprivate && Nowait) { |
| 4164 | Diag(Copyprivate->getLocStart(), |
| 4165 | diag::err_omp_single_copyprivate_with_nowait); |
| 4166 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4167 | return StmtError(); |
| 4168 | } |
| 4169 | } |
| 4170 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4171 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4172 | } |
| 4173 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4174 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4175 | SourceLocation StartLoc, |
| 4176 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4177 | if (!AStmt) |
| 4178 | return StmtError(); |
| 4179 | |
| 4180 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4181 | |
| 4182 | getCurFunction()->setHasBranchProtectedScope(); |
| 4183 | |
| 4184 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4185 | } |
| 4186 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4187 | StmtResult |
| 4188 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 4189 | Stmt *AStmt, SourceLocation StartLoc, |
| 4190 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4191 | if (!AStmt) |
| 4192 | return StmtError(); |
| 4193 | |
| 4194 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4195 | |
| 4196 | getCurFunction()->setHasBranchProtectedScope(); |
| 4197 | |
| 4198 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4199 | AStmt); |
| 4200 | } |
| 4201 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4202 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4203 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4204 | SourceLocation EndLoc, |
| 4205 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4206 | if (!AStmt) |
| 4207 | return StmtError(); |
| 4208 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4209 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4210 | // 1.2.2 OpenMP Language Terminology |
| 4211 | // Structured block - An executable statement with a single entry at the |
| 4212 | // top and a single exit at the bottom. |
| 4213 | // The point of exit cannot be a branch out of the structured block. |
| 4214 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4215 | CS->getCapturedDecl()->setNothrow(); |
| 4216 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4217 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4218 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4219 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4220 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4221 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4222 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4223 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4224 | if (NestedLoopCount == 0) |
| 4225 | return StmtError(); |
| 4226 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4227 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4228 | "omp parallel for loop exprs were not built"); |
| 4229 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4230 | if (!CurContext->isDependentContext()) { |
| 4231 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4232 | for (auto C : Clauses) { |
| 4233 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4234 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4235 | B.NumIterations, *this, CurScope)) |
| 4236 | return StmtError(); |
| 4237 | } |
| 4238 | } |
| 4239 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4240 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4241 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4242 | NestedLoopCount, Clauses, AStmt, B, |
| 4243 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4246 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4247 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4248 | SourceLocation EndLoc, |
| 4249 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4250 | if (!AStmt) |
| 4251 | return StmtError(); |
| 4252 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4253 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4254 | // 1.2.2 OpenMP Language Terminology |
| 4255 | // Structured block - An executable statement with a single entry at the |
| 4256 | // top and a single exit at the bottom. |
| 4257 | // The point of exit cannot be a branch out of the structured block. |
| 4258 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4259 | CS->getCapturedDecl()->setNothrow(); |
| 4260 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4261 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4262 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4263 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4264 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4265 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4266 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4267 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4268 | if (NestedLoopCount == 0) |
| 4269 | return StmtError(); |
| 4270 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4271 | if (!CurContext->isDependentContext()) { |
| 4272 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4273 | for (auto C : Clauses) { |
| 4274 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4275 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4276 | B.NumIterations, *this, CurScope)) |
| 4277 | return StmtError(); |
| 4278 | } |
| 4279 | } |
| 4280 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4281 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4282 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4283 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4284 | OMPSafelenClause *Safelen = nullptr; |
| 4285 | OMPSimdlenClause *Simdlen = nullptr; |
| 4286 | for (auto *Clause : Clauses) { |
| 4287 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4288 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4289 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4290 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4291 | if (Safelen && Simdlen) |
| 4292 | break; |
| 4293 | } |
| 4294 | if (Simdlen && Safelen && |
| 4295 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4296 | Safelen->getSafelen())) |
| 4297 | return StmtError(); |
| 4298 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4299 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4300 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4301 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4302 | } |
| 4303 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4304 | StmtResult |
| 4305 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 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"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4312 | auto BaseStmt = AStmt; |
| 4313 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4314 | BaseStmt = CS->getCapturedStmt(); |
| 4315 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4316 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4317 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4318 | return StmtError(); |
| 4319 | // All associated statements must be '#pragma omp section' except for |
| 4320 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4321 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4322 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4323 | if (SectionStmt) |
| 4324 | Diag(SectionStmt->getLocStart(), |
| 4325 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4326 | return StmtError(); |
| 4327 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4328 | cast<OMPSectionDirective>(SectionStmt) |
| 4329 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4330 | } |
| 4331 | } else { |
| 4332 | Diag(AStmt->getLocStart(), |
| 4333 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4334 | return StmtError(); |
| 4335 | } |
| 4336 | |
| 4337 | getCurFunction()->setHasBranchProtectedScope(); |
| 4338 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4339 | return OMPParallelSectionsDirective::Create( |
| 4340 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4341 | } |
| 4342 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4343 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4344 | Stmt *AStmt, SourceLocation StartLoc, |
| 4345 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4346 | if (!AStmt) |
| 4347 | return StmtError(); |
| 4348 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4349 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4350 | // 1.2.2 OpenMP Language Terminology |
| 4351 | // Structured block - An executable statement with a single entry at the |
| 4352 | // top and a single exit at the bottom. |
| 4353 | // The point of exit cannot be a branch out of the structured block. |
| 4354 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4355 | CS->getCapturedDecl()->setNothrow(); |
| 4356 | |
| 4357 | getCurFunction()->setHasBranchProtectedScope(); |
| 4358 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4359 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4360 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4361 | } |
| 4362 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4363 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4364 | SourceLocation EndLoc) { |
| 4365 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4366 | } |
| 4367 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4368 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4369 | SourceLocation EndLoc) { |
| 4370 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4371 | } |
| 4372 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4373 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4374 | SourceLocation EndLoc) { |
| 4375 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4376 | } |
| 4377 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4378 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4379 | SourceLocation StartLoc, |
| 4380 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4381 | if (!AStmt) |
| 4382 | return StmtError(); |
| 4383 | |
| 4384 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4385 | |
| 4386 | getCurFunction()->setHasBranchProtectedScope(); |
| 4387 | |
| 4388 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4389 | } |
| 4390 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4391 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4392 | SourceLocation StartLoc, |
| 4393 | SourceLocation EndLoc) { |
| 4394 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4395 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4396 | } |
| 4397 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4398 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4399 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4400 | SourceLocation StartLoc, |
| 4401 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4402 | if (!AStmt) |
| 4403 | return StmtError(); |
| 4404 | |
| 4405 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4406 | |
| 4407 | getCurFunction()->setHasBranchProtectedScope(); |
| 4408 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4409 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4410 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4411 | for (auto *C: Clauses) { |
| 4412 | if (C->getClauseKind() == OMPC_threads) |
| 4413 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4414 | else if (C->getClauseKind() == OMPC_simd) |
| 4415 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4416 | } |
| 4417 | |
| 4418 | // TODO: this must happen only if 'threads' clause specified or if no clauses |
| 4419 | // is specified. |
| 4420 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4421 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4422 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) << (TC != nullptr); |
| 4423 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4424 | return StmtError(); |
| 4425 | } |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4426 | if (!SC && isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
| 4427 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4428 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4429 | // that can appear in the simd region. |
| 4430 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 4431 | return StmtError(); |
| 4432 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4433 | |
| 4434 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4435 | } |
| 4436 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4437 | namespace { |
| 4438 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4439 | /// construct. |
| 4440 | class OpenMPAtomicUpdateChecker { |
| 4441 | /// \brief Error results for atomic update expressions. |
| 4442 | enum ExprAnalysisErrorCode { |
| 4443 | /// \brief A statement is not an expression statement. |
| 4444 | NotAnExpression, |
| 4445 | /// \brief Expression is not builtin binary or unary operation. |
| 4446 | NotABinaryOrUnaryExpression, |
| 4447 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4448 | NotAnUnaryIncDecExpression, |
| 4449 | /// \brief An expression is not of scalar type. |
| 4450 | NotAScalarType, |
| 4451 | /// \brief A binary operation is not an assignment operation. |
| 4452 | NotAnAssignmentOp, |
| 4453 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4454 | NotABinaryExpression, |
| 4455 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4456 | /// expression. |
| 4457 | NotABinaryOperator, |
| 4458 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4459 | /// part. |
| 4460 | NotAnUpdateExpression, |
| 4461 | /// \brief No errors is found. |
| 4462 | NoError |
| 4463 | }; |
| 4464 | /// \brief Reference to Sema. |
| 4465 | Sema &SemaRef; |
| 4466 | /// \brief A location for note diagnostics (when error is found). |
| 4467 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4468 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4469 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4470 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4471 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4472 | /// \brief Helper expression of the form |
| 4473 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4474 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4475 | Expr *UpdateExpr; |
| 4476 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4477 | /// important for non-associative operations. |
| 4478 | bool IsXLHSInRHSPart; |
| 4479 | BinaryOperatorKind Op; |
| 4480 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4481 | /// \brief true if the source expression is a postfix unary operation, false |
| 4482 | /// if it is a prefix unary operation. |
| 4483 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4484 | |
| 4485 | public: |
| 4486 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4487 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4488 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4489 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4490 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4491 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4492 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4493 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4494 | /// \param NoteId Diagnostic note for the main error message. |
| 4495 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4496 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4497 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4498 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4499 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4500 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4501 | /// \brief Return the update expression used in calculation of the updated |
| 4502 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4503 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4504 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4505 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4506 | /// false otherwise. |
| 4507 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4508 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4509 | /// \brief true if the source expression is a postfix unary operation, false |
| 4510 | /// if it is a prefix unary operation. |
| 4511 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4512 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4513 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4514 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4515 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4516 | }; |
| 4517 | } // namespace |
| 4518 | |
| 4519 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4520 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4521 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4522 | SourceLocation ErrorLoc, NoteLoc; |
| 4523 | SourceRange ErrorRange, NoteRange; |
| 4524 | // Allowed constructs are: |
| 4525 | // x = x binop expr; |
| 4526 | // x = expr binop x; |
| 4527 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4528 | X = AtomicBinOp->getLHS(); |
| 4529 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4530 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4531 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4532 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4533 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4534 | Op = AtomicInnerBinOp->getOpcode(); |
| 4535 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4536 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4537 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4538 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4539 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4540 | /*Canonical=*/true); |
| 4541 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4542 | /*Canonical=*/true); |
| 4543 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4544 | /*Canonical=*/true); |
| 4545 | if (XId == LHSId) { |
| 4546 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4547 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4548 | } else if (XId == RHSId) { |
| 4549 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4550 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4551 | } else { |
| 4552 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4553 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4554 | NoteLoc = X->getExprLoc(); |
| 4555 | NoteRange = X->getSourceRange(); |
| 4556 | ErrorFound = NotAnUpdateExpression; |
| 4557 | } |
| 4558 | } else { |
| 4559 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4560 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4561 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4562 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4563 | ErrorFound = NotABinaryOperator; |
| 4564 | } |
| 4565 | } else { |
| 4566 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4567 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4568 | ErrorFound = NotABinaryExpression; |
| 4569 | } |
| 4570 | } else { |
| 4571 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4572 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4573 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4574 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4575 | ErrorFound = NotAnAssignmentOp; |
| 4576 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4577 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4578 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4579 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4580 | return true; |
| 4581 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4582 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4583 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4584 | } |
| 4585 | |
| 4586 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4587 | unsigned NoteId) { |
| 4588 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4589 | SourceLocation ErrorLoc, NoteLoc; |
| 4590 | SourceRange ErrorRange, NoteRange; |
| 4591 | // Allowed constructs are: |
| 4592 | // x++; |
| 4593 | // x--; |
| 4594 | // ++x; |
| 4595 | // --x; |
| 4596 | // x binop= expr; |
| 4597 | // x = x binop expr; |
| 4598 | // x = expr binop x; |
| 4599 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4600 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4601 | if (AtomicBody->getType()->isScalarType() || |
| 4602 | AtomicBody->isInstantiationDependent()) { |
| 4603 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4604 | AtomicBody->IgnoreParenImpCasts())) { |
| 4605 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4606 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4607 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4608 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4609 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4610 | X = AtomicCompAssignOp->getLHS(); |
| 4611 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4612 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4613 | AtomicBody->IgnoreParenImpCasts())) { |
| 4614 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4615 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4616 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4617 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4618 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4619 | // Check for Unary Operation |
| 4620 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4621 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4622 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4623 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4624 | X = AtomicUnaryOp->getSubExpr(); |
| 4625 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4626 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4627 | } else { |
| 4628 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4629 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4630 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4631 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4632 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4633 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4634 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4635 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4636 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4637 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4638 | } |
| 4639 | } else { |
| 4640 | ErrorFound = NotAScalarType; |
| 4641 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4642 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4643 | } |
| 4644 | } else { |
| 4645 | ErrorFound = NotAnExpression; |
| 4646 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4647 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4648 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4649 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4650 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4651 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4652 | return true; |
| 4653 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4654 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4655 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4656 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4657 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4658 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4659 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4660 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4661 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4662 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4663 | auto Update = |
| 4664 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4665 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4666 | if (Update.isInvalid()) |
| 4667 | return true; |
| 4668 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4669 | Sema::AA_Casting); |
| 4670 | if (Update.isInvalid()) |
| 4671 | return true; |
| 4672 | UpdateExpr = Update.get(); |
| 4673 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4674 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4677 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4678 | Stmt *AStmt, |
| 4679 | SourceLocation StartLoc, |
| 4680 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4681 | if (!AStmt) |
| 4682 | return StmtError(); |
| 4683 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4684 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4685 | // 1.2.2 OpenMP Language Terminology |
| 4686 | // Structured block - An executable statement with a single entry at the |
| 4687 | // top and a single exit at the bottom. |
| 4688 | // The point of exit cannot be a branch out of the structured block. |
| 4689 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4690 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4691 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4692 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4693 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4694 | C->getClauseKind() == OMPC_update || |
| 4695 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4696 | if (AtomicKind != OMPC_unknown) { |
| 4697 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4698 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4699 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4700 | << getOpenMPClauseName(AtomicKind); |
| 4701 | } else { |
| 4702 | AtomicKind = C->getClauseKind(); |
| 4703 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4704 | } |
| 4705 | } |
| 4706 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4707 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4708 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4709 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4710 | Body = EWC->getSubExpr(); |
| 4711 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4712 | Expr *X = nullptr; |
| 4713 | Expr *V = nullptr; |
| 4714 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4715 | Expr *UE = nullptr; |
| 4716 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4717 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4718 | // OpenMP [2.12.6, atomic Construct] |
| 4719 | // In the next expressions: |
| 4720 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4721 | // * During the execution of an atomic region, multiple syntactic |
| 4722 | // occurrences of x must designate the same storage location. |
| 4723 | // * Neither of v and expr (as applicable) may access the storage location |
| 4724 | // designated by x. |
| 4725 | // * Neither of x and expr (as applicable) may access the storage location |
| 4726 | // designated by v. |
| 4727 | // * expr is an expression with scalar type. |
| 4728 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4729 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4730 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4731 | // (expr). This requirement is satisfied if the operators in expr have |
| 4732 | // precedence greater than binop, or by using parentheses around expr or |
| 4733 | // subexpressions of expr. |
| 4734 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4735 | // binop x. This requirement is satisfied if the operators in expr have |
| 4736 | // precedence equal to or greater than binop, or by using parentheses around |
| 4737 | // expr or subexpressions of expr. |
| 4738 | // * For forms that allow multiple occurrences of x, the number of times |
| 4739 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4740 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4741 | enum { |
| 4742 | NotAnExpression, |
| 4743 | NotAnAssignmentOp, |
| 4744 | NotAScalarType, |
| 4745 | NotAnLValue, |
| 4746 | NoError |
| 4747 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4748 | SourceLocation ErrorLoc, NoteLoc; |
| 4749 | SourceRange ErrorRange, NoteRange; |
| 4750 | // If clause is read: |
| 4751 | // v = x; |
| 4752 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4753 | auto AtomicBinOp = |
| 4754 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4755 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4756 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4757 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4758 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4759 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4760 | if (!X->isLValue() || !V->isLValue()) { |
| 4761 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4762 | ErrorFound = NotAnLValue; |
| 4763 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4764 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4765 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4766 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4767 | } |
| 4768 | } else if (!X->isInstantiationDependent() || |
| 4769 | !V->isInstantiationDependent()) { |
| 4770 | auto NotScalarExpr = |
| 4771 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4772 | ? V |
| 4773 | : X; |
| 4774 | ErrorFound = NotAScalarType; |
| 4775 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4776 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4777 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4778 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4779 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4780 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4781 | ErrorFound = NotAnAssignmentOp; |
| 4782 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4783 | ErrorRange = AtomicBody->getSourceRange(); |
| 4784 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4785 | : AtomicBody->getExprLoc(); |
| 4786 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4787 | : AtomicBody->getSourceRange(); |
| 4788 | } |
| 4789 | } else { |
| 4790 | ErrorFound = NotAnExpression; |
| 4791 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4792 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4793 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4794 | if (ErrorFound != NoError) { |
| 4795 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4796 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4797 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4798 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4799 | return StmtError(); |
| 4800 | } else if (CurContext->isDependentContext()) |
| 4801 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4802 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4803 | enum { |
| 4804 | NotAnExpression, |
| 4805 | NotAnAssignmentOp, |
| 4806 | NotAScalarType, |
| 4807 | NotAnLValue, |
| 4808 | NoError |
| 4809 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4810 | SourceLocation ErrorLoc, NoteLoc; |
| 4811 | SourceRange ErrorRange, NoteRange; |
| 4812 | // If clause is write: |
| 4813 | // x = expr; |
| 4814 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4815 | auto AtomicBinOp = |
| 4816 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4817 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4818 | X = AtomicBinOp->getLHS(); |
| 4819 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4820 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4821 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4822 | if (!X->isLValue()) { |
| 4823 | ErrorFound = NotAnLValue; |
| 4824 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4825 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4826 | NoteLoc = X->getExprLoc(); |
| 4827 | NoteRange = X->getSourceRange(); |
| 4828 | } |
| 4829 | } else if (!X->isInstantiationDependent() || |
| 4830 | !E->isInstantiationDependent()) { |
| 4831 | auto NotScalarExpr = |
| 4832 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4833 | ? E |
| 4834 | : X; |
| 4835 | ErrorFound = NotAScalarType; |
| 4836 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4837 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4838 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4839 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4840 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4841 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4842 | ErrorFound = NotAnAssignmentOp; |
| 4843 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4844 | ErrorRange = AtomicBody->getSourceRange(); |
| 4845 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4846 | : AtomicBody->getExprLoc(); |
| 4847 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4848 | : AtomicBody->getSourceRange(); |
| 4849 | } |
| 4850 | } else { |
| 4851 | ErrorFound = NotAnExpression; |
| 4852 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4853 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4854 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4855 | if (ErrorFound != NoError) { |
| 4856 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4857 | << ErrorRange; |
| 4858 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4859 | << NoteRange; |
| 4860 | return StmtError(); |
| 4861 | } else if (CurContext->isDependentContext()) |
| 4862 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4863 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4864 | // If clause is update: |
| 4865 | // x++; |
| 4866 | // x--; |
| 4867 | // ++x; |
| 4868 | // --x; |
| 4869 | // x binop= expr; |
| 4870 | // x = x binop expr; |
| 4871 | // x = expr binop x; |
| 4872 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4873 | if (Checker.checkStatement( |
| 4874 | Body, (AtomicKind == OMPC_update) |
| 4875 | ? diag::err_omp_atomic_update_not_expression_statement |
| 4876 | : diag::err_omp_atomic_not_expression_statement, |
| 4877 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4878 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4879 | if (!CurContext->isDependentContext()) { |
| 4880 | E = Checker.getExpr(); |
| 4881 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4882 | UE = Checker.getUpdateExpr(); |
| 4883 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4884 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4885 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4886 | enum { |
| 4887 | NotAnAssignmentOp, |
| 4888 | NotACompoundStatement, |
| 4889 | NotTwoSubstatements, |
| 4890 | NotASpecificExpression, |
| 4891 | NoError |
| 4892 | } ErrorFound = NoError; |
| 4893 | SourceLocation ErrorLoc, NoteLoc; |
| 4894 | SourceRange ErrorRange, NoteRange; |
| 4895 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 4896 | // If clause is a capture: |
| 4897 | // v = x++; |
| 4898 | // v = x--; |
| 4899 | // v = ++x; |
| 4900 | // v = --x; |
| 4901 | // v = x binop= expr; |
| 4902 | // v = x = x binop expr; |
| 4903 | // v = x = expr binop x; |
| 4904 | auto *AtomicBinOp = |
| 4905 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4906 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4907 | V = AtomicBinOp->getLHS(); |
| 4908 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4909 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4910 | if (Checker.checkStatement( |
| 4911 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 4912 | diag::note_omp_atomic_update)) |
| 4913 | return StmtError(); |
| 4914 | E = Checker.getExpr(); |
| 4915 | X = Checker.getX(); |
| 4916 | UE = Checker.getUpdateExpr(); |
| 4917 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 4918 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4919 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4920 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4921 | ErrorRange = AtomicBody->getSourceRange(); |
| 4922 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4923 | : AtomicBody->getExprLoc(); |
| 4924 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4925 | : AtomicBody->getSourceRange(); |
| 4926 | ErrorFound = NotAnAssignmentOp; |
| 4927 | } |
| 4928 | if (ErrorFound != NoError) { |
| 4929 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 4930 | << ErrorRange; |
| 4931 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4932 | return StmtError(); |
| 4933 | } else if (CurContext->isDependentContext()) { |
| 4934 | UE = V = E = X = nullptr; |
| 4935 | } |
| 4936 | } else { |
| 4937 | // If clause is a capture: |
| 4938 | // { v = x; x = expr; } |
| 4939 | // { v = x; x++; } |
| 4940 | // { v = x; x--; } |
| 4941 | // { v = x; ++x; } |
| 4942 | // { v = x; --x; } |
| 4943 | // { v = x; x binop= expr; } |
| 4944 | // { v = x; x = x binop expr; } |
| 4945 | // { v = x; x = expr binop x; } |
| 4946 | // { x++; v = x; } |
| 4947 | // { x--; v = x; } |
| 4948 | // { ++x; v = x; } |
| 4949 | // { --x; v = x; } |
| 4950 | // { x binop= expr; v = x; } |
| 4951 | // { x = x binop expr; v = x; } |
| 4952 | // { x = expr binop x; v = x; } |
| 4953 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 4954 | // Check that this is { expr1; expr2; } |
| 4955 | if (CS->size() == 2) { |
| 4956 | auto *First = CS->body_front(); |
| 4957 | auto *Second = CS->body_back(); |
| 4958 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 4959 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4960 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 4961 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4962 | // Need to find what subexpression is 'v' and what is 'x'. |
| 4963 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4964 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 4965 | BinaryOperator *BinOp = nullptr; |
| 4966 | if (IsUpdateExprFound) { |
| 4967 | BinOp = dyn_cast<BinaryOperator>(First); |
| 4968 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4969 | } |
| 4970 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4971 | // { v = x; x++; } |
| 4972 | // { v = x; x--; } |
| 4973 | // { v = x; ++x; } |
| 4974 | // { v = x; --x; } |
| 4975 | // { v = x; x binop= expr; } |
| 4976 | // { v = x; x = x binop expr; } |
| 4977 | // { v = x; x = expr binop x; } |
| 4978 | // Check that the first expression has form v = x. |
| 4979 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4980 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4981 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4982 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4983 | IsUpdateExprFound = XId == PossibleXId; |
| 4984 | if (IsUpdateExprFound) { |
| 4985 | V = BinOp->getLHS(); |
| 4986 | X = Checker.getX(); |
| 4987 | E = Checker.getExpr(); |
| 4988 | UE = Checker.getUpdateExpr(); |
| 4989 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4990 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4991 | } |
| 4992 | } |
| 4993 | if (!IsUpdateExprFound) { |
| 4994 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 4995 | BinOp = nullptr; |
| 4996 | if (IsUpdateExprFound) { |
| 4997 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 4998 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4999 | } |
| 5000 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5001 | // { x++; v = x; } |
| 5002 | // { x--; v = x; } |
| 5003 | // { ++x; v = x; } |
| 5004 | // { --x; v = x; } |
| 5005 | // { x binop= expr; v = x; } |
| 5006 | // { x = x binop expr; v = x; } |
| 5007 | // { x = expr binop x; v = x; } |
| 5008 | // Check that the second expression has form v = x. |
| 5009 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5010 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5011 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5012 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5013 | IsUpdateExprFound = XId == PossibleXId; |
| 5014 | if (IsUpdateExprFound) { |
| 5015 | V = BinOp->getLHS(); |
| 5016 | X = Checker.getX(); |
| 5017 | E = Checker.getExpr(); |
| 5018 | UE = Checker.getUpdateExpr(); |
| 5019 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5020 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5021 | } |
| 5022 | } |
| 5023 | } |
| 5024 | if (!IsUpdateExprFound) { |
| 5025 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5026 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5027 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5028 | if (!FirstExpr || !SecondExpr || |
| 5029 | !(FirstExpr->isInstantiationDependent() || |
| 5030 | SecondExpr->isInstantiationDependent())) { |
| 5031 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5032 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5033 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5034 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5035 | : First->getLocStart(); |
| 5036 | NoteRange = ErrorRange = FirstBinOp |
| 5037 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5038 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5039 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5040 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5041 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5042 | ErrorFound = NotAnAssignmentOp; |
| 5043 | NoteLoc = ErrorLoc = SecondBinOp |
| 5044 | ? SecondBinOp->getOperatorLoc() |
| 5045 | : Second->getLocStart(); |
| 5046 | NoteRange = ErrorRange = |
| 5047 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5048 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5049 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5050 | auto *PossibleXRHSInFirst = |
| 5051 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5052 | auto *PossibleXLHSInSecond = |
| 5053 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5054 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5055 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5056 | /*Canonical=*/true); |
| 5057 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5058 | /*Canonical=*/true); |
| 5059 | IsUpdateExprFound = X1Id == X2Id; |
| 5060 | if (IsUpdateExprFound) { |
| 5061 | V = FirstBinOp->getLHS(); |
| 5062 | X = SecondBinOp->getLHS(); |
| 5063 | E = SecondBinOp->getRHS(); |
| 5064 | UE = nullptr; |
| 5065 | IsXLHSInRHSPart = false; |
| 5066 | IsPostfixUpdate = true; |
| 5067 | } else { |
| 5068 | ErrorFound = NotASpecificExpression; |
| 5069 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5070 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5071 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5072 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5073 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5074 | } |
| 5075 | } |
| 5076 | } |
| 5077 | } |
| 5078 | } else { |
| 5079 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5080 | NoteRange = ErrorRange = |
| 5081 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5082 | ErrorFound = NotTwoSubstatements; |
| 5083 | } |
| 5084 | } else { |
| 5085 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5086 | NoteRange = ErrorRange = |
| 5087 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5088 | ErrorFound = NotACompoundStatement; |
| 5089 | } |
| 5090 | if (ErrorFound != NoError) { |
| 5091 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5092 | << ErrorRange; |
| 5093 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5094 | return StmtError(); |
| 5095 | } else if (CurContext->isDependentContext()) { |
| 5096 | UE = V = E = X = nullptr; |
| 5097 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5098 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5099 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5100 | |
| 5101 | getCurFunction()->setHasBranchProtectedScope(); |
| 5102 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5103 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5104 | X, V, E, UE, IsXLHSInRHSPart, |
| 5105 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5106 | } |
| 5107 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5108 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5109 | Stmt *AStmt, |
| 5110 | SourceLocation StartLoc, |
| 5111 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5112 | if (!AStmt) |
| 5113 | return StmtError(); |
| 5114 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame^] | 5115 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5116 | // 1.2.2 OpenMP Language Terminology |
| 5117 | // Structured block - An executable statement with a single entry at the |
| 5118 | // top and a single exit at the bottom. |
| 5119 | // The point of exit cannot be a branch out of the structured block. |
| 5120 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5121 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5122 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5123 | // OpenMP [2.16, Nesting of Regions] |
| 5124 | // If specified, a teams construct must be contained within a target |
| 5125 | // construct. That target construct must contain no statements or directives |
| 5126 | // outside of the teams construct. |
| 5127 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5128 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5129 | bool OMPTeamsFound = true; |
| 5130 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5131 | auto I = CS->body_begin(); |
| 5132 | while (I != CS->body_end()) { |
| 5133 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 5134 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5135 | OMPTeamsFound = false; |
| 5136 | break; |
| 5137 | } |
| 5138 | ++I; |
| 5139 | } |
| 5140 | assert(I != CS->body_end() && "Not found statement"); |
| 5141 | S = *I; |
| 5142 | } |
| 5143 | if (!OMPTeamsFound) { |
| 5144 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5145 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5146 | diag::note_omp_nested_teams_construct_here); |
| 5147 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5148 | << isa<OMPExecutableDirective>(S); |
| 5149 | return StmtError(); |
| 5150 | } |
| 5151 | } |
| 5152 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5153 | getCurFunction()->setHasBranchProtectedScope(); |
| 5154 | |
| 5155 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5156 | } |
| 5157 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5158 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5159 | Stmt *AStmt, |
| 5160 | SourceLocation StartLoc, |
| 5161 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5162 | if (!AStmt) |
| 5163 | return StmtError(); |
| 5164 | |
| 5165 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5166 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5167 | getCurFunction()->setHasBranchProtectedScope(); |
| 5168 | |
| 5169 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5170 | AStmt); |
| 5171 | } |
| 5172 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5173 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5174 | Stmt *AStmt, SourceLocation StartLoc, |
| 5175 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5176 | if (!AStmt) |
| 5177 | return StmtError(); |
| 5178 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5179 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5180 | // 1.2.2 OpenMP Language Terminology |
| 5181 | // Structured block - An executable statement with a single entry at the |
| 5182 | // top and a single exit at the bottom. |
| 5183 | // The point of exit cannot be a branch out of the structured block. |
| 5184 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5185 | CS->getCapturedDecl()->setNothrow(); |
| 5186 | |
| 5187 | getCurFunction()->setHasBranchProtectedScope(); |
| 5188 | |
| 5189 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5190 | } |
| 5191 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5192 | StmtResult |
| 5193 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5194 | SourceLocation EndLoc, |
| 5195 | OpenMPDirectiveKind CancelRegion) { |
| 5196 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5197 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5198 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5199 | << getOpenMPDirectiveName(CancelRegion); |
| 5200 | return StmtError(); |
| 5201 | } |
| 5202 | if (DSAStack->isParentNowaitRegion()) { |
| 5203 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5204 | return StmtError(); |
| 5205 | } |
| 5206 | if (DSAStack->isParentOrderedRegion()) { |
| 5207 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5208 | return StmtError(); |
| 5209 | } |
| 5210 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5211 | CancelRegion); |
| 5212 | } |
| 5213 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5214 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5215 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5216 | SourceLocation EndLoc, |
| 5217 | OpenMPDirectiveKind CancelRegion) { |
| 5218 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5219 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5220 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5221 | << getOpenMPDirectiveName(CancelRegion); |
| 5222 | return StmtError(); |
| 5223 | } |
| 5224 | if (DSAStack->isParentNowaitRegion()) { |
| 5225 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5226 | return StmtError(); |
| 5227 | } |
| 5228 | if (DSAStack->isParentOrderedRegion()) { |
| 5229 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5230 | return StmtError(); |
| 5231 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5232 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5233 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5234 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5235 | } |
| 5236 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5237 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5238 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5239 | SourceLocation EndLoc, |
| 5240 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5241 | if (!AStmt) |
| 5242 | return StmtError(); |
| 5243 | |
| 5244 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5245 | OMPLoopDirective::HelperExprs B; |
| 5246 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5247 | // define the nested loops number. |
| 5248 | unsigned NestedLoopCount = |
| 5249 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
| 5250 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5251 | VarsWithImplicitDSA, B); |
| 5252 | if (NestedLoopCount == 0) |
| 5253 | return StmtError(); |
| 5254 | |
| 5255 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5256 | "omp for loop exprs were not built"); |
| 5257 | |
| 5258 | getCurFunction()->setHasBranchProtectedScope(); |
| 5259 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5260 | NestedLoopCount, Clauses, AStmt, B); |
| 5261 | } |
| 5262 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5263 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5264 | SourceLocation StartLoc, |
| 5265 | SourceLocation LParenLoc, |
| 5266 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5267 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5268 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5269 | case OMPC_final: |
| 5270 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5271 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5272 | case OMPC_num_threads: |
| 5273 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5274 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5275 | case OMPC_safelen: |
| 5276 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5277 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5278 | case OMPC_simdlen: |
| 5279 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5280 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5281 | case OMPC_collapse: |
| 5282 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5283 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5284 | case OMPC_ordered: |
| 5285 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 5286 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5287 | case OMPC_device: |
| 5288 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5289 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5290 | case OMPC_num_teams: |
| 5291 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5292 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5293 | case OMPC_thread_limit: |
| 5294 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5295 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5296 | case OMPC_priority: |
| 5297 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 5298 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5299 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5300 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5301 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5302 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5303 | case OMPC_private: |
| 5304 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5305 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5306 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5307 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5308 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5309 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5310 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5311 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5312 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5313 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5314 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5315 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5316 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5317 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5318 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5319 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5320 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5321 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5322 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5323 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5324 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5325 | case OMPC_map: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5326 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5327 | llvm_unreachable("Clause is not allowed."); |
| 5328 | } |
| 5329 | return Res; |
| 5330 | } |
| 5331 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5332 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 5333 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5334 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5335 | SourceLocation NameModifierLoc, |
| 5336 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5337 | SourceLocation EndLoc) { |
| 5338 | Expr *ValExpr = Condition; |
| 5339 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5340 | !Condition->isInstantiationDependent() && |
| 5341 | !Condition->containsUnexpandedParameterPack()) { |
| 5342 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5343 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5344 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5345 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5346 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5347 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5348 | } |
| 5349 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5350 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5351 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5352 | } |
| 5353 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5354 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5355 | SourceLocation StartLoc, |
| 5356 | SourceLocation LParenLoc, |
| 5357 | SourceLocation EndLoc) { |
| 5358 | Expr *ValExpr = Condition; |
| 5359 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5360 | !Condition->isInstantiationDependent() && |
| 5361 | !Condition->containsUnexpandedParameterPack()) { |
| 5362 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5363 | Condition->getExprLoc(), Condition); |
| 5364 | if (Val.isInvalid()) |
| 5365 | return nullptr; |
| 5366 | |
| 5367 | ValExpr = Val.get(); |
| 5368 | } |
| 5369 | |
| 5370 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5371 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5372 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5373 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5374 | if (!Op) |
| 5375 | return ExprError(); |
| 5376 | |
| 5377 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5378 | public: |
| 5379 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5380 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5381 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5382 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5383 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5384 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5385 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5386 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5387 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5388 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5389 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5390 | QualType T, |
| 5391 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5392 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5393 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5394 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5395 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5396 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5397 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5398 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5399 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5400 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5401 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5402 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5403 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5404 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5405 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5406 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5407 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5408 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5409 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5410 | llvm_unreachable("conversion functions are permitted"); |
| 5411 | } |
| 5412 | } ConvertDiagnoser; |
| 5413 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5414 | } |
| 5415 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5416 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5417 | OpenMPClauseKind CKind, |
| 5418 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5419 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 5420 | !ValExpr->isInstantiationDependent()) { |
| 5421 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 5422 | ExprResult Value = |
| 5423 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 5424 | if (Value.isInvalid()) |
| 5425 | return false; |
| 5426 | |
| 5427 | ValExpr = Value.get(); |
| 5428 | // The expression must evaluate to a non-negative integer value. |
| 5429 | llvm::APSInt Result; |
| 5430 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5431 | Result.isSigned() && |
| 5432 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 5433 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5434 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5435 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 5436 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5437 | return false; |
| 5438 | } |
| 5439 | } |
| 5440 | return true; |
| 5441 | } |
| 5442 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5443 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5444 | SourceLocation StartLoc, |
| 5445 | SourceLocation LParenLoc, |
| 5446 | SourceLocation EndLoc) { |
| 5447 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5448 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5449 | // OpenMP [2.5, Restrictions] |
| 5450 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5451 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 5452 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5453 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5454 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5455 | return new (Context) |
| 5456 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5457 | } |
| 5458 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5459 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 5460 | OpenMPClauseKind CKind) { |
| 5461 | if (!E) |
| 5462 | return ExprError(); |
| 5463 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5464 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5465 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5466 | llvm::APSInt Result; |
| 5467 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5468 | if (ICE.isInvalid()) |
| 5469 | return ExprError(); |
| 5470 | if (!Result.isStrictlyPositive()) { |
| 5471 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5472 | << getOpenMPClauseName(CKind) << 1 << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5473 | return ExprError(); |
| 5474 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5475 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5476 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5477 | << E->getSourceRange(); |
| 5478 | return ExprError(); |
| 5479 | } |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5480 | if (CKind == OMPC_collapse) |
| 5481 | DSAStack->setCollapseNumber(Result.getExtValue()); |
| 5482 | else if (CKind == OMPC_ordered) |
| 5483 | DSAStack->setCollapseNumber(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5484 | return ICE; |
| 5485 | } |
| 5486 | |
| 5487 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5488 | SourceLocation LParenLoc, |
| 5489 | SourceLocation EndLoc) { |
| 5490 | // OpenMP [2.8.1, simd construct, Description] |
| 5491 | // The parameter of the safelen clause must be a constant |
| 5492 | // positive integer expression. |
| 5493 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5494 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5495 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5496 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5497 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5498 | } |
| 5499 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5500 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5501 | SourceLocation LParenLoc, |
| 5502 | SourceLocation EndLoc) { |
| 5503 | // OpenMP [2.8.1, simd construct, Description] |
| 5504 | // The parameter of the simdlen clause must be a constant |
| 5505 | // positive integer expression. |
| 5506 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5507 | if (Simdlen.isInvalid()) |
| 5508 | return nullptr; |
| 5509 | return new (Context) |
| 5510 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5511 | } |
| 5512 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5513 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5514 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5515 | SourceLocation LParenLoc, |
| 5516 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5517 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5518 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5519 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5520 | // The parameter of the collapse clause must be a constant |
| 5521 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5522 | ExprResult NumForLoopsResult = |
| 5523 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5524 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5525 | return nullptr; |
| 5526 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5527 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5528 | } |
| 5529 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5530 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5531 | SourceLocation EndLoc, |
| 5532 | SourceLocation LParenLoc, |
| 5533 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5534 | // OpenMP [2.7.1, loop construct, Description] |
| 5535 | // OpenMP [2.8.1, simd construct, Description] |
| 5536 | // OpenMP [2.9.6, distribute construct, Description] |
| 5537 | // The parameter of the ordered clause must be a constant |
| 5538 | // positive integer expression if any. |
| 5539 | if (NumForLoops && LParenLoc.isValid()) { |
| 5540 | ExprResult NumForLoopsResult = |
| 5541 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5542 | if (NumForLoopsResult.isInvalid()) |
| 5543 | return nullptr; |
| 5544 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5545 | } else |
| 5546 | NumForLoops = nullptr; |
| 5547 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5548 | return new (Context) |
| 5549 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5550 | } |
| 5551 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5552 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5553 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5554 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5555 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5556 | switch (Kind) { |
| 5557 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5558 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5559 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5560 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5561 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5562 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5563 | Res = ActOnOpenMPProcBindClause( |
| 5564 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5565 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5566 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5567 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5568 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5569 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5570 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5571 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5572 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5573 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5574 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5575 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5576 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5577 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5578 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5579 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5580 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5581 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5582 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5583 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5584 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5585 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5586 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5587 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5588 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5589 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5590 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5591 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5592 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5593 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5594 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5595 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5596 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5597 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5598 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5599 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5600 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5601 | case OMPC_priority: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5602 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5603 | llvm_unreachable("Clause is not allowed."); |
| 5604 | } |
| 5605 | return Res; |
| 5606 | } |
| 5607 | |
| 5608 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 5609 | SourceLocation KindKwLoc, |
| 5610 | SourceLocation StartLoc, |
| 5611 | SourceLocation LParenLoc, |
| 5612 | SourceLocation EndLoc) { |
| 5613 | if (Kind == OMPC_DEFAULT_unknown) { |
| 5614 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5615 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 5616 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 5617 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5618 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5619 | Values += "'"; |
| 5620 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 5621 | Values += "'"; |
| 5622 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5623 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5624 | Values += " or "; |
| 5625 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5626 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5627 | break; |
| 5628 | default: |
| 5629 | Values += Sep; |
| 5630 | break; |
| 5631 | } |
| 5632 | } |
| 5633 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5634 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5635 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5636 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5637 | switch (Kind) { |
| 5638 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5639 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5640 | break; |
| 5641 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5642 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5643 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5644 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5645 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5646 | break; |
| 5647 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5648 | return new (Context) |
| 5649 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5650 | } |
| 5651 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5652 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5653 | SourceLocation KindKwLoc, |
| 5654 | SourceLocation StartLoc, |
| 5655 | SourceLocation LParenLoc, |
| 5656 | SourceLocation EndLoc) { |
| 5657 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5658 | std::string Values; |
| 5659 | std::string Sep(", "); |
| 5660 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 5661 | Values += "'"; |
| 5662 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 5663 | Values += "'"; |
| 5664 | switch (i) { |
| 5665 | case OMPC_PROC_BIND_unknown - 2: |
| 5666 | Values += " or "; |
| 5667 | break; |
| 5668 | case OMPC_PROC_BIND_unknown - 1: |
| 5669 | break; |
| 5670 | default: |
| 5671 | Values += Sep; |
| 5672 | break; |
| 5673 | } |
| 5674 | } |
| 5675 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5676 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5677 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5678 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5679 | return new (Context) |
| 5680 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5681 | } |
| 5682 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5683 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 5684 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 5685 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5686 | SourceLocation ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5687 | SourceLocation EndLoc) { |
| 5688 | OMPClause *Res = nullptr; |
| 5689 | switch (Kind) { |
| 5690 | case OMPC_schedule: |
| 5691 | Res = ActOnOpenMPScheduleClause( |
| 5692 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5693 | LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5694 | break; |
| 5695 | case OMPC_if: |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5696 | Res = |
| 5697 | ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr, |
| 5698 | StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
| 5699 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5700 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5701 | case OMPC_num_threads: |
| 5702 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5703 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5704 | case OMPC_collapse: |
| 5705 | case OMPC_default: |
| 5706 | case OMPC_proc_bind: |
| 5707 | case OMPC_private: |
| 5708 | case OMPC_firstprivate: |
| 5709 | case OMPC_lastprivate: |
| 5710 | case OMPC_shared: |
| 5711 | case OMPC_reduction: |
| 5712 | case OMPC_linear: |
| 5713 | case OMPC_aligned: |
| 5714 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5715 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5716 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5717 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5718 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5719 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5720 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5721 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5722 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5723 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5724 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5725 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5726 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5727 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5728 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5729 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5730 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5731 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5732 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5733 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5734 | case OMPC_priority: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5735 | case OMPC_unknown: |
| 5736 | llvm_unreachable("Clause is not allowed."); |
| 5737 | } |
| 5738 | return Res; |
| 5739 | } |
| 5740 | |
| 5741 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 5742 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 5743 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 5744 | SourceLocation EndLoc) { |
| 5745 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 5746 | std::string Values; |
| 5747 | std::string Sep(", "); |
| 5748 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 5749 | Values += "'"; |
| 5750 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 5751 | Values += "'"; |
| 5752 | switch (i) { |
| 5753 | case OMPC_SCHEDULE_unknown - 2: |
| 5754 | Values += " or "; |
| 5755 | break; |
| 5756 | case OMPC_SCHEDULE_unknown - 1: |
| 5757 | break; |
| 5758 | default: |
| 5759 | Values += Sep; |
| 5760 | break; |
| 5761 | } |
| 5762 | } |
| 5763 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 5764 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 5765 | return nullptr; |
| 5766 | } |
| 5767 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5768 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5769 | if (ChunkSize) { |
| 5770 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 5771 | !ChunkSize->isInstantiationDependent() && |
| 5772 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 5773 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 5774 | ExprResult Val = |
| 5775 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 5776 | if (Val.isInvalid()) |
| 5777 | return nullptr; |
| 5778 | |
| 5779 | ValExpr = Val.get(); |
| 5780 | |
| 5781 | // OpenMP [2.7.1, Restrictions] |
| 5782 | // chunk_size must be a loop invariant integer expression with a positive |
| 5783 | // value. |
| 5784 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5785 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 5786 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 5787 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5788 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5789 | return nullptr; |
| 5790 | } |
| 5791 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 5792 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 5793 | ChunkSize->getType(), ".chunk."); |
| 5794 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 5795 | ChunkSize->getExprLoc(), |
| 5796 | /*RefersToCapture=*/true); |
| 5797 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5798 | } |
| 5799 | } |
| 5800 | } |
| 5801 | |
| 5802 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5803 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5804 | } |
| 5805 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5806 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 5807 | SourceLocation StartLoc, |
| 5808 | SourceLocation EndLoc) { |
| 5809 | OMPClause *Res = nullptr; |
| 5810 | switch (Kind) { |
| 5811 | case OMPC_ordered: |
| 5812 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 5813 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5814 | case OMPC_nowait: |
| 5815 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 5816 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5817 | case OMPC_untied: |
| 5818 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 5819 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5820 | case OMPC_mergeable: |
| 5821 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 5822 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5823 | case OMPC_read: |
| 5824 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 5825 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5826 | case OMPC_write: |
| 5827 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 5828 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5829 | case OMPC_update: |
| 5830 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 5831 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5832 | case OMPC_capture: |
| 5833 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 5834 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5835 | case OMPC_seq_cst: |
| 5836 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 5837 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5838 | case OMPC_threads: |
| 5839 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 5840 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5841 | case OMPC_simd: |
| 5842 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 5843 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5844 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5845 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5846 | case OMPC_num_threads: |
| 5847 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5848 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5849 | case OMPC_collapse: |
| 5850 | case OMPC_schedule: |
| 5851 | case OMPC_private: |
| 5852 | case OMPC_firstprivate: |
| 5853 | case OMPC_lastprivate: |
| 5854 | case OMPC_shared: |
| 5855 | case OMPC_reduction: |
| 5856 | case OMPC_linear: |
| 5857 | case OMPC_aligned: |
| 5858 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5859 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5860 | case OMPC_default: |
| 5861 | case OMPC_proc_bind: |
| 5862 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5863 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5864 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5865 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5866 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5867 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 5868 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 5869 | case OMPC_priority: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5870 | case OMPC_unknown: |
| 5871 | llvm_unreachable("Clause is not allowed."); |
| 5872 | } |
| 5873 | return Res; |
| 5874 | } |
| 5875 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5876 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 5877 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5878 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5879 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 5880 | } |
| 5881 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5882 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 5883 | SourceLocation EndLoc) { |
| 5884 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 5885 | } |
| 5886 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5887 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 5888 | SourceLocation EndLoc) { |
| 5889 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 5890 | } |
| 5891 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5892 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 5893 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5894 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 5895 | } |
| 5896 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5897 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 5898 | SourceLocation EndLoc) { |
| 5899 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 5900 | } |
| 5901 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5902 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 5903 | SourceLocation EndLoc) { |
| 5904 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 5905 | } |
| 5906 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5907 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 5908 | SourceLocation EndLoc) { |
| 5909 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 5910 | } |
| 5911 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5912 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 5913 | SourceLocation EndLoc) { |
| 5914 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 5915 | } |
| 5916 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5917 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 5918 | SourceLocation EndLoc) { |
| 5919 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 5920 | } |
| 5921 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5922 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 5923 | SourceLocation EndLoc) { |
| 5924 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 5925 | } |
| 5926 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5927 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 5928 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 5929 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 5930 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5931 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5932 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 5933 | OpenMPMapClauseKind MapType, SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5934 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5935 | switch (Kind) { |
| 5936 | case OMPC_private: |
| 5937 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5938 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5939 | case OMPC_firstprivate: |
| 5940 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5941 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5942 | case OMPC_lastprivate: |
| 5943 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5944 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5945 | case OMPC_shared: |
| 5946 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5947 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5948 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5949 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 5950 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5951 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5952 | case OMPC_linear: |
| 5953 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5954 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5955 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5956 | case OMPC_aligned: |
| 5957 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 5958 | ColonLoc, EndLoc); |
| 5959 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5960 | case OMPC_copyin: |
| 5961 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5962 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5963 | case OMPC_copyprivate: |
| 5964 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5965 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5966 | case OMPC_flush: |
| 5967 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5968 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5969 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 5970 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 5971 | StartLoc, LParenLoc, EndLoc); |
| 5972 | break; |
| 5973 | case OMPC_map: |
| 5974 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, DepLinMapLoc, ColonLoc, |
| 5975 | VarList, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5976 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5977 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5978 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5979 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5980 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5981 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5982 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5983 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5984 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5985 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5986 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5987 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5988 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5989 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5990 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5991 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5992 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5993 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5994 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5995 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5996 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5997 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5998 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 5999 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6000 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6001 | case OMPC_priority: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6002 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6003 | llvm_unreachable("Clause is not allowed."); |
| 6004 | } |
| 6005 | return Res; |
| 6006 | } |
| 6007 | |
| 6008 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 6009 | SourceLocation StartLoc, |
| 6010 | SourceLocation LParenLoc, |
| 6011 | SourceLocation EndLoc) { |
| 6012 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6013 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6014 | for (auto &RefExpr : VarList) { |
| 6015 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 6016 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6017 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6018 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6019 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6020 | continue; |
| 6021 | } |
| 6022 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6023 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6024 | // OpenMP [2.1, C/C++] |
| 6025 | // A list item is a variable name. |
| 6026 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6027 | // A variable that is part of another variable (as an array or |
| 6028 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6029 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6030 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6031 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6032 | continue; |
| 6033 | } |
| 6034 | Decl *D = DE->getDecl(); |
| 6035 | VarDecl *VD = cast<VarDecl>(D); |
| 6036 | |
| 6037 | QualType Type = VD->getType(); |
| 6038 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6039 | // It will be analyzed later. |
| 6040 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6041 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6042 | continue; |
| 6043 | } |
| 6044 | |
| 6045 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6046 | // A variable that appears in a private clause must not have an incomplete |
| 6047 | // type or a reference type. |
| 6048 | if (RequireCompleteType(ELoc, Type, |
| 6049 | diag::err_omp_private_incomplete_type)) { |
| 6050 | continue; |
| 6051 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6052 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6053 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6054 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6055 | // in a Construct] |
| 6056 | // Variables with the predetermined data-sharing attributes may not be |
| 6057 | // listed in data-sharing attributes clauses, except for the cases |
| 6058 | // listed below. For these exceptions only, listing a predetermined |
| 6059 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6060 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6061 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6062 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6063 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6064 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6065 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6066 | continue; |
| 6067 | } |
| 6068 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6069 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6070 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6071 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6072 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6073 | << getOpenMPClauseName(OMPC_private) << Type |
| 6074 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6075 | bool IsDecl = |
| 6076 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6077 | Diag(VD->getLocation(), |
| 6078 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6079 | << VD; |
| 6080 | continue; |
| 6081 | } |
| 6082 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6083 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 6084 | // A variable of class type (or array thereof) that appears in a private |
| 6085 | // clause requires an accessible, unambiguous default constructor for the |
| 6086 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6087 | // Generate helper private variable and initialize it with the default |
| 6088 | // value. The address of the original variable is replaced by the address of |
| 6089 | // the new private variable in CodeGen. This new variable is not added to |
| 6090 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 6091 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6092 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6093 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 6094 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6095 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6096 | if (VDPrivate->isInvalidDecl()) |
| 6097 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6098 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6099 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6100 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6101 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6102 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6103 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6104 | } |
| 6105 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6106 | if (Vars.empty()) |
| 6107 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6108 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 6109 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6110 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6111 | } |
| 6112 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6113 | namespace { |
| 6114 | class DiagsUninitializedSeveretyRAII { |
| 6115 | private: |
| 6116 | DiagnosticsEngine &Diags; |
| 6117 | SourceLocation SavedLoc; |
| 6118 | bool IsIgnored; |
| 6119 | |
| 6120 | public: |
| 6121 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 6122 | bool IsIgnored) |
| 6123 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 6124 | if (!IsIgnored) { |
| 6125 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 6126 | /*Map*/ diag::Severity::Ignored, Loc); |
| 6127 | } |
| 6128 | } |
| 6129 | ~DiagsUninitializedSeveretyRAII() { |
| 6130 | if (!IsIgnored) |
| 6131 | Diags.popMappings(SavedLoc); |
| 6132 | } |
| 6133 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 6134 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6135 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6136 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 6137 | SourceLocation StartLoc, |
| 6138 | SourceLocation LParenLoc, |
| 6139 | SourceLocation EndLoc) { |
| 6140 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6141 | SmallVector<Expr *, 8> PrivateCopies; |
| 6142 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6143 | bool IsImplicitClause = |
| 6144 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 6145 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 6146 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6147 | for (auto &RefExpr : VarList) { |
| 6148 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 6149 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6150 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6151 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6152 | PrivateCopies.push_back(nullptr); |
| 6153 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6154 | continue; |
| 6155 | } |
| 6156 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6157 | SourceLocation ELoc = |
| 6158 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6159 | // OpenMP [2.1, C/C++] |
| 6160 | // A list item is a variable name. |
| 6161 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 6162 | // A variable that is part of another variable (as an array or |
| 6163 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6164 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6165 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6166 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6167 | continue; |
| 6168 | } |
| 6169 | Decl *D = DE->getDecl(); |
| 6170 | VarDecl *VD = cast<VarDecl>(D); |
| 6171 | |
| 6172 | QualType Type = VD->getType(); |
| 6173 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6174 | // It will be analyzed later. |
| 6175 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6176 | PrivateCopies.push_back(nullptr); |
| 6177 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6178 | continue; |
| 6179 | } |
| 6180 | |
| 6181 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6182 | // A variable that appears in a private clause must not have an incomplete |
| 6183 | // type or a reference type. |
| 6184 | if (RequireCompleteType(ELoc, Type, |
| 6185 | diag::err_omp_firstprivate_incomplete_type)) { |
| 6186 | continue; |
| 6187 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6188 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6189 | |
| 6190 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 6191 | // 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] | 6192 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6193 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6194 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6195 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6196 | // If an implicit firstprivate variable found it was checked already. |
| 6197 | if (!IsImplicitClause) { |
| 6198 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6199 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6200 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 6201 | // A list item that specifies a given variable may not appear in more |
| 6202 | // than one clause on the same directive, except that a variable may be |
| 6203 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6204 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6205 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6206 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6207 | << getOpenMPClauseName(DVar.CKind) |
| 6208 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6209 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6210 | continue; |
| 6211 | } |
| 6212 | |
| 6213 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6214 | // in a Construct] |
| 6215 | // Variables with the predetermined data-sharing attributes may not be |
| 6216 | // listed in data-sharing attributes clauses, except for the cases |
| 6217 | // listed below. For these exceptions only, listing a predetermined |
| 6218 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6219 | // the variable's predetermined data-sharing attributes. |
| 6220 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6221 | // in a Construct, C/C++, p.2] |
| 6222 | // Variables with const-qualified type having no mutable member may be |
| 6223 | // listed in a firstprivate clause, even if they are static data members. |
| 6224 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 6225 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 6226 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6227 | << getOpenMPClauseName(DVar.CKind) |
| 6228 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6229 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6230 | continue; |
| 6231 | } |
| 6232 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6233 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6234 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 6235 | // A list item that is private within a parallel region must not appear |
| 6236 | // in a firstprivate clause on a worksharing construct if any of the |
| 6237 | // worksharing regions arising from the worksharing construct ever bind |
| 6238 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6239 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6240 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6241 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6242 | if (DVar.CKind != OMPC_shared && |
| 6243 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6244 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6245 | Diag(ELoc, diag::err_omp_required_access) |
| 6246 | << getOpenMPClauseName(OMPC_firstprivate) |
| 6247 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6248 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6249 | continue; |
| 6250 | } |
| 6251 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6252 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 6253 | // A list item that appears in a reduction clause of a parallel construct |
| 6254 | // must not appear in a firstprivate clause on a worksharing or task |
| 6255 | // construct if any of the worksharing or task regions arising from the |
| 6256 | // worksharing or task construct ever bind to any of the parallel regions |
| 6257 | // arising from the parallel construct. |
| 6258 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 6259 | // A list item that appears in a reduction clause in worksharing |
| 6260 | // construct must not appear in a firstprivate clause in a task construct |
| 6261 | // encountered during execution of any of the worksharing regions arising |
| 6262 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6263 | if (CurrDir == OMPD_task) { |
| 6264 | DVar = |
| 6265 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 6266 | [](OpenMPDirectiveKind K) -> bool { |
| 6267 | return isOpenMPParallelDirective(K) || |
| 6268 | isOpenMPWorksharingDirective(K); |
| 6269 | }, |
| 6270 | false); |
| 6271 | if (DVar.CKind == OMPC_reduction && |
| 6272 | (isOpenMPParallelDirective(DVar.DKind) || |
| 6273 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 6274 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 6275 | << getOpenMPDirectiveName(DVar.DKind); |
| 6276 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6277 | continue; |
| 6278 | } |
| 6279 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6280 | } |
| 6281 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6282 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6283 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6284 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 6285 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 6286 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 6287 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 6288 | bool IsDecl = |
| 6289 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6290 | Diag(VD->getLocation(), |
| 6291 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6292 | << VD; |
| 6293 | continue; |
| 6294 | } |
| 6295 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6296 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6297 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6298 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6299 | // Generate helper private variable and initialize it with the value of the |
| 6300 | // original variable. The address of the original variable is replaced by |
| 6301 | // the address of the new private variable in the CodeGen. This new variable |
| 6302 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 6303 | // original variable for proper diagnostics and variable capturing. |
| 6304 | Expr *VDInitRefExpr = nullptr; |
| 6305 | // For arrays generate initializer for single element and replace it by the |
| 6306 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6307 | if (Type->isArrayType()) { |
| 6308 | auto VDInit = |
| 6309 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 6310 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6311 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6312 | ElemType = ElemType.getUnqualifiedType(); |
| 6313 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 6314 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6315 | InitializedEntity Entity = |
| 6316 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6317 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 6318 | |
| 6319 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 6320 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 6321 | if (Result.isInvalid()) |
| 6322 | VDPrivate->setInvalidDecl(); |
| 6323 | else |
| 6324 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6325 | // Remove temp variable declaration. |
| 6326 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6327 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6328 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6329 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6330 | VDInitRefExpr = |
| 6331 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 6332 | AddInitializerToDecl(VDPrivate, |
| 6333 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 6334 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6335 | } |
| 6336 | if (VDPrivate->isInvalidDecl()) { |
| 6337 | if (IsImplicitClause) { |
| 6338 | Diag(DE->getExprLoc(), |
| 6339 | diag::note_omp_task_predetermined_firstprivate_here); |
| 6340 | } |
| 6341 | continue; |
| 6342 | } |
| 6343 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6344 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 6345 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6346 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 6347 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6348 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 6349 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6350 | } |
| 6351 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6352 | if (Vars.empty()) |
| 6353 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6354 | |
| 6355 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 6356 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6357 | } |
| 6358 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6359 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 6360 | SourceLocation StartLoc, |
| 6361 | SourceLocation LParenLoc, |
| 6362 | SourceLocation EndLoc) { |
| 6363 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6364 | SmallVector<Expr *, 8> SrcExprs; |
| 6365 | SmallVector<Expr *, 8> DstExprs; |
| 6366 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6367 | for (auto &RefExpr : VarList) { |
| 6368 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 6369 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6370 | // It will be analyzed later. |
| 6371 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6372 | SrcExprs.push_back(nullptr); |
| 6373 | DstExprs.push_back(nullptr); |
| 6374 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6375 | continue; |
| 6376 | } |
| 6377 | |
| 6378 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6379 | // OpenMP [2.1, C/C++] |
| 6380 | // A list item is a variable name. |
| 6381 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 6382 | // A variable that is part of another variable (as an array or structure |
| 6383 | // element) cannot appear in a lastprivate clause. |
| 6384 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 6385 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6386 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6387 | continue; |
| 6388 | } |
| 6389 | Decl *D = DE->getDecl(); |
| 6390 | VarDecl *VD = cast<VarDecl>(D); |
| 6391 | |
| 6392 | QualType Type = VD->getType(); |
| 6393 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6394 | // It will be analyzed later. |
| 6395 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6396 | SrcExprs.push_back(nullptr); |
| 6397 | DstExprs.push_back(nullptr); |
| 6398 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6399 | continue; |
| 6400 | } |
| 6401 | |
| 6402 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6403 | // A variable that appears in a lastprivate clause must not have an |
| 6404 | // incomplete type or a reference type. |
| 6405 | if (RequireCompleteType(ELoc, Type, |
| 6406 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6407 | continue; |
| 6408 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6409 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6410 | |
| 6411 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6412 | // in a Construct] |
| 6413 | // Variables with the predetermined data-sharing attributes may not be |
| 6414 | // listed in data-sharing attributes clauses, except for the cases |
| 6415 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6416 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6417 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6418 | DVar.CKind != OMPC_firstprivate && |
| 6419 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6420 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6421 | << getOpenMPClauseName(DVar.CKind) |
| 6422 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6423 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6424 | continue; |
| 6425 | } |
| 6426 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6427 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6428 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6429 | // A list item that is private within a parallel region, or that appears in |
| 6430 | // the reduction clause of a parallel construct, must not appear in a |
| 6431 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6432 | // worksharing regions ever binds to any of the corresponding parallel |
| 6433 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6434 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6435 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6436 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6437 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6438 | if (DVar.CKind != OMPC_shared) { |
| 6439 | Diag(ELoc, diag::err_omp_required_access) |
| 6440 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6441 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6442 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6443 | continue; |
| 6444 | } |
| 6445 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6446 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6447 | // A variable of class type (or array thereof) that appears in a |
| 6448 | // lastprivate clause requires an accessible, unambiguous default |
| 6449 | // constructor for the class type, unless the list item is also specified |
| 6450 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6451 | // A variable of class type (or array thereof) that appears in a |
| 6452 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6453 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6454 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6455 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6456 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6457 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6458 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6459 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6460 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6461 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6462 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6463 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6464 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6465 | // For arrays generate assignment operation for single element and replace |
| 6466 | // it by the original array element in CodeGen. |
| 6467 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6468 | PseudoDstExpr, PseudoSrcExpr); |
| 6469 | if (AssignmentOp.isInvalid()) |
| 6470 | continue; |
| 6471 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6472 | /*DiscardedValue=*/true); |
| 6473 | if (AssignmentOp.isInvalid()) |
| 6474 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6475 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6476 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6477 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6478 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6479 | SrcExprs.push_back(PseudoSrcExpr); |
| 6480 | DstExprs.push_back(PseudoDstExpr); |
| 6481 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6482 | } |
| 6483 | |
| 6484 | if (Vars.empty()) |
| 6485 | return nullptr; |
| 6486 | |
| 6487 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6488 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6489 | } |
| 6490 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6491 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 6492 | SourceLocation StartLoc, |
| 6493 | SourceLocation LParenLoc, |
| 6494 | SourceLocation EndLoc) { |
| 6495 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6496 | for (auto &RefExpr : VarList) { |
| 6497 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6498 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6499 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6500 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6501 | continue; |
| 6502 | } |
| 6503 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6504 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6505 | // OpenMP [2.1, C/C++] |
| 6506 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 6507 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 6508 | // A variable that is part of another variable (as an array or structure |
| 6509 | // element) cannot appear in a shared unless it is a static data member |
| 6510 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6511 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6512 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6513 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6514 | continue; |
| 6515 | } |
| 6516 | Decl *D = DE->getDecl(); |
| 6517 | VarDecl *VD = cast<VarDecl>(D); |
| 6518 | |
| 6519 | QualType Type = VD->getType(); |
| 6520 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6521 | // It will be analyzed later. |
| 6522 | Vars.push_back(DE); |
| 6523 | continue; |
| 6524 | } |
| 6525 | |
| 6526 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6527 | // in a Construct] |
| 6528 | // Variables with the predetermined data-sharing attributes may not be |
| 6529 | // listed in data-sharing attributes clauses, except for the cases |
| 6530 | // listed below. For these exceptions only, listing a predetermined |
| 6531 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6532 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6533 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6534 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 6535 | DVar.RefExpr) { |
| 6536 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6537 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6538 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6539 | continue; |
| 6540 | } |
| 6541 | |
| 6542 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 6543 | Vars.push_back(DE); |
| 6544 | } |
| 6545 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6546 | if (Vars.empty()) |
| 6547 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6548 | |
| 6549 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 6550 | } |
| 6551 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6552 | namespace { |
| 6553 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 6554 | DSAStackTy *Stack; |
| 6555 | |
| 6556 | public: |
| 6557 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 6558 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6559 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6560 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 6561 | return false; |
| 6562 | if (DVar.CKind != OMPC_unknown) |
| 6563 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6564 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6565 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6566 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6567 | return true; |
| 6568 | return false; |
| 6569 | } |
| 6570 | return false; |
| 6571 | } |
| 6572 | bool VisitStmt(Stmt *S) { |
| 6573 | for (auto Child : S->children()) { |
| 6574 | if (Child && Visit(Child)) |
| 6575 | return true; |
| 6576 | } |
| 6577 | return false; |
| 6578 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6579 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6580 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6581 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6582 | |
| 6583 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 6584 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 6585 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 6586 | CXXScopeSpec &ReductionIdScopeSpec, |
| 6587 | const DeclarationNameInfo &ReductionId) { |
| 6588 | // TODO: Allow scope specification search when 'declare reduction' is |
| 6589 | // supported. |
| 6590 | assert(ReductionIdScopeSpec.isEmpty() && |
| 6591 | "No support for scoped reduction identifiers yet."); |
| 6592 | |
| 6593 | auto DN = ReductionId.getName(); |
| 6594 | auto OOK = DN.getCXXOverloadedOperator(); |
| 6595 | BinaryOperatorKind BOK = BO_Comma; |
| 6596 | |
| 6597 | // OpenMP [2.14.3.6, reduction clause] |
| 6598 | // C |
| 6599 | // reduction-identifier is either an identifier or one of the following |
| 6600 | // operators: +, -, *, &, |, ^, && and || |
| 6601 | // C++ |
| 6602 | // reduction-identifier is either an id-expression or one of the following |
| 6603 | // operators: +, -, *, &, |, ^, && and || |
| 6604 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 6605 | switch (OOK) { |
| 6606 | case OO_Plus: |
| 6607 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6608 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6609 | break; |
| 6610 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6611 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6612 | break; |
| 6613 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6614 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6615 | break; |
| 6616 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6617 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6618 | break; |
| 6619 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6620 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6621 | break; |
| 6622 | case OO_AmpAmp: |
| 6623 | BOK = BO_LAnd; |
| 6624 | break; |
| 6625 | case OO_PipePipe: |
| 6626 | BOK = BO_LOr; |
| 6627 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6628 | case OO_New: |
| 6629 | case OO_Delete: |
| 6630 | case OO_Array_New: |
| 6631 | case OO_Array_Delete: |
| 6632 | case OO_Slash: |
| 6633 | case OO_Percent: |
| 6634 | case OO_Tilde: |
| 6635 | case OO_Exclaim: |
| 6636 | case OO_Equal: |
| 6637 | case OO_Less: |
| 6638 | case OO_Greater: |
| 6639 | case OO_LessEqual: |
| 6640 | case OO_GreaterEqual: |
| 6641 | case OO_PlusEqual: |
| 6642 | case OO_MinusEqual: |
| 6643 | case OO_StarEqual: |
| 6644 | case OO_SlashEqual: |
| 6645 | case OO_PercentEqual: |
| 6646 | case OO_CaretEqual: |
| 6647 | case OO_AmpEqual: |
| 6648 | case OO_PipeEqual: |
| 6649 | case OO_LessLess: |
| 6650 | case OO_GreaterGreater: |
| 6651 | case OO_LessLessEqual: |
| 6652 | case OO_GreaterGreaterEqual: |
| 6653 | case OO_EqualEqual: |
| 6654 | case OO_ExclaimEqual: |
| 6655 | case OO_PlusPlus: |
| 6656 | case OO_MinusMinus: |
| 6657 | case OO_Comma: |
| 6658 | case OO_ArrowStar: |
| 6659 | case OO_Arrow: |
| 6660 | case OO_Call: |
| 6661 | case OO_Subscript: |
| 6662 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 6663 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6664 | case NUM_OVERLOADED_OPERATORS: |
| 6665 | llvm_unreachable("Unexpected reduction identifier"); |
| 6666 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6667 | if (auto II = DN.getAsIdentifierInfo()) { |
| 6668 | if (II->isStr("max")) |
| 6669 | BOK = BO_GT; |
| 6670 | else if (II->isStr("min")) |
| 6671 | BOK = BO_LT; |
| 6672 | } |
| 6673 | break; |
| 6674 | } |
| 6675 | SourceRange ReductionIdRange; |
| 6676 | if (ReductionIdScopeSpec.isValid()) { |
| 6677 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 6678 | } |
| 6679 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 6680 | if (BOK == BO_Comma) { |
| 6681 | // Not allowed reduction identifier is found. |
| 6682 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 6683 | << ReductionIdRange; |
| 6684 | return nullptr; |
| 6685 | } |
| 6686 | |
| 6687 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6688 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6689 | SmallVector<Expr *, 8> LHSs; |
| 6690 | SmallVector<Expr *, 8> RHSs; |
| 6691 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6692 | for (auto RefExpr : VarList) { |
| 6693 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 6694 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6695 | // It will be analyzed later. |
| 6696 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6697 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6698 | LHSs.push_back(nullptr); |
| 6699 | RHSs.push_back(nullptr); |
| 6700 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6701 | continue; |
| 6702 | } |
| 6703 | |
| 6704 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6705 | RefExpr->isInstantiationDependent() || |
| 6706 | RefExpr->containsUnexpandedParameterPack()) { |
| 6707 | // It will be analyzed later. |
| 6708 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6709 | Privates.push_back(nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6710 | LHSs.push_back(nullptr); |
| 6711 | RHSs.push_back(nullptr); |
| 6712 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6713 | continue; |
| 6714 | } |
| 6715 | |
| 6716 | auto ELoc = RefExpr->getExprLoc(); |
| 6717 | auto ERange = RefExpr->getSourceRange(); |
| 6718 | // OpenMP [2.1, C/C++] |
| 6719 | // A list item is a variable or array section, subject to the restrictions |
| 6720 | // specified in Section 2.4 on page 42 and in each of the sections |
| 6721 | // describing clauses and directives for which a list appears. |
| 6722 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6723 | // A variable that is part of another variable (as an array or |
| 6724 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6725 | auto *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6726 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr); |
| 6727 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr); |
| 6728 | if (!ASE && !OASE && (!DE || !isa<VarDecl>(DE->getDecl()))) { |
| 6729 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) << ERange; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6730 | continue; |
| 6731 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6732 | QualType Type; |
| 6733 | VarDecl *VD = nullptr; |
| 6734 | if (DE) { |
| 6735 | auto D = DE->getDecl(); |
| 6736 | VD = cast<VarDecl>(D); |
| 6737 | Type = VD->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6738 | } else if (ASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6739 | Type = ASE->getType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6740 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 6741 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 6742 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 6743 | DE = dyn_cast<DeclRefExpr>(Base); |
| 6744 | if (DE) |
| 6745 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 6746 | if (!VD) { |
| 6747 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 6748 | << 0 << Base->getSourceRange(); |
| 6749 | continue; |
| 6750 | } |
| 6751 | } else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6752 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 6753 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 6754 | Type = ATy->getElementType(); |
| 6755 | else |
| 6756 | Type = BaseType->getPointeeType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6757 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 6758 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 6759 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 6760 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 6761 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 6762 | DE = dyn_cast<DeclRefExpr>(Base); |
| 6763 | if (DE) |
| 6764 | VD = dyn_cast<VarDecl>(DE->getDecl()); |
| 6765 | if (!VD) { |
| 6766 | Diag(Base->getExprLoc(), diag::err_omp_expected_base_var_name) |
| 6767 | << 1 << Base->getSourceRange(); |
| 6768 | continue; |
| 6769 | } |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6770 | } |
| 6771 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6772 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6773 | // A variable that appears in a private clause must not have an incomplete |
| 6774 | // type or a reference type. |
| 6775 | if (RequireCompleteType(ELoc, Type, |
| 6776 | diag::err_omp_reduction_incomplete_type)) |
| 6777 | continue; |
| 6778 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6779 | // Arrays may not appear in a reduction clause. |
| 6780 | if (Type.getNonReferenceType()->isArrayType()) { |
| 6781 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6782 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6783 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6784 | VarDecl::DeclarationOnly; |
| 6785 | Diag(VD->getLocation(), |
| 6786 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6787 | << VD; |
| 6788 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6789 | continue; |
| 6790 | } |
| 6791 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6792 | // A list item that appears in a reduction clause must not be |
| 6793 | // const-qualified. |
| 6794 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6795 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6796 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6797 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6798 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6799 | VarDecl::DeclarationOnly; |
| 6800 | Diag(VD->getLocation(), |
| 6801 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6802 | << VD; |
| 6803 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6804 | continue; |
| 6805 | } |
| 6806 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 6807 | // If a list-item is a reference type then it must bind to the same object |
| 6808 | // for all threads of the team. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6809 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6810 | VarDecl *VDDef = VD->getDefinition(); |
| 6811 | if (Type->isReferenceType() && VDDef) { |
| 6812 | DSARefChecker Check(DSAStack); |
| 6813 | if (Check.Visit(VDDef->getInit())) { |
| 6814 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 6815 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 6816 | continue; |
| 6817 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6818 | } |
| 6819 | } |
| 6820 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6821 | // The type of a list item that appears in a reduction clause must be valid |
| 6822 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 6823 | // of the list item must be an allowed arithmetic data type: char, int, |
| 6824 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 6825 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 6826 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 6827 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 6828 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 6829 | !(Type->isScalarType() || |
| 6830 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 6831 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 6832 | << getLangOpts().CPlusPlus; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6833 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6834 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6835 | VarDecl::DeclarationOnly; |
| 6836 | Diag(VD->getLocation(), |
| 6837 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6838 | << VD; |
| 6839 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6840 | continue; |
| 6841 | } |
| 6842 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 6843 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 6844 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6845 | if (!ASE && !OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6846 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 6847 | VarDecl::DeclarationOnly; |
| 6848 | Diag(VD->getLocation(), |
| 6849 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6850 | << VD; |
| 6851 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6852 | continue; |
| 6853 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6854 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6855 | // in a Construct] |
| 6856 | // Variables with the predetermined data-sharing attributes may not be |
| 6857 | // listed in data-sharing attributes clauses, except for the cases |
| 6858 | // listed below. For these exceptions only, listing a predetermined |
| 6859 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6860 | // the variable's predetermined data-sharing attributes. |
| 6861 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 6862 | // Any number of reduction clauses can be specified on the directive, |
| 6863 | // but a list item can appear only once in the reduction clauses for that |
| 6864 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 6865 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6866 | DVar = DSAStack->getTopDSA(VD, false); |
| 6867 | if (DVar.CKind == OMPC_reduction) { |
| 6868 | Diag(ELoc, diag::err_omp_once_referenced) |
| 6869 | << getOpenMPClauseName(OMPC_reduction); |
| 6870 | if (DVar.RefExpr) { |
| 6871 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6872 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6873 | } else if (DVar.CKind != OMPC_unknown) { |
| 6874 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6875 | << getOpenMPClauseName(DVar.CKind) |
| 6876 | << getOpenMPClauseName(OMPC_reduction); |
| 6877 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6878 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6879 | } |
| 6880 | |
| 6881 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 6882 | // A list item that appears in a reduction clause of a worksharing |
| 6883 | // construct must be shared in the parallel regions to which any of the |
| 6884 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6885 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6886 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6887 | !isOpenMPParallelDirective(CurrDir)) { |
| 6888 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 6889 | if (DVar.CKind != OMPC_shared) { |
| 6890 | Diag(ELoc, diag::err_omp_required_access) |
| 6891 | << getOpenMPClauseName(OMPC_reduction) |
| 6892 | << getOpenMPClauseName(OMPC_shared); |
| 6893 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6894 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6895 | } |
| 6896 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6897 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6898 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 6899 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 6900 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 6901 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6902 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 6903 | auto PrivateTy = Type; |
| 6904 | if (OASE) { |
| 6905 | // For array sections only: |
| 6906 | // Create pseudo array type for private copy. The size for this array will |
| 6907 | // be generated during codegen. |
| 6908 | // For array subscripts or single variables Private Ty is the same as Type |
| 6909 | // (type of the variable or single array element). |
| 6910 | PrivateTy = Context.getVariableArrayType( |
| 6911 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 6912 | Context.getSizeType(), VK_RValue), |
| 6913 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
| 6914 | } |
| 6915 | // Private copy. |
| 6916 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, VD->getName(), |
| 6917 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6918 | // Add initializer for private variable. |
| 6919 | Expr *Init = nullptr; |
| 6920 | switch (BOK) { |
| 6921 | case BO_Add: |
| 6922 | case BO_Xor: |
| 6923 | case BO_Or: |
| 6924 | case BO_LOr: |
| 6925 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 6926 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6927 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6928 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6929 | break; |
| 6930 | case BO_Mul: |
| 6931 | case BO_LAnd: |
| 6932 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6933 | // '*' and '&&' reduction ops - initializer is '1'. |
| 6934 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 6935 | } |
| 6936 | break; |
| 6937 | case BO_And: { |
| 6938 | // '&' reduction op - initializer is '~0'. |
| 6939 | QualType OrigType = Type; |
| 6940 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 6941 | Type = ComplexTy->getElementType(); |
| 6942 | } |
| 6943 | if (Type->isRealFloatingType()) { |
| 6944 | llvm::APFloat InitValue = |
| 6945 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 6946 | /*isIEEE=*/true); |
| 6947 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6948 | Type, ELoc); |
| 6949 | } else if (Type->isScalarType()) { |
| 6950 | auto Size = Context.getTypeSize(Type); |
| 6951 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 6952 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 6953 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6954 | } |
| 6955 | if (Init && OrigType->isAnyComplexType()) { |
| 6956 | // Init = 0xFFFF + 0xFFFFi; |
| 6957 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 6958 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 6959 | } |
| 6960 | Type = OrigType; |
| 6961 | break; |
| 6962 | } |
| 6963 | case BO_LT: |
| 6964 | case BO_GT: { |
| 6965 | // 'min' reduction op - initializer is 'Largest representable number in |
| 6966 | // the reduction list item type'. |
| 6967 | // 'max' reduction op - initializer is 'Least representable number in |
| 6968 | // the reduction list item type'. |
| 6969 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 6970 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 6971 | auto Size = Context.getTypeSize(Type); |
| 6972 | QualType IntTy = |
| 6973 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 6974 | llvm::APInt InitValue = |
| 6975 | (BOK != BO_LT) |
| 6976 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 6977 | : llvm::APInt::getMinValue(Size) |
| 6978 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 6979 | : llvm::APInt::getMaxValue(Size); |
| 6980 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6981 | if (Type->isPointerType()) { |
| 6982 | // Cast to pointer type. |
| 6983 | auto CastExpr = BuildCStyleCastExpr( |
| 6984 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 6985 | SourceLocation(), Init); |
| 6986 | if (CastExpr.isInvalid()) |
| 6987 | continue; |
| 6988 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6989 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6990 | } else if (Type->isRealFloatingType()) { |
| 6991 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 6992 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 6993 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6994 | Type, ELoc); |
| 6995 | } |
| 6996 | break; |
| 6997 | } |
| 6998 | case BO_PtrMemD: |
| 6999 | case BO_PtrMemI: |
| 7000 | case BO_MulAssign: |
| 7001 | case BO_Div: |
| 7002 | case BO_Rem: |
| 7003 | case BO_Sub: |
| 7004 | case BO_Shl: |
| 7005 | case BO_Shr: |
| 7006 | case BO_LE: |
| 7007 | case BO_GE: |
| 7008 | case BO_EQ: |
| 7009 | case BO_NE: |
| 7010 | case BO_AndAssign: |
| 7011 | case BO_XorAssign: |
| 7012 | case BO_OrAssign: |
| 7013 | case BO_Assign: |
| 7014 | case BO_AddAssign: |
| 7015 | case BO_SubAssign: |
| 7016 | case BO_DivAssign: |
| 7017 | case BO_RemAssign: |
| 7018 | case BO_ShlAssign: |
| 7019 | case BO_ShrAssign: |
| 7020 | case BO_Comma: |
| 7021 | llvm_unreachable("Unexpected reduction operation"); |
| 7022 | } |
| 7023 | if (Init) { |
| 7024 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 7025 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7026 | } else |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7027 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7028 | if (!RHSVD->hasInit()) { |
| 7029 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 7030 | << ReductionIdRange; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7031 | if (VD) { |
| 7032 | bool IsDecl = VD->isThisDeclarationADefinition(Context) == |
| 7033 | VarDecl::DeclarationOnly; |
| 7034 | Diag(VD->getLocation(), |
| 7035 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7036 | << VD; |
| 7037 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7038 | continue; |
| 7039 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7040 | // Store initializer for single element in private copy. Will be used during |
| 7041 | // codegen. |
| 7042 | PrivateVD->setInit(RHSVD->getInit()); |
| 7043 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7044 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 7045 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7046 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7047 | ExprResult ReductionOp = |
| 7048 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 7049 | LHSDRE, RHSDRE); |
| 7050 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 7051 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7052 | ReductionOp = |
| 7053 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7054 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 7055 | } else { |
| 7056 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 7057 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 7058 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 7059 | ReductionOp = |
| 7060 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 7061 | BO_Assign, LHSDRE, ConditionalOp); |
| 7062 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7063 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7064 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7065 | if (ReductionOp.isInvalid()) |
| 7066 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7067 | |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7068 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 7069 | Vars.push_back(RefExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7070 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 7071 | LHSs.push_back(LHSDRE); |
| 7072 | RHSs.push_back(RHSDRE); |
| 7073 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7074 | } |
| 7075 | |
| 7076 | if (Vars.empty()) |
| 7077 | return nullptr; |
| 7078 | |
| 7079 | return OMPReductionClause::Create( |
| 7080 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7081 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
| 7082 | LHSs, RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7083 | } |
| 7084 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7085 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 7086 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 7087 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 7088 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7089 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7090 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7091 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7092 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 7093 | LinKind == OMPC_LINEAR_unknown) { |
| 7094 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 7095 | LinKind = OMPC_LINEAR_val; |
| 7096 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7097 | for (auto &RefExpr : VarList) { |
| 7098 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 7099 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7100 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7101 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7102 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7103 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7104 | continue; |
| 7105 | } |
| 7106 | |
| 7107 | // OpenMP [2.14.3.7, linear clause] |
| 7108 | // A list item that appears in a linear clause is subject to the private |
| 7109 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 7110 | // noted. In addition, the value of the new list item on each iteration |
| 7111 | // of the associated loop(s) corresponds to the value of the original |
| 7112 | // list item before entering the construct plus the logical number of |
| 7113 | // the iteration times linear-step. |
| 7114 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7115 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7116 | // OpenMP [2.1, C/C++] |
| 7117 | // A list item is a variable name. |
| 7118 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 7119 | // A variable that is part of another variable (as an array or |
| 7120 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7121 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7122 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7123 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7124 | continue; |
| 7125 | } |
| 7126 | |
| 7127 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7128 | |
| 7129 | // OpenMP [2.14.3.7, linear clause] |
| 7130 | // A list-item cannot appear in more than one linear clause. |
| 7131 | // A list-item that appears in a linear clause cannot appear in any |
| 7132 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7133 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7134 | if (DVar.RefExpr) { |
| 7135 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7136 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 7137 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7138 | continue; |
| 7139 | } |
| 7140 | |
| 7141 | QualType QType = VD->getType(); |
| 7142 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 7143 | // It will be analyzed later. |
| 7144 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7145 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7146 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7147 | continue; |
| 7148 | } |
| 7149 | |
| 7150 | // A variable must not have an incomplete type or a reference type. |
| 7151 | if (RequireCompleteType(ELoc, QType, |
| 7152 | diag::err_omp_linear_incomplete_type)) { |
| 7153 | continue; |
| 7154 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 7155 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 7156 | !QType->isReferenceType()) { |
| 7157 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 7158 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 7159 | continue; |
| 7160 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7161 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7162 | |
| 7163 | // A list item must not be const-qualified. |
| 7164 | if (QType.isConstant(Context)) { |
| 7165 | Diag(ELoc, diag::err_omp_const_variable) |
| 7166 | << getOpenMPClauseName(OMPC_linear); |
| 7167 | bool IsDecl = |
| 7168 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7169 | Diag(VD->getLocation(), |
| 7170 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7171 | << VD; |
| 7172 | continue; |
| 7173 | } |
| 7174 | |
| 7175 | // A list item must be of integral or pointer type. |
| 7176 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 7177 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7178 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 7179 | !Ty->isPointerType())) { |
| 7180 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 7181 | bool IsDecl = |
| 7182 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7183 | Diag(VD->getLocation(), |
| 7184 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7185 | << VD; |
| 7186 | continue; |
| 7187 | } |
| 7188 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7189 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7190 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 7191 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7192 | auto *PrivateRef = buildDeclRefExpr( |
| 7193 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7194 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7195 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7196 | Expr *InitExpr; |
| 7197 | if (LinKind == OMPC_LINEAR_uval) |
| 7198 | InitExpr = VD->getInit(); |
| 7199 | else |
| 7200 | InitExpr = DE; |
| 7201 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7202 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7203 | auto InitRef = buildDeclRefExpr( |
| 7204 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7205 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 7206 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7207 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7208 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7209 | } |
| 7210 | |
| 7211 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7212 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7213 | |
| 7214 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7215 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7216 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 7217 | !Step->isInstantiationDependent() && |
| 7218 | !Step->containsUnexpandedParameterPack()) { |
| 7219 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7220 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7221 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7222 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7223 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7224 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7225 | // Build var to save the step value. |
| 7226 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7227 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7228 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7229 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7230 | ExprResult CalcStep = |
| 7231 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7232 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7233 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7234 | // Warn about zero linear step (it would be probably better specified as |
| 7235 | // making corresponding variables 'const'). |
| 7236 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7237 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 7238 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7239 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 7240 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7241 | if (!IsConstant && CalcStep.isUsable()) { |
| 7242 | // Calculate the step beforehand instead of doing this on each iteration. |
| 7243 | // (This is not used if the number of iterations may be kfold-ed). |
| 7244 | CalcStepExpr = CalcStep.get(); |
| 7245 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7246 | } |
| 7247 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 7248 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 7249 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 7250 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7251 | } |
| 7252 | |
| 7253 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 7254 | Expr *NumIterations, Sema &SemaRef, |
| 7255 | Scope *S) { |
| 7256 | // Walk the vars and build update/final expressions for the CodeGen. |
| 7257 | SmallVector<Expr *, 8> Updates; |
| 7258 | SmallVector<Expr *, 8> Finals; |
| 7259 | Expr *Step = Clause.getStep(); |
| 7260 | Expr *CalcStep = Clause.getCalcStep(); |
| 7261 | // OpenMP [2.14.3.7, linear clause] |
| 7262 | // If linear-step is not specified it is assumed to be 1. |
| 7263 | if (Step == nullptr) |
| 7264 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 7265 | else if (CalcStep) |
| 7266 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 7267 | bool HasErrors = false; |
| 7268 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7269 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7270 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7271 | for (auto &RefExpr : Clause.varlists()) { |
| 7272 | Expr *InitExpr = *CurInit; |
| 7273 | |
| 7274 | // Build privatized reference to the current linear var. |
| 7275 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 7276 | Expr *CapturedRef; |
| 7277 | if (LinKind == OMPC_LINEAR_uval) |
| 7278 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 7279 | else |
| 7280 | CapturedRef = |
| 7281 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 7282 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 7283 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7284 | |
| 7285 | // Build update: Var = InitExpr + IV * Step |
| 7286 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7287 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7288 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7289 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 7290 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7291 | |
| 7292 | // Build final: Var = InitExpr + NumIterations * Step |
| 7293 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7294 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7295 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7296 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 7297 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7298 | if (!Update.isUsable() || !Final.isUsable()) { |
| 7299 | Updates.push_back(nullptr); |
| 7300 | Finals.push_back(nullptr); |
| 7301 | HasErrors = true; |
| 7302 | } else { |
| 7303 | Updates.push_back(Update.get()); |
| 7304 | Finals.push_back(Final.get()); |
| 7305 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7306 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 7307 | } |
| 7308 | Clause.setUpdates(Updates); |
| 7309 | Clause.setFinals(Finals); |
| 7310 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7311 | } |
| 7312 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7313 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 7314 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 7315 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 7316 | |
| 7317 | SmallVector<Expr *, 8> Vars; |
| 7318 | for (auto &RefExpr : VarList) { |
| 7319 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 7320 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7321 | // It will be analyzed later. |
| 7322 | Vars.push_back(RefExpr); |
| 7323 | continue; |
| 7324 | } |
| 7325 | |
| 7326 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7327 | // OpenMP [2.1, C/C++] |
| 7328 | // A list item is a variable name. |
| 7329 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7330 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7331 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7332 | continue; |
| 7333 | } |
| 7334 | |
| 7335 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 7336 | |
| 7337 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7338 | // The type of list items appearing in the aligned clause must be |
| 7339 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7340 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7341 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7342 | const Type *Ty = QType.getTypePtrOrNull(); |
| 7343 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 7344 | !Ty->isPointerType())) { |
| 7345 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 7346 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 7347 | bool IsDecl = |
| 7348 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7349 | Diag(VD->getLocation(), |
| 7350 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7351 | << VD; |
| 7352 | continue; |
| 7353 | } |
| 7354 | |
| 7355 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 7356 | // A list-item cannot appear in more than one aligned clause. |
| 7357 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 7358 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 7359 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 7360 | << getOpenMPClauseName(OMPC_aligned); |
| 7361 | continue; |
| 7362 | } |
| 7363 | |
| 7364 | Vars.push_back(DE); |
| 7365 | } |
| 7366 | |
| 7367 | // OpenMP [2.8.1, simd construct, Description] |
| 7368 | // The parameter of the aligned clause, alignment, must be a constant |
| 7369 | // positive integer expression. |
| 7370 | // If no optional parameter is specified, implementation-defined default |
| 7371 | // alignments for SIMD instructions on the target platforms are assumed. |
| 7372 | if (Alignment != nullptr) { |
| 7373 | ExprResult AlignResult = |
| 7374 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 7375 | if (AlignResult.isInvalid()) |
| 7376 | return nullptr; |
| 7377 | Alignment = AlignResult.get(); |
| 7378 | } |
| 7379 | if (Vars.empty()) |
| 7380 | return nullptr; |
| 7381 | |
| 7382 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 7383 | EndLoc, Vars, Alignment); |
| 7384 | } |
| 7385 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7386 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 7387 | SourceLocation StartLoc, |
| 7388 | SourceLocation LParenLoc, |
| 7389 | SourceLocation EndLoc) { |
| 7390 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7391 | SmallVector<Expr *, 8> SrcExprs; |
| 7392 | SmallVector<Expr *, 8> DstExprs; |
| 7393 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7394 | for (auto &RefExpr : VarList) { |
| 7395 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 7396 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7397 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7398 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7399 | SrcExprs.push_back(nullptr); |
| 7400 | DstExprs.push_back(nullptr); |
| 7401 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7402 | continue; |
| 7403 | } |
| 7404 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7405 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7406 | // OpenMP [2.1, C/C++] |
| 7407 | // A list item is a variable name. |
| 7408 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7409 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7410 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7411 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7412 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7413 | continue; |
| 7414 | } |
| 7415 | |
| 7416 | Decl *D = DE->getDecl(); |
| 7417 | VarDecl *VD = cast<VarDecl>(D); |
| 7418 | |
| 7419 | QualType Type = VD->getType(); |
| 7420 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7421 | // It will be analyzed later. |
| 7422 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7423 | SrcExprs.push_back(nullptr); |
| 7424 | DstExprs.push_back(nullptr); |
| 7425 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7426 | continue; |
| 7427 | } |
| 7428 | |
| 7429 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 7430 | // A list item that appears in a copyin clause must be threadprivate. |
| 7431 | if (!DSAStack->isThreadPrivate(VD)) { |
| 7432 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7433 | << getOpenMPClauseName(OMPC_copyin) |
| 7434 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7435 | continue; |
| 7436 | } |
| 7437 | |
| 7438 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7439 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7440 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7441 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7442 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7443 | auto *SrcVD = |
| 7444 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 7445 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7446 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7447 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 7448 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7449 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 7450 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7451 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7452 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7453 | // For arrays generate assignment operation for single element and replace |
| 7454 | // it by the original array element in CodeGen. |
| 7455 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7456 | PseudoDstExpr, PseudoSrcExpr); |
| 7457 | if (AssignmentOp.isInvalid()) |
| 7458 | continue; |
| 7459 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7460 | /*DiscardedValue=*/true); |
| 7461 | if (AssignmentOp.isInvalid()) |
| 7462 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7463 | |
| 7464 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 7465 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7466 | SrcExprs.push_back(PseudoSrcExpr); |
| 7467 | DstExprs.push_back(PseudoDstExpr); |
| 7468 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7469 | } |
| 7470 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7471 | if (Vars.empty()) |
| 7472 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7473 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7474 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7475 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7476 | } |
| 7477 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7478 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7479 | SourceLocation StartLoc, |
| 7480 | SourceLocation LParenLoc, |
| 7481 | SourceLocation EndLoc) { |
| 7482 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7483 | SmallVector<Expr *, 8> SrcExprs; |
| 7484 | SmallVector<Expr *, 8> DstExprs; |
| 7485 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7486 | for (auto &RefExpr : VarList) { |
| 7487 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7488 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7489 | // It will be analyzed later. |
| 7490 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7491 | SrcExprs.push_back(nullptr); |
| 7492 | DstExprs.push_back(nullptr); |
| 7493 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7494 | continue; |
| 7495 | } |
| 7496 | |
| 7497 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7498 | // OpenMP [2.1, C/C++] |
| 7499 | // A list item is a variable name. |
| 7500 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7501 | // A list item that appears in a copyin clause must be threadprivate. |
| 7502 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7503 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7504 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7505 | continue; |
| 7506 | } |
| 7507 | |
| 7508 | Decl *D = DE->getDecl(); |
| 7509 | VarDecl *VD = cast<VarDecl>(D); |
| 7510 | |
| 7511 | QualType Type = VD->getType(); |
| 7512 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7513 | // It will be analyzed later. |
| 7514 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7515 | SrcExprs.push_back(nullptr); |
| 7516 | DstExprs.push_back(nullptr); |
| 7517 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7518 | continue; |
| 7519 | } |
| 7520 | |
| 7521 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 7522 | // A list item that appears in a copyprivate clause may not appear in a |
| 7523 | // private or firstprivate clause on the single construct. |
| 7524 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7525 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7526 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 7527 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7528 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7529 | << getOpenMPClauseName(DVar.CKind) |
| 7530 | << getOpenMPClauseName(OMPC_copyprivate); |
| 7531 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7532 | continue; |
| 7533 | } |
| 7534 | |
| 7535 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 7536 | // All list items that appear in a copyprivate clause must be either |
| 7537 | // threadprivate or private in the enclosing context. |
| 7538 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7539 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7540 | if (DVar.CKind == OMPC_shared) { |
| 7541 | Diag(ELoc, diag::err_omp_required_access) |
| 7542 | << getOpenMPClauseName(OMPC_copyprivate) |
| 7543 | << "threadprivate or private in the enclosing context"; |
| 7544 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7545 | continue; |
| 7546 | } |
| 7547 | } |
| 7548 | } |
| 7549 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7550 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7551 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7552 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7553 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 7554 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7555 | bool IsDecl = |
| 7556 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7557 | Diag(VD->getLocation(), |
| 7558 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7559 | << VD; |
| 7560 | continue; |
| 7561 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7562 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7563 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7564 | // A variable of class type (or array thereof) that appears in a |
| 7565 | // copyin clause requires an accessible, unambiguous copy assignment |
| 7566 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7567 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 7568 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7569 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7570 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 7571 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7572 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7573 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7574 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7575 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 7576 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7577 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7578 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7579 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7580 | PseudoDstExpr, PseudoSrcExpr); |
| 7581 | if (AssignmentOp.isInvalid()) |
| 7582 | continue; |
| 7583 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7584 | /*DiscardedValue=*/true); |
| 7585 | if (AssignmentOp.isInvalid()) |
| 7586 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7587 | |
| 7588 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 7589 | // implicitly private. |
| 7590 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7591 | SrcExprs.push_back(PseudoSrcExpr); |
| 7592 | DstExprs.push_back(PseudoDstExpr); |
| 7593 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7594 | } |
| 7595 | |
| 7596 | if (Vars.empty()) |
| 7597 | return nullptr; |
| 7598 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7599 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 7600 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7601 | } |
| 7602 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7603 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 7604 | SourceLocation StartLoc, |
| 7605 | SourceLocation LParenLoc, |
| 7606 | SourceLocation EndLoc) { |
| 7607 | if (VarList.empty()) |
| 7608 | return nullptr; |
| 7609 | |
| 7610 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 7611 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7612 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7613 | OMPClause * |
| 7614 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 7615 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 7616 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 7617 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7618 | if (DepKind == OMPC_DEPEND_unknown) { |
| 7619 | std::string Values; |
| 7620 | std::string Sep(", "); |
| 7621 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 7622 | Values += "'"; |
| 7623 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 7624 | Values += "'"; |
| 7625 | switch (i) { |
| 7626 | case OMPC_DEPEND_unknown - 2: |
| 7627 | Values += " or "; |
| 7628 | break; |
| 7629 | case OMPC_DEPEND_unknown - 1: |
| 7630 | break; |
| 7631 | default: |
| 7632 | Values += Sep; |
| 7633 | break; |
| 7634 | } |
| 7635 | } |
| 7636 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 7637 | << Values << getOpenMPClauseName(OMPC_depend); |
| 7638 | return nullptr; |
| 7639 | } |
| 7640 | SmallVector<Expr *, 8> Vars; |
| 7641 | for (auto &RefExpr : VarList) { |
| 7642 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7643 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7644 | // It will be analyzed later. |
| 7645 | Vars.push_back(RefExpr); |
| 7646 | continue; |
| 7647 | } |
| 7648 | |
| 7649 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7650 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 7651 | // A variable that is part of another variable (such as a field of a |
| 7652 | // structure) but is not an array element or an array section cannot appear |
| 7653 | // in a depend clause. |
| 7654 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7655 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7656 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7657 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7658 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 7659 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7660 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7661 | !ASE->getBase()->getType()->isArrayType())) { |
| 7662 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7663 | << RefExpr->getSourceRange(); |
| 7664 | continue; |
| 7665 | } |
| 7666 | |
| 7667 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 7668 | } |
| 7669 | |
| 7670 | if (Vars.empty()) |
| 7671 | return nullptr; |
| 7672 | |
| 7673 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 7674 | DepLoc, ColonLoc, Vars); |
| 7675 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7676 | |
| 7677 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 7678 | SourceLocation LParenLoc, |
| 7679 | SourceLocation EndLoc) { |
| 7680 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7681 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7682 | // OpenMP [2.9.1, Restrictions] |
| 7683 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7684 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 7685 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7686 | return nullptr; |
| 7687 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7688 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7689 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7690 | |
| 7691 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 7692 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 7693 | if (!RD || RD->isInvalidDecl()) |
| 7694 | return true; |
| 7695 | |
| 7696 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 7697 | if (RD->isDynamicClass()) { |
| 7698 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7699 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 7700 | return false; |
| 7701 | } |
| 7702 | auto *DC = RD; |
| 7703 | bool IsCorrect = true; |
| 7704 | for (auto *I : DC->decls()) { |
| 7705 | if (I) { |
| 7706 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 7707 | if (MD->isStatic()) { |
| 7708 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7709 | SemaRef.Diag(MD->getLocation(), |
| 7710 | diag::note_omp_static_member_in_target); |
| 7711 | IsCorrect = false; |
| 7712 | } |
| 7713 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 7714 | if (VD->isStaticDataMember()) { |
| 7715 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 7716 | SemaRef.Diag(VD->getLocation(), |
| 7717 | diag::note_omp_static_member_in_target); |
| 7718 | IsCorrect = false; |
| 7719 | } |
| 7720 | } |
| 7721 | } |
| 7722 | } |
| 7723 | |
| 7724 | for (auto &I : RD->bases()) { |
| 7725 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 7726 | I.getType()->getAsCXXRecordDecl())) |
| 7727 | IsCorrect = false; |
| 7728 | } |
| 7729 | return IsCorrect; |
| 7730 | } |
| 7731 | |
| 7732 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 7733 | DSAStackTy *Stack, QualType QTy) { |
| 7734 | NamedDecl *ND; |
| 7735 | if (QTy->isIncompleteType(&ND)) { |
| 7736 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 7737 | return false; |
| 7738 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 7739 | if (!RD->isInvalidDecl() && |
| 7740 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 7741 | return false; |
| 7742 | } |
| 7743 | return true; |
| 7744 | } |
| 7745 | |
| 7746 | OMPClause *Sema::ActOnOpenMPMapClause( |
| 7747 | OpenMPMapClauseKind MapTypeModifier, OpenMPMapClauseKind MapType, |
| 7748 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 7749 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7750 | SmallVector<Expr *, 4> Vars; |
| 7751 | |
| 7752 | for (auto &RE : VarList) { |
| 7753 | assert(RE && "Null expr in omp map"); |
| 7754 | if (isa<DependentScopeDeclRefExpr>(RE)) { |
| 7755 | // It will be analyzed later. |
| 7756 | Vars.push_back(RE); |
| 7757 | continue; |
| 7758 | } |
| 7759 | SourceLocation ELoc = RE->getExprLoc(); |
| 7760 | |
| 7761 | // OpenMP [2.14.5, Restrictions] |
| 7762 | // A variable that is part of another variable (such as field of a |
| 7763 | // structure) but is not an array element or an array section cannot appear |
| 7764 | // in a map clause. |
| 7765 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 7766 | |
| 7767 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 7768 | VE->isInstantiationDependent() || |
| 7769 | VE->containsUnexpandedParameterPack()) { |
| 7770 | // It will be analyzed later. |
| 7771 | Vars.push_back(RE); |
| 7772 | continue; |
| 7773 | } |
| 7774 | |
| 7775 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
| 7776 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7777 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7778 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7779 | |
| 7780 | if (!RE->IgnoreParenImpCasts()->isLValue() || |
| 7781 | (!OASE && !ASE && !DE) || |
| 7782 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 7783 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7784 | !ASE->getBase()->getType()->isArrayType())) { |
| 7785 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7786 | << RE->getSourceRange(); |
| 7787 | continue; |
| 7788 | } |
| 7789 | |
| 7790 | Decl *D = nullptr; |
| 7791 | if (DE) { |
| 7792 | D = DE->getDecl(); |
| 7793 | } else if (ASE) { |
| 7794 | auto *B = ASE->getBase()->IgnoreParenCasts(); |
| 7795 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 7796 | } else if (OASE) { |
| 7797 | auto *B = OASE->getBase(); |
| 7798 | D = dyn_cast<DeclRefExpr>(B)->getDecl(); |
| 7799 | } |
| 7800 | assert(D && "Null decl on map clause."); |
| 7801 | auto *VD = cast<VarDecl>(D); |
| 7802 | |
| 7803 | // OpenMP [2.14.5, Restrictions, p.8] |
| 7804 | // threadprivate variables cannot appear in a map clause. |
| 7805 | if (DSAStack->isThreadPrivate(VD)) { |
| 7806 | auto DVar = DSAStack->getTopDSA(VD, false); |
| 7807 | Diag(ELoc, diag::err_omp_threadprivate_in_map); |
| 7808 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7809 | continue; |
| 7810 | } |
| 7811 | |
| 7812 | // OpenMP [2.14.5, Restrictions, p.2] |
| 7813 | // At most one list item can be an array item derived from a given variable |
| 7814 | // in map clauses of the same construct. |
| 7815 | // OpenMP [2.14.5, Restrictions, p.3] |
| 7816 | // List items of map clauses in the same construct must not share original |
| 7817 | // storage. |
| 7818 | // OpenMP [2.14.5, Restrictions, C/C++, p.2] |
| 7819 | // A variable for which the type is pointer, reference to array, or |
| 7820 | // reference to pointer and an array section derived from that variable |
| 7821 | // must not appear as list items of map clauses of the same construct. |
| 7822 | DSAStackTy::MapInfo MI = DSAStack->IsMappedInCurrentRegion(VD); |
| 7823 | if (MI.RefExpr) { |
| 7824 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 7825 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 7826 | << MI.RefExpr->getSourceRange(); |
| 7827 | continue; |
| 7828 | } |
| 7829 | |
| 7830 | // OpenMP [2.14.5, Restrictions, C/C++, p.3,4] |
| 7831 | // A variable for which the type is pointer, reference to array, or |
| 7832 | // reference to pointer must not appear as a list item if the enclosing |
| 7833 | // device data environment already contains an array section derived from |
| 7834 | // that variable. |
| 7835 | // An array section derived from a variable for which the type is pointer, |
| 7836 | // reference to array, or reference to pointer must not appear as a list |
| 7837 | // item if the enclosing device data environment already contains that |
| 7838 | // variable. |
| 7839 | QualType Type = VD->getType(); |
| 7840 | MI = DSAStack->getMapInfoForVar(VD); |
| 7841 | if (MI.RefExpr && (isa<DeclRefExpr>(MI.RefExpr->IgnoreParenLValueCasts()) != |
| 7842 | isa<DeclRefExpr>(VE)) && |
| 7843 | (Type->isPointerType() || Type->isReferenceType())) { |
| 7844 | Diag(ELoc, diag::err_omp_map_shared_storage) << ELoc; |
| 7845 | Diag(MI.RefExpr->getExprLoc(), diag::note_used_here) |
| 7846 | << MI.RefExpr->getSourceRange(); |
| 7847 | continue; |
| 7848 | } |
| 7849 | |
| 7850 | // OpenMP [2.14.5, Restrictions, C/C++, p.7] |
| 7851 | // A list item must have a mappable type. |
| 7852 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), *this, |
| 7853 | DSAStack, Type)) |
| 7854 | continue; |
| 7855 | |
| 7856 | Vars.push_back(RE); |
| 7857 | MI.RefExpr = RE; |
| 7858 | DSAStack->addMapInfoForVar(VD, MI); |
| 7859 | } |
| 7860 | if (Vars.empty()) |
| 7861 | return nullptr; |
| 7862 | |
| 7863 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7864 | MapTypeModifier, MapType, MapLoc); |
| 7865 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7866 | |
| 7867 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 7868 | SourceLocation StartLoc, |
| 7869 | SourceLocation LParenLoc, |
| 7870 | SourceLocation EndLoc) { |
| 7871 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7872 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7873 | // OpenMP [teams Constrcut, Restrictions] |
| 7874 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7875 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 7876 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7877 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7878 | |
| 7879 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7880 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7881 | |
| 7882 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 7883 | SourceLocation StartLoc, |
| 7884 | SourceLocation LParenLoc, |
| 7885 | SourceLocation EndLoc) { |
| 7886 | Expr *ValExpr = ThreadLimit; |
| 7887 | |
| 7888 | // OpenMP [teams Constrcut, Restrictions] |
| 7889 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7890 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 7891 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7892 | return nullptr; |
| 7893 | |
| 7894 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 7895 | EndLoc); |
| 7896 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7897 | |
| 7898 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 7899 | SourceLocation StartLoc, |
| 7900 | SourceLocation LParenLoc, |
| 7901 | SourceLocation EndLoc) { |
| 7902 | Expr *ValExpr = Priority; |
| 7903 | |
| 7904 | // OpenMP [2.9.1, task Constrcut] |
| 7905 | // The priority-value is a non-negative numerical scalar expression. |
| 7906 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 7907 | /*StrictlyPositive=*/false)) |
| 7908 | return nullptr; |
| 7909 | |
| 7910 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7911 | } |