Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 15 | #include "TreeTransform.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 19 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtCXX.h" |
| 22 | #include "clang/AST/StmtOpenMP.h" |
| 23 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 24 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 27 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 28 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Scope.h" |
| 30 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 31 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | using namespace clang; |
| 33 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 34 | //===----------------------------------------------------------------------===// |
| 35 | // Stack of data-sharing attributes for variables |
| 36 | //===----------------------------------------------------------------------===// |
| 37 | |
| 38 | namespace { |
| 39 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 40 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 41 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 42 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 43 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 44 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 45 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 46 | template <class T> struct MatchesAny { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 47 | explicit MatchesAny(ArrayRef<T> Arr) : Arr(std::move(Arr)) {} |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 48 | bool operator()(T Kind) { |
| 49 | for (auto KindEl : Arr) |
| 50 | if (KindEl == Kind) |
| 51 | return true; |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | ArrayRef<T> Arr; |
| 57 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 58 | struct MatchesAlways { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 59 | MatchesAlways() {} |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 60 | template <class T> bool operator()(T) { return true; } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | typedef MatchesAny<OpenMPClauseKind> MatchesAnyClause; |
| 64 | typedef MatchesAny<OpenMPDirectiveKind> MatchesAnyDirective; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 65 | |
| 66 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 67 | /// clauses and their data-sharing attributes. |
| 68 | class DSAStackTy { |
| 69 | public: |
| 70 | struct DSAVarData { |
| 71 | OpenMPDirectiveKind DKind; |
| 72 | OpenMPClauseKind CKind; |
| 73 | DeclRefExpr *RefExpr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 74 | SourceLocation ImplicitDSALoc; |
| 75 | DSAVarData() |
| 76 | : DKind(OMPD_unknown), CKind(OMPC_unknown), RefExpr(nullptr), |
| 77 | ImplicitDSALoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 78 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 79 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 80 | private: |
| 81 | struct DSAInfo { |
| 82 | OpenMPClauseKind Attributes; |
| 83 | DeclRefExpr *RefExpr; |
| 84 | }; |
| 85 | typedef llvm::SmallDenseMap<VarDecl *, DSAInfo, 64> DeclSAMapTy; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 86 | typedef llvm::SmallDenseMap<VarDecl *, DeclRefExpr *, 64> AlignedMapTy; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 87 | typedef llvm::DenseSet<VarDecl *> LoopControlVariablesSetTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 88 | |
| 89 | struct SharingMapTy { |
| 90 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 91 | AlignedMapTy AlignedMap; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 92 | LoopControlVariablesSetTy LCVSet; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 93 | DefaultDataSharingAttributes DefaultAttr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 94 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 95 | OpenMPDirectiveKind Directive; |
| 96 | DeclarationNameInfo DirectiveName; |
| 97 | Scope *CurScope; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 98 | SourceLocation ConstructLoc; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 99 | bool OrderedRegion; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 100 | bool NowaitRegion; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 101 | unsigned CollapseNumber; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 102 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 103 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 104 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 105 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 106 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 107 | ConstructLoc(Loc), OrderedRegion(false), NowaitRegion(false), |
| 108 | CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 109 | SharingMapTy() |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 110 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 111 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 112 | ConstructLoc(), OrderedRegion(false), NowaitRegion(false), |
| 113 | CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 117 | |
| 118 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 119 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 120 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 121 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 122 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 123 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 124 | bool ForceCapturing; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 125 | |
| 126 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 127 | |
| 128 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 129 | |
| 130 | /// \brief Checks if the variable is a local for OpenMP region. |
| 131 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 132 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 133 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 134 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 135 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 136 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 137 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 138 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 139 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 140 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 141 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 142 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 143 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 144 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 145 | Scope *CurScope, SourceLocation Loc) { |
| 146 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 147 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | void pop() { |
| 151 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 152 | Stack.pop_back(); |
| 153 | } |
| 154 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 155 | /// \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] | 156 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 157 | /// for diagnostics. |
| 158 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 159 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 160 | /// \brief Register specified variable as loop control variable. |
| 161 | void addLoopControlVariable(VarDecl *D); |
| 162 | /// \brief Check if the specified variable is a loop control variable for |
| 163 | /// current region. |
| 164 | bool isLoopControlVariable(VarDecl *D); |
| 165 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 166 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 167 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 168 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 169 | /// \brief Returns data sharing attributes from top of the stack for the |
| 170 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 171 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 172 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 173 | DSAVarData getImplicitDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 174 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 175 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 176 | /// predicate. |
| 177 | template <class ClausesPredicate, class DirectivesPredicate> |
| 178 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 179 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 180 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 181 | /// match specified \a CPred predicate in any innermost directive which |
| 182 | /// matches \a DPred predicate. |
| 183 | template <class ClausesPredicate, class DirectivesPredicate> |
| 184 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 185 | DirectivesPredicate DPred, |
| 186 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 187 | /// \brief Checks if the specified variables has explicit data-sharing |
| 188 | /// attributes which match specified \a CPred predicate at the specified |
| 189 | /// OpenMP region. |
| 190 | bool hasExplicitDSA(VarDecl *D, |
| 191 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 192 | unsigned Level); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 193 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 194 | template <class NamedDirectivesPredicate> |
| 195 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 196 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 197 | /// \brief Returns currently analyzed directive. |
| 198 | OpenMPDirectiveKind getCurrentDirective() const { |
| 199 | return Stack.back().Directive; |
| 200 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 201 | /// \brief Returns parent directive. |
| 202 | OpenMPDirectiveKind getParentDirective() const { |
| 203 | if (Stack.size() > 2) |
| 204 | return Stack[Stack.size() - 2].Directive; |
| 205 | return OMPD_unknown; |
| 206 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 207 | |
| 208 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 209 | void setDefaultDSANone(SourceLocation Loc) { |
| 210 | Stack.back().DefaultAttr = DSA_none; |
| 211 | Stack.back().DefaultAttrLoc = Loc; |
| 212 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 213 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 214 | void setDefaultDSAShared(SourceLocation Loc) { |
| 215 | Stack.back().DefaultAttr = DSA_shared; |
| 216 | Stack.back().DefaultAttrLoc = Loc; |
| 217 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 218 | |
| 219 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 220 | return Stack.back().DefaultAttr; |
| 221 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 222 | SourceLocation getDefaultDSALocation() const { |
| 223 | return Stack.back().DefaultAttrLoc; |
| 224 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 225 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 226 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 227 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 228 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 229 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 232 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
| 233 | void setOrderedRegion(bool IsOrdered = true) { |
| 234 | Stack.back().OrderedRegion = IsOrdered; |
| 235 | } |
| 236 | /// \brief Returns true, if parent region is ordered (has associated |
| 237 | /// 'ordered' clause), false - otherwise. |
| 238 | bool isParentOrderedRegion() const { |
| 239 | if (Stack.size() > 2) |
| 240 | return Stack[Stack.size() - 2].OrderedRegion; |
| 241 | return false; |
| 242 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 243 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 244 | void setNowaitRegion(bool IsNowait = true) { |
| 245 | Stack.back().NowaitRegion = IsNowait; |
| 246 | } |
| 247 | /// \brief Returns true, if parent region is nowait (has associated |
| 248 | /// 'nowait' clause), false - otherwise. |
| 249 | bool isParentNowaitRegion() const { |
| 250 | if (Stack.size() > 2) |
| 251 | return Stack[Stack.size() - 2].NowaitRegion; |
| 252 | return false; |
| 253 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 254 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 255 | /// \brief Set collapse value for the region. |
| 256 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 257 | /// \brief Return collapse value for region. |
| 258 | unsigned getCollapseNumber() const { |
| 259 | return Stack.back().CollapseNumber; |
| 260 | } |
| 261 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 262 | /// \brief Marks current target region as one with closely nested teams |
| 263 | /// region. |
| 264 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 265 | if (Stack.size() > 2) |
| 266 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 267 | } |
| 268 | /// \brief Returns true, if current region has closely nested teams region. |
| 269 | bool hasInnerTeamsRegion() const { |
| 270 | return getInnerTeamsRegionLoc().isValid(); |
| 271 | } |
| 272 | /// \brief Returns location of the nested teams region (if any). |
| 273 | SourceLocation getInnerTeamsRegionLoc() const { |
| 274 | if (Stack.size() > 1) |
| 275 | return Stack.back().InnerTeamsRegionLoc; |
| 276 | return SourceLocation(); |
| 277 | } |
| 278 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 279 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 280 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 281 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 282 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 283 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 284 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 285 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 286 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 287 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 288 | |
| 289 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 290 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 291 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 292 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 293 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 294 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 295 | // in a region but not in construct] |
| 296 | // File-scope or namespace-scope variables referenced in called routines |
| 297 | // in the region are shared unless they appear in a threadprivate |
| 298 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 299 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 300 | DVar.CKind = OMPC_shared; |
| 301 | |
| 302 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 303 | // in a region but not in construct] |
| 304 | // Variables with static storage duration that are declared in called |
| 305 | // routines in the region are shared. |
| 306 | if (D->hasGlobalStorage()) |
| 307 | DVar.CKind = OMPC_shared; |
| 308 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 309 | return DVar; |
| 310 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 311 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 312 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 313 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 314 | // in a Construct, C/C++, predetermined, p.1] |
| 315 | // Variables with automatic storage duration that are declared in a scope |
| 316 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 317 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 318 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 319 | DVar.CKind = OMPC_private; |
| 320 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 323 | // Explicitly specified attributes and local variables with predetermined |
| 324 | // attributes. |
| 325 | if (Iter->SharingMap.count(D)) { |
| 326 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 327 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 328 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 329 | return DVar; |
| 330 | } |
| 331 | |
| 332 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 333 | // in a Construct, C/C++, implicitly determined, p.1] |
| 334 | // In a parallel or task construct, the data-sharing attributes of these |
| 335 | // variables are determined by the default clause, if present. |
| 336 | switch (Iter->DefaultAttr) { |
| 337 | case DSA_shared: |
| 338 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 339 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 340 | return DVar; |
| 341 | case DSA_none: |
| 342 | return DVar; |
| 343 | case DSA_unspecified: |
| 344 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 345 | // in a Construct, implicitly determined, p.2] |
| 346 | // In a parallel construct, if no default clause is present, these |
| 347 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 348 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 349 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 350 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 351 | DVar.CKind = OMPC_shared; |
| 352 | return DVar; |
| 353 | } |
| 354 | |
| 355 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 356 | // in a Construct, implicitly determined, p.4] |
| 357 | // In a task construct, if no default clause is present, a variable that in |
| 358 | // the enclosing context is determined to be shared by all implicit tasks |
| 359 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 360 | if (DVar.DKind == OMPD_task) { |
| 361 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 362 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 363 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 364 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 365 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 366 | // in a Construct, implicitly determined, p.6] |
| 367 | // In a task construct, if no default clause is present, a variable |
| 368 | // whose data-sharing attribute is not determined by the rules above is |
| 369 | // firstprivate. |
| 370 | DVarTemp = getDSA(I, D); |
| 371 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 372 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 373 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 374 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 375 | return DVar; |
| 376 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 377 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 378 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 379 | } |
| 380 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 381 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 382 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 383 | return DVar; |
| 384 | } |
| 385 | } |
| 386 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 387 | // in a Construct, implicitly determined, p.3] |
| 388 | // For constructs other than task, if no default clause is present, these |
| 389 | // variables inherit their data-sharing attributes from the enclosing |
| 390 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 391 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 394 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 395 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 396 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 397 | auto It = Stack.back().AlignedMap.find(D); |
| 398 | if (It == Stack.back().AlignedMap.end()) { |
| 399 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 400 | Stack.back().AlignedMap[D] = NewDE; |
| 401 | return nullptr; |
| 402 | } else { |
| 403 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 404 | return It->second; |
| 405 | } |
| 406 | return nullptr; |
| 407 | } |
| 408 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 409 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 410 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 411 | D = D->getCanonicalDecl(); |
| 412 | Stack.back().LCVSet.insert(D); |
| 413 | } |
| 414 | |
| 415 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 416 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 417 | D = D->getCanonicalDecl(); |
| 418 | return Stack.back().LCVSet.count(D) > 0; |
| 419 | } |
| 420 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 421 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 422 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 423 | if (A == OMPC_threadprivate) { |
| 424 | Stack[0].SharingMap[D].Attributes = A; |
| 425 | Stack[0].SharingMap[D].RefExpr = E; |
| 426 | } else { |
| 427 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 428 | Stack.back().SharingMap[D].Attributes = A; |
| 429 | Stack.back().SharingMap[D].RefExpr = E; |
| 430 | } |
| 431 | } |
| 432 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 433 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 434 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 435 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 436 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 437 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 438 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 439 | ++I; |
| 440 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 441 | if (I == E) |
| 442 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 443 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 444 | Scope *CurScope = getCurScope(); |
| 445 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 446 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 447 | } |
| 448 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 449 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 450 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 453 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 454 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
| 455 | StringRef Name) { |
| 456 | DeclContext *DC = SemaRef.CurContext; |
| 457 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 458 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 459 | VarDecl *Decl = |
| 460 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
| 461 | Decl->setImplicit(); |
| 462 | return Decl; |
| 463 | } |
| 464 | |
| 465 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 466 | SourceLocation Loc, |
| 467 | bool RefersToCapture = false) { |
| 468 | D->setReferenced(); |
| 469 | D->markUsed(S.Context); |
| 470 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 471 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 472 | VK_LValue); |
| 473 | } |
| 474 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 475 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 476 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 477 | DSAVarData DVar; |
| 478 | |
| 479 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 480 | // in a Construct, C/C++, predetermined, p.1] |
| 481 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 482 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 483 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 484 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 485 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 486 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 487 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 488 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 489 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 490 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 491 | } |
| 492 | if (Stack[0].SharingMap.count(D)) { |
| 493 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 494 | DVar.CKind = OMPC_threadprivate; |
| 495 | return DVar; |
| 496 | } |
| 497 | |
| 498 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 499 | // in a Construct, C/C++, predetermined, p.1] |
| 500 | // Variables with automatic storage duration that are declared in a scope |
| 501 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 502 | OpenMPDirectiveKind Kind = |
| 503 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 504 | auto StartI = std::next(Stack.rbegin()); |
| 505 | auto EndI = std::prev(Stack.rend()); |
| 506 | if (FromParent && StartI != EndI) { |
| 507 | StartI = std::next(StartI); |
| 508 | } |
| 509 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 510 | if (isOpenMPLocal(D, StartI) && |
| 511 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 512 | D->getStorageClass() == SC_None)) || |
| 513 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 514 | DVar.CKind = OMPC_private; |
| 515 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 516 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 517 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 518 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 519 | // in a Construct, C/C++, predetermined, p.4] |
| 520 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 521 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 522 | // in a Construct, C/C++, predetermined, p.7] |
| 523 | // Variables with static storage duration that are declared in a scope |
| 524 | // inside the construct are shared. |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 525 | if (D->isStaticDataMember() || D->isStaticLocal()) { |
| 526 | DSAVarData DVarTemp = |
| 527 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 528 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 529 | return DVar; |
| 530 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 531 | DVar.CKind = OMPC_shared; |
| 532 | return DVar; |
| 533 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 537 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 538 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 539 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 540 | // in a Construct, C/C++, predetermined, p.6] |
| 541 | // Variables with const qualified type having no mutable member are |
| 542 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 543 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 544 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 545 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 546 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 547 | // Variables with const-qualified type having no mutable member may be |
| 548 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 549 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 550 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 551 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 552 | return DVar; |
| 553 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 554 | DVar.CKind = OMPC_shared; |
| 555 | return DVar; |
| 556 | } |
| 557 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 558 | // Explicitly specified attributes and local variables with predetermined |
| 559 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 560 | auto I = std::prev(StartI); |
| 561 | if (I->SharingMap.count(D)) { |
| 562 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 563 | DVar.CKind = I->SharingMap[D].Attributes; |
| 564 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | return DVar; |
| 568 | } |
| 569 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 570 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 571 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 572 | auto StartI = Stack.rbegin(); |
| 573 | auto EndI = std::prev(Stack.rend()); |
| 574 | if (FromParent && StartI != EndI) { |
| 575 | StartI = std::next(StartI); |
| 576 | } |
| 577 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 578 | } |
| 579 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 580 | template <class ClausesPredicate, class DirectivesPredicate> |
| 581 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 582 | DirectivesPredicate DPred, |
| 583 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 584 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 585 | auto StartI = std::next(Stack.rbegin()); |
| 586 | auto EndI = std::prev(Stack.rend()); |
| 587 | if (FromParent && StartI != EndI) { |
| 588 | StartI = std::next(StartI); |
| 589 | } |
| 590 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 591 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 592 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 593 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 594 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 595 | return DVar; |
| 596 | } |
| 597 | return DSAVarData(); |
| 598 | } |
| 599 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 600 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 601 | DSAStackTy::DSAVarData |
| 602 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 603 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 604 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 605 | auto StartI = std::next(Stack.rbegin()); |
| 606 | auto EndI = std::prev(Stack.rend()); |
| 607 | if (FromParent && StartI != EndI) { |
| 608 | StartI = std::next(StartI); |
| 609 | } |
| 610 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 611 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 612 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 613 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 614 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 615 | return DVar; |
| 616 | return DSAVarData(); |
| 617 | } |
| 618 | return DSAVarData(); |
| 619 | } |
| 620 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 621 | bool DSAStackTy::hasExplicitDSA( |
| 622 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 623 | unsigned Level) { |
| 624 | if (CPred(ClauseKindMode)) |
| 625 | return true; |
| 626 | if (isClauseParsingMode()) |
| 627 | ++Level; |
| 628 | D = D->getCanonicalDecl(); |
| 629 | auto StartI = Stack.rbegin(); |
| 630 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 631 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 632 | return false; |
| 633 | std::advance(StartI, Level); |
| 634 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 635 | CPred(StartI->SharingMap[D].Attributes); |
| 636 | } |
| 637 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 638 | template <class NamedDirectivesPredicate> |
| 639 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 640 | auto StartI = std::next(Stack.rbegin()); |
| 641 | auto EndI = std::prev(Stack.rend()); |
| 642 | if (FromParent && StartI != EndI) { |
| 643 | StartI = std::next(StartI); |
| 644 | } |
| 645 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 646 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 647 | return true; |
| 648 | } |
| 649 | return false; |
| 650 | } |
| 651 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 652 | void Sema::InitDataSharingAttributesStack() { |
| 653 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 654 | } |
| 655 | |
| 656 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 657 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 658 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 659 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 660 | VD = VD->getCanonicalDecl(); |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 661 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 662 | (!DSAStack->isClauseParsingMode() || |
| 663 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 664 | if (DSAStack->isLoopControlVariable(VD) || |
| 665 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 666 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 667 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 668 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 669 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 670 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 671 | return true; |
| 672 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 673 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 674 | return DVarPrivate.CKind != OMPC_unknown; |
| 675 | } |
| 676 | return false; |
| 677 | } |
| 678 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 679 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 680 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 681 | return DSAStack->hasExplicitDSA( |
| 682 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 683 | } |
| 684 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 685 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 686 | |
| 687 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 688 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 689 | Scope *CurScope, SourceLocation Loc) { |
| 690 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 691 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 692 | } |
| 693 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 694 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 695 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 696 | } |
| 697 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 698 | void Sema::EndOpenMPClause() { |
| 699 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 700 | } |
| 701 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 702 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 703 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 704 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 705 | // clause requires an accessible, unambiguous default constructor for the |
| 706 | // class type, unless the list item is also specified in a firstprivate |
| 707 | // clause. |
| 708 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 709 | for (auto *C : D->clauses()) { |
| 710 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 711 | SmallVector<Expr *, 8> PrivateCopies; |
| 712 | for (auto *DE : Clause->varlists()) { |
| 713 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 714 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 715 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 716 | } |
| 717 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 718 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 719 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 720 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 721 | // Generate helper private variable and initialize it with the |
| 722 | // default value. The address of the original variable is replaced |
| 723 | // by the address of the new private variable in CodeGen. This new |
| 724 | // variable is not added to IdResolver, so the code in the OpenMP |
| 725 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 726 | auto *VDPrivate = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 727 | buildVarDecl(*this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 728 | VD->getName()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 729 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 730 | if (VDPrivate->isInvalidDecl()) |
| 731 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 732 | PrivateCopies.push_back(buildDeclRefExpr( |
| 733 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 734 | } else { |
| 735 | // The variable is also a firstprivate, so initialization sequence |
| 736 | // for private copy is generated already. |
| 737 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 738 | } |
| 739 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 740 | // Set initializers to private copies if no errors were found. |
| 741 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 742 | Clause->setPrivateCopies(PrivateCopies); |
| 743 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | } |
| 747 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 748 | DSAStack->pop(); |
| 749 | DiscardCleanupsInEvaluationContext(); |
| 750 | PopExpressionEvaluationContext(); |
| 751 | } |
| 752 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 753 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 754 | Expr *NumIterations, Sema &SemaRef, |
| 755 | Scope *S); |
| 756 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 757 | namespace { |
| 758 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 759 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 760 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 761 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 762 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 763 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 764 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 765 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 766 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 767 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 768 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 769 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 770 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 771 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 772 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 773 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 774 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 775 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 776 | |
| 777 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 778 | CXXScopeSpec &ScopeSpec, |
| 779 | const DeclarationNameInfo &Id) { |
| 780 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 781 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 782 | |
| 783 | if (Lookup.isAmbiguous()) |
| 784 | return ExprError(); |
| 785 | |
| 786 | VarDecl *VD; |
| 787 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 788 | if (TypoCorrection Corrected = CorrectTypo( |
| 789 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 790 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 791 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 792 | PDiag(Lookup.empty() |
| 793 | ? diag::err_undeclared_var_use_suggest |
| 794 | : diag::err_omp_expected_var_arg_suggest) |
| 795 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 796 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 797 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 798 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 799 | : diag::err_omp_expected_var_arg) |
| 800 | << Id.getName(); |
| 801 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 802 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 803 | } else { |
| 804 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 805 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 806 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 807 | return ExprError(); |
| 808 | } |
| 809 | } |
| 810 | Lookup.suppressDiagnostics(); |
| 811 | |
| 812 | // OpenMP [2.9.2, Syntax, C/C++] |
| 813 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 814 | if (!VD->hasGlobalStorage()) { |
| 815 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 816 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 817 | bool IsDecl = |
| 818 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 819 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 820 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 821 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 822 | return ExprError(); |
| 823 | } |
| 824 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 825 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 826 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 827 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 828 | // A threadprivate directive for file-scope variables must appear outside |
| 829 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 830 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 831 | !getCurLexicalContext()->isTranslationUnit()) { |
| 832 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 833 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 834 | bool IsDecl = |
| 835 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 836 | Diag(VD->getLocation(), |
| 837 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 838 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 839 | return ExprError(); |
| 840 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 841 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 842 | // A threadprivate directive for static class member variables must appear |
| 843 | // in the class definition, in the same scope in which the member |
| 844 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 845 | if (CanonicalVD->isStaticDataMember() && |
| 846 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 847 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 848 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 849 | bool IsDecl = |
| 850 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 851 | Diag(VD->getLocation(), |
| 852 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 853 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 854 | return ExprError(); |
| 855 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 856 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 857 | // A threadprivate directive for namespace-scope variables must appear |
| 858 | // outside any definition or declaration other than the namespace |
| 859 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 860 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 861 | (!getCurLexicalContext()->isFileContext() || |
| 862 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 863 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 864 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 865 | bool IsDecl = |
| 866 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 867 | Diag(VD->getLocation(), |
| 868 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 869 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 870 | return ExprError(); |
| 871 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 872 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 873 | // A threadprivate directive for static block-scope variables must appear |
| 874 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 875 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 876 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 877 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 878 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 879 | bool IsDecl = |
| 880 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 881 | Diag(VD->getLocation(), |
| 882 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 883 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 884 | return ExprError(); |
| 885 | } |
| 886 | |
| 887 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 888 | // A threadprivate directive must lexically precede all references to any |
| 889 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 890 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 891 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 892 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 893 | return ExprError(); |
| 894 | } |
| 895 | |
| 896 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 897 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 898 | return DE; |
| 899 | } |
| 900 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 901 | Sema::DeclGroupPtrTy |
| 902 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 903 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 904 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 905 | CurContext->addDecl(D); |
| 906 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 907 | } |
| 908 | return DeclGroupPtrTy(); |
| 909 | } |
| 910 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 911 | namespace { |
| 912 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 913 | Sema &SemaRef; |
| 914 | |
| 915 | public: |
| 916 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 917 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 918 | if (VD->hasLocalStorage()) { |
| 919 | SemaRef.Diag(E->getLocStart(), |
| 920 | diag::err_omp_local_var_in_threadprivate_init) |
| 921 | << E->getSourceRange(); |
| 922 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 923 | << VD << VD->getSourceRange(); |
| 924 | return true; |
| 925 | } |
| 926 | } |
| 927 | return false; |
| 928 | } |
| 929 | bool VisitStmt(const Stmt *S) { |
| 930 | for (auto Child : S->children()) { |
| 931 | if (Child && Visit(Child)) |
| 932 | return true; |
| 933 | } |
| 934 | return false; |
| 935 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 936 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 937 | }; |
| 938 | } // namespace |
| 939 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 940 | OMPThreadPrivateDecl * |
| 941 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 942 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 943 | for (auto &RefExpr : VarList) { |
| 944 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 945 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 946 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 947 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 948 | QualType QType = VD->getType(); |
| 949 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 950 | // It will be analyzed later. |
| 951 | Vars.push_back(DE); |
| 952 | continue; |
| 953 | } |
| 954 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 955 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 956 | // A threadprivate variable must not have an incomplete type. |
| 957 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 958 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 959 | continue; |
| 960 | } |
| 961 | |
| 962 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 963 | // A threadprivate variable must not have a reference type. |
| 964 | if (VD->getType()->isReferenceType()) { |
| 965 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 966 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 967 | bool IsDecl = |
| 968 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 969 | Diag(VD->getLocation(), |
| 970 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 971 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 972 | continue; |
| 973 | } |
| 974 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 975 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 976 | // the corresponding diagnostic. |
| 977 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 978 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 979 | getLangOpts().OpenMPUseTLS && |
| 980 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 981 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 982 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 983 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 984 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 985 | bool IsDecl = |
| 986 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 987 | Diag(VD->getLocation(), |
| 988 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 989 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 990 | continue; |
| 991 | } |
| 992 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 993 | // Check if initial value of threadprivate variable reference variable with |
| 994 | // local storage (it is not supported by runtime). |
| 995 | if (auto Init = VD->getAnyInitializer()) { |
| 996 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 997 | if (Checker.Visit(Init)) |
| 998 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 999 | } |
| 1000 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1001 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1002 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1003 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1004 | Context, SourceRange(Loc, Loc))); |
| 1005 | if (auto *ML = Context.getASTMutationListener()) |
| 1006 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1007 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1008 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1009 | if (!Vars.empty()) { |
| 1010 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1011 | Vars); |
| 1012 | D->setAccess(AS_public); |
| 1013 | } |
| 1014 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1015 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1016 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1017 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1018 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1019 | bool IsLoopIterVar = false) { |
| 1020 | if (DVar.RefExpr) { |
| 1021 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1022 | << getOpenMPClauseName(DVar.CKind); |
| 1023 | return; |
| 1024 | } |
| 1025 | enum { |
| 1026 | PDSA_StaticMemberShared, |
| 1027 | PDSA_StaticLocalVarShared, |
| 1028 | PDSA_LoopIterVarPrivate, |
| 1029 | PDSA_LoopIterVarLinear, |
| 1030 | PDSA_LoopIterVarLastprivate, |
| 1031 | PDSA_ConstVarShared, |
| 1032 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1033 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1034 | PDSA_LocalVarPrivate, |
| 1035 | PDSA_Implicit |
| 1036 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1037 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1038 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1039 | if (IsLoopIterVar) { |
| 1040 | if (DVar.CKind == OMPC_private) |
| 1041 | Reason = PDSA_LoopIterVarPrivate; |
| 1042 | else if (DVar.CKind == OMPC_lastprivate) |
| 1043 | Reason = PDSA_LoopIterVarLastprivate; |
| 1044 | else |
| 1045 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1046 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1047 | Reason = PDSA_TaskVarFirstprivate; |
| 1048 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1049 | } else if (VD->isStaticLocal()) |
| 1050 | Reason = PDSA_StaticLocalVarShared; |
| 1051 | else if (VD->isStaticDataMember()) |
| 1052 | Reason = PDSA_StaticMemberShared; |
| 1053 | else if (VD->isFileVarDecl()) |
| 1054 | Reason = PDSA_GlobalVarShared; |
| 1055 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1056 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1057 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1058 | ReportHint = true; |
| 1059 | Reason = PDSA_LocalVarPrivate; |
| 1060 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1061 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1062 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1063 | << Reason << ReportHint |
| 1064 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1065 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1066 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1067 | << getOpenMPClauseName(DVar.CKind); |
| 1068 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1071 | namespace { |
| 1072 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1073 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1074 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1075 | bool ErrorFound; |
| 1076 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1077 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1078 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1079 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1080 | public: |
| 1081 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1082 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1083 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1084 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1085 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1086 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1087 | auto DVar = Stack->getTopDSA(VD, false); |
| 1088 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1089 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1090 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1091 | auto ELoc = E->getExprLoc(); |
| 1092 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1093 | // The default(none) clause requires that each variable that is referenced |
| 1094 | // in the construct, and does not have a predetermined data-sharing |
| 1095 | // attribute, must have its data-sharing attribute explicitly determined |
| 1096 | // by being listed in a data-sharing attribute clause. |
| 1097 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1098 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1099 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1100 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1101 | return; |
| 1102 | } |
| 1103 | |
| 1104 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1105 | // A list item that appears in a reduction clause of the innermost |
| 1106 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1107 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1108 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1109 | [](OpenMPDirectiveKind K) -> bool { |
| 1110 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1111 | isOpenMPWorksharingDirective(K) || |
| 1112 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1113 | }, |
| 1114 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1115 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1116 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1117 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1118 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1119 | return; |
| 1120 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1121 | |
| 1122 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1123 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1124 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1125 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1129 | for (auto *C : S->clauses()) { |
| 1130 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1131 | // for task directives. |
| 1132 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1133 | for (auto *CC : C->children()) { |
| 1134 | if (CC) |
| 1135 | Visit(CC); |
| 1136 | } |
| 1137 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1138 | } |
| 1139 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1140 | for (auto *C : S->children()) { |
| 1141 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1142 | Visit(C); |
| 1143 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1144 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1145 | |
| 1146 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1147 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1148 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1149 | return VarsWithInheritedDSA; |
| 1150 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1151 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1152 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1153 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1154 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1155 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1156 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1157 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1158 | switch (DKind) { |
| 1159 | case OMPD_parallel: { |
| 1160 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1161 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1162 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1163 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1164 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1165 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1166 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1167 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1168 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1169 | break; |
| 1170 | } |
| 1171 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1172 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1173 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1174 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1175 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1176 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1177 | break; |
| 1178 | } |
| 1179 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1180 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1181 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1182 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1183 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1184 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1185 | break; |
| 1186 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1187 | case OMPD_for_simd: { |
| 1188 | Sema::CapturedParamNameType Params[] = { |
| 1189 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1190 | }; |
| 1191 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1192 | Params); |
| 1193 | break; |
| 1194 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1195 | case OMPD_sections: { |
| 1196 | Sema::CapturedParamNameType Params[] = { |
| 1197 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1198 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1199 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1200 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1201 | break; |
| 1202 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1203 | case OMPD_section: { |
| 1204 | Sema::CapturedParamNameType Params[] = { |
| 1205 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1206 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1207 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1208 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1209 | break; |
| 1210 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1211 | case OMPD_single: { |
| 1212 | Sema::CapturedParamNameType Params[] = { |
| 1213 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1214 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1215 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1216 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1217 | break; |
| 1218 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1219 | case OMPD_master: { |
| 1220 | Sema::CapturedParamNameType Params[] = { |
| 1221 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1222 | }; |
| 1223 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1224 | Params); |
| 1225 | break; |
| 1226 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1227 | case OMPD_critical: { |
| 1228 | Sema::CapturedParamNameType Params[] = { |
| 1229 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1230 | }; |
| 1231 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1232 | Params); |
| 1233 | break; |
| 1234 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1235 | case OMPD_parallel_for: { |
| 1236 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1237 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1238 | Sema::CapturedParamNameType Params[] = { |
| 1239 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1240 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1241 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1242 | }; |
| 1243 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1244 | Params); |
| 1245 | break; |
| 1246 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1247 | case OMPD_parallel_for_simd: { |
| 1248 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1249 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1250 | Sema::CapturedParamNameType Params[] = { |
| 1251 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1252 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1253 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1254 | }; |
| 1255 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1256 | Params); |
| 1257 | break; |
| 1258 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1259 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1260 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1261 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1262 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1263 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1264 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1265 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1266 | }; |
| 1267 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1268 | Params); |
| 1269 | break; |
| 1270 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1271 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1272 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1273 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1274 | FunctionProtoType::ExtProtoInfo EPI; |
| 1275 | EPI.Variadic = true; |
| 1276 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1277 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1278 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1279 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1280 | std::make_pair(".privates.", |
| 1281 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1282 | std::make_pair( |
| 1283 | ".copy_fn.", |
| 1284 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1285 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1286 | }; |
| 1287 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1288 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1289 | // Mark this captured region as inlined, because we don't use outlined |
| 1290 | // function directly. |
| 1291 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1292 | AlwaysInlineAttr::CreateImplicit( |
| 1293 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1294 | break; |
| 1295 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1296 | case OMPD_ordered: { |
| 1297 | Sema::CapturedParamNameType Params[] = { |
| 1298 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1299 | }; |
| 1300 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1301 | Params); |
| 1302 | break; |
| 1303 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1304 | case OMPD_atomic: { |
| 1305 | Sema::CapturedParamNameType Params[] = { |
| 1306 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1307 | }; |
| 1308 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1309 | Params); |
| 1310 | break; |
| 1311 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1312 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1313 | case OMPD_target: { |
| 1314 | Sema::CapturedParamNameType Params[] = { |
| 1315 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1316 | }; |
| 1317 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1318 | Params); |
| 1319 | break; |
| 1320 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1321 | case OMPD_teams: { |
| 1322 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1323 | QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty); |
| 1324 | Sema::CapturedParamNameType Params[] = { |
| 1325 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1326 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1327 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1328 | }; |
| 1329 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1330 | Params); |
| 1331 | break; |
| 1332 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1333 | case OMPD_taskgroup: { |
| 1334 | Sema::CapturedParamNameType Params[] = { |
| 1335 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1336 | }; |
| 1337 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1338 | Params); |
| 1339 | break; |
| 1340 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1341 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1342 | case OMPD_taskyield: |
| 1343 | case OMPD_barrier: |
| 1344 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1345 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1346 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1347 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1348 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1349 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1350 | llvm_unreachable("Unknown OpenMP directive"); |
| 1351 | } |
| 1352 | } |
| 1353 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1354 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1355 | ArrayRef<OMPClause *> Clauses) { |
| 1356 | if (!S.isUsable()) { |
| 1357 | ActOnCapturedRegionError(); |
| 1358 | return StmtError(); |
| 1359 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1360 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1361 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1362 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1363 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1364 | (getLangOpts().OpenMPUseTLS && |
| 1365 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1366 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1367 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1368 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1369 | for (auto *VarRef : Clause->children()) { |
| 1370 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1371 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1372 | } |
| 1373 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1374 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1375 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1376 | Clause->getClauseKind() == OMPC_schedule) { |
| 1377 | // Mark all variables in private list clauses as used in inner region. |
| 1378 | // Required for proper codegen of combined directives. |
| 1379 | // TODO: add processing for other clauses. |
| 1380 | if (auto *E = cast_or_null<Expr>( |
| 1381 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1382 | MarkDeclarationsReferencedInExpr(E); |
| 1383 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1384 | } |
| 1385 | } |
| 1386 | return ActOnCapturedRegionEnd(S.get()); |
| 1387 | } |
| 1388 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1389 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1390 | OpenMPDirectiveKind CurrentRegion, |
| 1391 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1392 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1393 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1394 | // Allowed nesting of constructs |
| 1395 | // +------------------+-----------------+------------------------------------+ |
| 1396 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1397 | // +------------------+-----------------+------------------------------------+ |
| 1398 | // | parallel | parallel | * | |
| 1399 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1400 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1401 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1402 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1403 | // | parallel | simd | * | |
| 1404 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1405 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1406 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1407 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1408 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1409 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1410 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1411 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1412 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1413 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1414 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1415 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1416 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1417 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1418 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1419 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1420 | // | parallel | cancellation | | |
| 1421 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1422 | // | parallel | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1423 | // +------------------+-----------------+------------------------------------+ |
| 1424 | // | for | parallel | * | |
| 1425 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1426 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1427 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1428 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1429 | // | for | simd | * | |
| 1430 | // | for | sections | + | |
| 1431 | // | for | section | + | |
| 1432 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1433 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1434 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1435 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1436 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1437 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1438 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1439 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1440 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1441 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1442 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1443 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1444 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1445 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1446 | // | for | cancellation | | |
| 1447 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1448 | // | for | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1449 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1450 | // | master | parallel | * | |
| 1451 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1452 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1453 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1454 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1455 | // | master | simd | * | |
| 1456 | // | master | sections | + | |
| 1457 | // | master | section | + | |
| 1458 | // | master | single | + | |
| 1459 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1460 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1461 | // | master |parallel sections| * | |
| 1462 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1463 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1464 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1465 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1466 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1467 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1468 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1469 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1470 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1471 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1472 | // | master | cancellation | | |
| 1473 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1474 | // | master | cancel | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1475 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1476 | // | critical | parallel | * | |
| 1477 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1478 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1479 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1480 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1481 | // | critical | simd | * | |
| 1482 | // | critical | sections | + | |
| 1483 | // | critical | section | + | |
| 1484 | // | critical | single | + | |
| 1485 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1486 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1487 | // | critical |parallel sections| * | |
| 1488 | // | critical | task | * | |
| 1489 | // | critical | taskyield | * | |
| 1490 | // | critical | barrier | + | |
| 1491 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1492 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1493 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1494 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1495 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1496 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1497 | // | critical | cancellation | | |
| 1498 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1499 | // | critical | cancel | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1500 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1501 | // | simd | parallel | | |
| 1502 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1503 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1504 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1505 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1506 | // | simd | simd | | |
| 1507 | // | simd | sections | | |
| 1508 | // | simd | section | | |
| 1509 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1510 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1511 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1512 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1513 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1514 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1515 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1516 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1517 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1518 | // | simd | flush | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1519 | // | simd | ordered | | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1520 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1521 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1522 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1523 | // | simd | cancellation | | |
| 1524 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1525 | // | simd | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1526 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1527 | // | for simd | parallel | | |
| 1528 | // | for simd | for | | |
| 1529 | // | for simd | for simd | | |
| 1530 | // | for simd | master | | |
| 1531 | // | for simd | critical | | |
| 1532 | // | for simd | simd | | |
| 1533 | // | for simd | sections | | |
| 1534 | // | for simd | section | | |
| 1535 | // | for simd | single | | |
| 1536 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1537 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1538 | // | for simd |parallel sections| | |
| 1539 | // | for simd | task | | |
| 1540 | // | for simd | taskyield | | |
| 1541 | // | for simd | barrier | | |
| 1542 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1543 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1544 | // | for simd | flush | | |
| 1545 | // | for simd | ordered | | |
| 1546 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1547 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1548 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1549 | // | for simd | cancellation | | |
| 1550 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1551 | // | for simd | cancel | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1552 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1553 | // | parallel for simd| parallel | | |
| 1554 | // | parallel for simd| for | | |
| 1555 | // | parallel for simd| for simd | | |
| 1556 | // | parallel for simd| master | | |
| 1557 | // | parallel for simd| critical | | |
| 1558 | // | parallel for simd| simd | | |
| 1559 | // | parallel for simd| sections | | |
| 1560 | // | parallel for simd| section | | |
| 1561 | // | parallel for simd| single | | |
| 1562 | // | parallel for simd| parallel for | | |
| 1563 | // | parallel for simd|parallel for simd| | |
| 1564 | // | parallel for simd|parallel sections| | |
| 1565 | // | parallel for simd| task | | |
| 1566 | // | parallel for simd| taskyield | | |
| 1567 | // | parallel for simd| barrier | | |
| 1568 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1569 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1570 | // | parallel for simd| flush | | |
| 1571 | // | parallel for simd| ordered | | |
| 1572 | // | parallel for simd| atomic | | |
| 1573 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1574 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1575 | // | parallel for simd| cancellation | | |
| 1576 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1577 | // | parallel for simd| cancel | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1578 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1579 | // | sections | parallel | * | |
| 1580 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1581 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1582 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1583 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1584 | // | sections | simd | * | |
| 1585 | // | sections | sections | + | |
| 1586 | // | sections | section | * | |
| 1587 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1588 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1589 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1590 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1591 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1592 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1593 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1594 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1595 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1596 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1597 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1598 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1599 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1600 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1601 | // | sections | cancellation | | |
| 1602 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1603 | // | sections | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1604 | // +------------------+-----------------+------------------------------------+ |
| 1605 | // | section | parallel | * | |
| 1606 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1607 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1608 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1609 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1610 | // | section | simd | * | |
| 1611 | // | section | sections | + | |
| 1612 | // | section | section | + | |
| 1613 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1614 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1615 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1616 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1617 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1618 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1619 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1620 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1621 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1622 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1623 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1624 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1625 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1626 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1627 | // | section | cancellation | | |
| 1628 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1629 | // | section | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1630 | // +------------------+-----------------+------------------------------------+ |
| 1631 | // | single | parallel | * | |
| 1632 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1633 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1634 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1635 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1636 | // | single | simd | * | |
| 1637 | // | single | sections | + | |
| 1638 | // | single | section | + | |
| 1639 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1640 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1641 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1642 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1643 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1644 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1645 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1646 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1647 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1648 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1649 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1650 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1651 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1652 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1653 | // | single | cancellation | | |
| 1654 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1655 | // | single | cancel | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1656 | // +------------------+-----------------+------------------------------------+ |
| 1657 | // | parallel for | parallel | * | |
| 1658 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1659 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1660 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1661 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1662 | // | parallel for | simd | * | |
| 1663 | // | parallel for | sections | + | |
| 1664 | // | parallel for | section | + | |
| 1665 | // | parallel for | single | + | |
| 1666 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1667 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1668 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1669 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1670 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1671 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1672 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1673 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1674 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1675 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1676 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1677 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1678 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1679 | // | parallel for | cancellation | | |
| 1680 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1681 | // | parallel for | cancel | ! | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1682 | // +------------------+-----------------+------------------------------------+ |
| 1683 | // | parallel sections| parallel | * | |
| 1684 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1685 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1686 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1687 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1688 | // | parallel sections| simd | * | |
| 1689 | // | parallel sections| sections | + | |
| 1690 | // | parallel sections| section | * | |
| 1691 | // | parallel sections| single | + | |
| 1692 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1693 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1694 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1695 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1696 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1697 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1698 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1699 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1700 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1701 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1702 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1703 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1704 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1705 | // | parallel sections| cancellation | | |
| 1706 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1707 | // | parallel sections| cancel | ! | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1708 | // +------------------+-----------------+------------------------------------+ |
| 1709 | // | task | parallel | * | |
| 1710 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1711 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1712 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1713 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1714 | // | task | simd | * | |
| 1715 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1716 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1717 | // | task | single | + | |
| 1718 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1719 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1720 | // | task |parallel sections| * | |
| 1721 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1722 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1723 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1724 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1725 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1726 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1727 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1728 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1729 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1730 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1731 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1732 | // | | point | ! | |
| 1733 | // | task | cancel | ! | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1734 | // +------------------+-----------------+------------------------------------+ |
| 1735 | // | ordered | parallel | * | |
| 1736 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1737 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1738 | // | ordered | master | * | |
| 1739 | // | ordered | critical | * | |
| 1740 | // | ordered | simd | * | |
| 1741 | // | ordered | sections | + | |
| 1742 | // | ordered | section | + | |
| 1743 | // | ordered | single | + | |
| 1744 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1745 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1746 | // | ordered |parallel sections| * | |
| 1747 | // | ordered | task | * | |
| 1748 | // | ordered | taskyield | * | |
| 1749 | // | ordered | barrier | + | |
| 1750 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1751 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1752 | // | ordered | flush | * | |
| 1753 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1754 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1755 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1756 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1757 | // | ordered | cancellation | | |
| 1758 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1759 | // | ordered | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1760 | // +------------------+-----------------+------------------------------------+ |
| 1761 | // | atomic | parallel | | |
| 1762 | // | atomic | for | | |
| 1763 | // | atomic | for simd | | |
| 1764 | // | atomic | master | | |
| 1765 | // | atomic | critical | | |
| 1766 | // | atomic | simd | | |
| 1767 | // | atomic | sections | | |
| 1768 | // | atomic | section | | |
| 1769 | // | atomic | single | | |
| 1770 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1771 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1772 | // | atomic |parallel sections| | |
| 1773 | // | atomic | task | | |
| 1774 | // | atomic | taskyield | | |
| 1775 | // | atomic | barrier | | |
| 1776 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1777 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1778 | // | atomic | flush | | |
| 1779 | // | atomic | ordered | | |
| 1780 | // | atomic | atomic | | |
| 1781 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1782 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1783 | // | atomic | cancellation | | |
| 1784 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1785 | // | atomic | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1786 | // +------------------+-----------------+------------------------------------+ |
| 1787 | // | target | parallel | * | |
| 1788 | // | target | for | * | |
| 1789 | // | target | for simd | * | |
| 1790 | // | target | master | * | |
| 1791 | // | target | critical | * | |
| 1792 | // | target | simd | * | |
| 1793 | // | target | sections | * | |
| 1794 | // | target | section | * | |
| 1795 | // | target | single | * | |
| 1796 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1797 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1798 | // | target |parallel sections| * | |
| 1799 | // | target | task | * | |
| 1800 | // | target | taskyield | * | |
| 1801 | // | target | barrier | * | |
| 1802 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1803 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1804 | // | target | flush | * | |
| 1805 | // | target | ordered | * | |
| 1806 | // | target | atomic | * | |
| 1807 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1808 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1809 | // | target | cancellation | | |
| 1810 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1811 | // | target | cancel | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1812 | // +------------------+-----------------+------------------------------------+ |
| 1813 | // | teams | parallel | * | |
| 1814 | // | teams | for | + | |
| 1815 | // | teams | for simd | + | |
| 1816 | // | teams | master | + | |
| 1817 | // | teams | critical | + | |
| 1818 | // | teams | simd | + | |
| 1819 | // | teams | sections | + | |
| 1820 | // | teams | section | + | |
| 1821 | // | teams | single | + | |
| 1822 | // | teams | parallel for | * | |
| 1823 | // | teams |parallel for simd| * | |
| 1824 | // | teams |parallel sections| * | |
| 1825 | // | teams | task | + | |
| 1826 | // | teams | taskyield | + | |
| 1827 | // | teams | barrier | + | |
| 1828 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1829 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1830 | // | teams | flush | + | |
| 1831 | // | teams | ordered | + | |
| 1832 | // | teams | atomic | + | |
| 1833 | // | teams | target | + | |
| 1834 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1835 | // | teams | cancellation | | |
| 1836 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1837 | // | teams | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1838 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1839 | if (Stack->getCurScope()) { |
| 1840 | auto ParentRegion = Stack->getParentDirective(); |
| 1841 | bool NestingProhibited = false; |
| 1842 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1843 | enum { |
| 1844 | NoRecommend, |
| 1845 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1846 | ShouldBeInOrderedRegion, |
| 1847 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1848 | } Recommend = NoRecommend; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1849 | if (isOpenMPSimdDirective(ParentRegion)) { |
| 1850 | // OpenMP [2.16, Nesting of Regions] |
| 1851 | // OpenMP constructs may not be nested inside a simd region. |
| 1852 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1853 | return true; |
| 1854 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1855 | if (ParentRegion == OMPD_atomic) { |
| 1856 | // OpenMP [2.16, Nesting of Regions] |
| 1857 | // OpenMP constructs may not be nested inside an atomic region. |
| 1858 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1859 | return true; |
| 1860 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1861 | if (CurrentRegion == OMPD_section) { |
| 1862 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1863 | // Orphaned section directives are prohibited. That is, the section |
| 1864 | // directives must appear within the sections construct and must not be |
| 1865 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1866 | if (ParentRegion != OMPD_sections && |
| 1867 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1868 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1869 | << (ParentRegion != OMPD_unknown) |
| 1870 | << getOpenMPDirectiveName(ParentRegion); |
| 1871 | return true; |
| 1872 | } |
| 1873 | return false; |
| 1874 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1875 | // Allow some constructs to be orphaned (they could be used in functions, |
| 1876 | // called from OpenMP regions with the required preconditions). |
| 1877 | if (ParentRegion == OMPD_unknown) |
| 1878 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1879 | if (CurrentRegion == OMPD_cancellation_point || |
| 1880 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1881 | // OpenMP [2.16, Nesting of Regions] |
| 1882 | // A cancellation point construct for which construct-type-clause is |
| 1883 | // taskgroup must be nested inside a task construct. A cancellation |
| 1884 | // point construct for which construct-type-clause is not taskgroup must |
| 1885 | // be closely nested inside an OpenMP construct that matches the type |
| 1886 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1887 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 1888 | // nested inside a task construct. A cancel construct for which |
| 1889 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 1890 | // OpenMP construct that matches the type specified in |
| 1891 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1892 | NestingProhibited = |
| 1893 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
| 1894 | (CancelRegion == OMPD_for && ParentRegion == OMPD_for) || |
| 1895 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 1896 | (CancelRegion == OMPD_sections && |
| 1897 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections))); |
| 1898 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1899 | // OpenMP [2.16, Nesting of Regions] |
| 1900 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1901 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1902 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 1903 | ParentRegion == OMPD_task; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1904 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 1905 | // OpenMP [2.16, Nesting of Regions] |
| 1906 | // A critical region may not be nested (closely or otherwise) inside a |
| 1907 | // critical region with the same name. Note that this restriction is not |
| 1908 | // sufficient to prevent deadlock. |
| 1909 | SourceLocation PreviousCriticalLoc; |
| 1910 | bool DeadLock = |
| 1911 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 1912 | OpenMPDirectiveKind K, |
| 1913 | const DeclarationNameInfo &DNI, |
| 1914 | SourceLocation Loc) |
| 1915 | ->bool { |
| 1916 | if (K == OMPD_critical && |
| 1917 | DNI.getName() == CurrentName.getName()) { |
| 1918 | PreviousCriticalLoc = Loc; |
| 1919 | return true; |
| 1920 | } else |
| 1921 | return false; |
| 1922 | }, |
| 1923 | false /* skip top directive */); |
| 1924 | if (DeadLock) { |
| 1925 | SemaRef.Diag(StartLoc, |
| 1926 | diag::err_omp_prohibited_region_critical_same_name) |
| 1927 | << CurrentName.getName(); |
| 1928 | if (PreviousCriticalLoc.isValid()) |
| 1929 | SemaRef.Diag(PreviousCriticalLoc, |
| 1930 | diag::note_omp_previous_critical_region); |
| 1931 | return true; |
| 1932 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1933 | } else if (CurrentRegion == OMPD_barrier) { |
| 1934 | // OpenMP [2.16, Nesting of Regions] |
| 1935 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1936 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1937 | NestingProhibited = |
| 1938 | isOpenMPWorksharingDirective(ParentRegion) || |
| 1939 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1940 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1941 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1942 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1943 | // OpenMP [2.16, Nesting of Regions] |
| 1944 | // A worksharing region may not be closely nested inside a worksharing, |
| 1945 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1946 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1947 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1948 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1949 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
| 1950 | Recommend = ShouldBeInParallelRegion; |
| 1951 | } else if (CurrentRegion == OMPD_ordered) { |
| 1952 | // OpenMP [2.16, Nesting of Regions] |
| 1953 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1954 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1955 | // An ordered region must be closely nested inside a loop region (or |
| 1956 | // parallel loop region) with an ordered clause. |
| 1957 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1958 | ParentRegion == OMPD_task || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1959 | !Stack->isParentOrderedRegion(); |
| 1960 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1961 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 1962 | // OpenMP [2.16, Nesting of Regions] |
| 1963 | // If specified, a teams construct must be contained within a target |
| 1964 | // construct. |
| 1965 | NestingProhibited = ParentRegion != OMPD_target; |
| 1966 | Recommend = ShouldBeInTargetRegion; |
| 1967 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 1968 | } |
| 1969 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 1970 | // OpenMP [2.16, Nesting of Regions] |
| 1971 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 1972 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 1973 | // constructs that can be closely nested in the teams region. |
| 1974 | // TODO: add distribute directive. |
| 1975 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 1976 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1977 | } |
| 1978 | if (NestingProhibited) { |
| 1979 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1980 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 1981 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1982 | return true; |
| 1983 | } |
| 1984 | } |
| 1985 | return false; |
| 1986 | } |
| 1987 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1988 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 1989 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 1990 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 1991 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1992 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1993 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 1994 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1995 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1996 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1997 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1998 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1999 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2000 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2001 | if (AStmt) { |
| 2002 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2003 | |
| 2004 | // Check default data sharing attributes for referenced variables. |
| 2005 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2006 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2007 | if (DSAChecker.isErrorFound()) |
| 2008 | return StmtError(); |
| 2009 | // Generate list of implicitly defined firstprivate variables. |
| 2010 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2011 | |
| 2012 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2013 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2014 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2015 | SourceLocation(), SourceLocation())) { |
| 2016 | ClausesWithImplicit.push_back(Implicit); |
| 2017 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2018 | DSAChecker.getImplicitFirstprivate().size(); |
| 2019 | } else |
| 2020 | ErrorFound = true; |
| 2021 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2022 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2023 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2024 | switch (Kind) { |
| 2025 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2026 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2027 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2028 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2029 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2030 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2031 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2032 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2033 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2034 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2035 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2036 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2037 | case OMPD_for_simd: |
| 2038 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2039 | EndLoc, VarsWithInheritedDSA); |
| 2040 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2041 | case OMPD_sections: |
| 2042 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2043 | EndLoc); |
| 2044 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2045 | case OMPD_section: |
| 2046 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2047 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2048 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2049 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2050 | case OMPD_single: |
| 2051 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2052 | EndLoc); |
| 2053 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2054 | case OMPD_master: |
| 2055 | assert(ClausesWithImplicit.empty() && |
| 2056 | "No clauses are allowed for 'omp master' directive"); |
| 2057 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2058 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2059 | case OMPD_critical: |
| 2060 | assert(ClausesWithImplicit.empty() && |
| 2061 | "No clauses are allowed for 'omp critical' directive"); |
| 2062 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2063 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2064 | case OMPD_parallel_for: |
| 2065 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2066 | EndLoc, VarsWithInheritedDSA); |
| 2067 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2068 | case OMPD_parallel_for_simd: |
| 2069 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2070 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2071 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2072 | case OMPD_parallel_sections: |
| 2073 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2074 | StartLoc, EndLoc); |
| 2075 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2076 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2077 | Res = |
| 2078 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2079 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2080 | case OMPD_taskyield: |
| 2081 | assert(ClausesWithImplicit.empty() && |
| 2082 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2083 | assert(AStmt == nullptr && |
| 2084 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2085 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2086 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2087 | case OMPD_barrier: |
| 2088 | assert(ClausesWithImplicit.empty() && |
| 2089 | "No clauses are allowed for 'omp barrier' directive"); |
| 2090 | assert(AStmt == nullptr && |
| 2091 | "No associated statement allowed for 'omp barrier' directive"); |
| 2092 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2093 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2094 | case OMPD_taskwait: |
| 2095 | assert(ClausesWithImplicit.empty() && |
| 2096 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2097 | assert(AStmt == nullptr && |
| 2098 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2099 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2100 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2101 | case OMPD_taskgroup: |
| 2102 | assert(ClausesWithImplicit.empty() && |
| 2103 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2104 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2105 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2106 | case OMPD_flush: |
| 2107 | assert(AStmt == nullptr && |
| 2108 | "No associated statement allowed for 'omp flush' directive"); |
| 2109 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2110 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2111 | case OMPD_ordered: |
| 2112 | assert(ClausesWithImplicit.empty() && |
| 2113 | "No clauses are allowed for 'omp ordered' directive"); |
| 2114 | Res = ActOnOpenMPOrderedDirective(AStmt, StartLoc, EndLoc); |
| 2115 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2116 | case OMPD_atomic: |
| 2117 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2118 | EndLoc); |
| 2119 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2120 | case OMPD_teams: |
| 2121 | Res = |
| 2122 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2123 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2124 | case OMPD_target: |
| 2125 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2126 | EndLoc); |
| 2127 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2128 | case OMPD_cancellation_point: |
| 2129 | assert(ClausesWithImplicit.empty() && |
| 2130 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2131 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2132 | "cancellation point' directive"); |
| 2133 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2134 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2135 | case OMPD_cancel: |
| 2136 | assert(ClausesWithImplicit.empty() && |
| 2137 | "No clauses are allowed for 'omp cancel' directive"); |
| 2138 | assert(AStmt == nullptr && |
| 2139 | "No associated statement allowed for 'omp cancel' directive"); |
| 2140 | Res = ActOnOpenMPCancelDirective(StartLoc, EndLoc, CancelRegion); |
| 2141 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2142 | case OMPD_target_data: |
| 2143 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2144 | EndLoc); |
| 2145 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2146 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2147 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2148 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2149 | llvm_unreachable("Unknown OpenMP directive"); |
| 2150 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2151 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2152 | for (auto P : VarsWithInheritedDSA) { |
| 2153 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2154 | << P.first << P.second->getSourceRange(); |
| 2155 | } |
| 2156 | if (!VarsWithInheritedDSA.empty()) |
| 2157 | return StmtError(); |
| 2158 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2159 | if (ErrorFound) |
| 2160 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2161 | return Res; |
| 2162 | } |
| 2163 | |
| 2164 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2165 | Stmt *AStmt, |
| 2166 | SourceLocation StartLoc, |
| 2167 | SourceLocation EndLoc) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2168 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2169 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2170 | // 1.2.2 OpenMP Language Terminology |
| 2171 | // Structured block - An executable statement with a single entry at the |
| 2172 | // top and a single exit at the bottom. |
| 2173 | // The point of exit cannot be a branch out of the structured block. |
| 2174 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2175 | CS->getCapturedDecl()->setNothrow(); |
| 2176 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2177 | getCurFunction()->setHasBranchProtectedScope(); |
| 2178 | |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 2179 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 2180 | AStmt); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2183 | namespace { |
| 2184 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2185 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2186 | /// for IR generation. |
| 2187 | class OpenMPIterationSpaceChecker { |
| 2188 | /// \brief Reference to Sema. |
| 2189 | Sema &SemaRef; |
| 2190 | /// \brief A location for diagnostics (when there is no some better location). |
| 2191 | SourceLocation DefaultLoc; |
| 2192 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2193 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2194 | /// \brief A source location for referring to loop init later. |
| 2195 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2196 | /// \brief A source location for referring to condition later. |
| 2197 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2198 | /// \brief A source location for referring to increment later. |
| 2199 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2200 | /// \brief Loop variable. |
| 2201 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2202 | /// \brief Reference to loop variable. |
| 2203 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2204 | /// \brief Lower bound (initializer for the var). |
| 2205 | Expr *LB; |
| 2206 | /// \brief Upper bound. |
| 2207 | Expr *UB; |
| 2208 | /// \brief Loop step (increment). |
| 2209 | Expr *Step; |
| 2210 | /// \brief This flag is true when condition is one of: |
| 2211 | /// Var < UB |
| 2212 | /// Var <= UB |
| 2213 | /// UB > Var |
| 2214 | /// UB >= Var |
| 2215 | bool TestIsLessOp; |
| 2216 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2217 | bool TestIsStrictOp; |
| 2218 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2219 | bool SubtractStep; |
| 2220 | |
| 2221 | public: |
| 2222 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2223 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2224 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2225 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2226 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2227 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2228 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2229 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2230 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2231 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2232 | /// for less/greater and for strict/non-strict comparison. |
| 2233 | bool CheckCond(Expr *S); |
| 2234 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2235 | /// does not conform, otherwise save loop step (#Step). |
| 2236 | bool CheckInc(Expr *S); |
| 2237 | /// \brief Return the loop counter variable. |
| 2238 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2239 | /// \brief Return the reference expression to loop counter variable. |
| 2240 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2241 | /// \brief Source range of the loop init. |
| 2242 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2243 | /// \brief Source range of the loop condition. |
| 2244 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2245 | /// \brief Source range of the loop increment. |
| 2246 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2247 | /// \brief True if the step should be subtracted. |
| 2248 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2249 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2250 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2251 | /// \brief Build the precondition expression for the loops. |
| 2252 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2253 | /// \brief Build reference expression to the counter be used for codegen. |
| 2254 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2255 | /// \brief Build reference expression to the private counter be used for |
| 2256 | /// codegen. |
| 2257 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2258 | /// \brief Build initization of the counter be used for codegen. |
| 2259 | Expr *BuildCounterInit() const; |
| 2260 | /// \brief Build step of the counter be used for codegen. |
| 2261 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2262 | /// \brief Return true if any expression is dependent. |
| 2263 | bool Dependent() const; |
| 2264 | |
| 2265 | private: |
| 2266 | /// \brief Check the right-hand side of an assignment in the increment |
| 2267 | /// expression. |
| 2268 | bool CheckIncRHS(Expr *RHS); |
| 2269 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2270 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2271 | /// \brief Helper to set upper bound. |
| 2272 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR, |
| 2273 | const SourceLocation &SL); |
| 2274 | /// \brief Helper to set loop increment. |
| 2275 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2276 | }; |
| 2277 | |
| 2278 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2279 | if (!Var) { |
| 2280 | assert(!LB && !UB && !Step); |
| 2281 | return false; |
| 2282 | } |
| 2283 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2284 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2285 | } |
| 2286 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2287 | template <typename T> |
| 2288 | static T *getExprAsWritten(T *E) { |
| 2289 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2290 | E = ExprTemp->getSubExpr(); |
| 2291 | |
| 2292 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2293 | E = MTE->GetTemporaryExpr(); |
| 2294 | |
| 2295 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2296 | E = Binder->getSubExpr(); |
| 2297 | |
| 2298 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2299 | E = ICE->getSubExprAsWritten(); |
| 2300 | return E->IgnoreParens(); |
| 2301 | } |
| 2302 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2303 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2304 | DeclRefExpr *NewVarRefExpr, |
| 2305 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2306 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2307 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2308 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2309 | if (!NewVar || !NewLB) |
| 2310 | return true; |
| 2311 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2312 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2313 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2314 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2315 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2316 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2317 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2318 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2319 | LB = NewLB; |
| 2320 | return false; |
| 2321 | } |
| 2322 | |
| 2323 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| 2324 | const SourceRange &SR, |
| 2325 | const SourceLocation &SL) { |
| 2326 | // State consistency checking to ensure correct usage. |
| 2327 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2328 | !TestIsLessOp && !TestIsStrictOp); |
| 2329 | if (!NewUB) |
| 2330 | return true; |
| 2331 | UB = NewUB; |
| 2332 | TestIsLessOp = LessOp; |
| 2333 | TestIsStrictOp = StrictOp; |
| 2334 | ConditionSrcRange = SR; |
| 2335 | ConditionLoc = SL; |
| 2336 | return false; |
| 2337 | } |
| 2338 | |
| 2339 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2340 | // State consistency checking to ensure correct usage. |
| 2341 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2342 | if (!NewStep) |
| 2343 | return true; |
| 2344 | if (!NewStep->isValueDependent()) { |
| 2345 | // Check that the step is integer expression. |
| 2346 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2347 | ExprResult Val = |
| 2348 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2349 | if (Val.isInvalid()) |
| 2350 | return true; |
| 2351 | NewStep = Val.get(); |
| 2352 | |
| 2353 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2354 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2355 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2356 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2357 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2358 | // the loop. |
| 2359 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2360 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2361 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2362 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2363 | // the loop. |
| 2364 | llvm::APSInt Result; |
| 2365 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2366 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2367 | bool IsConstNeg = |
| 2368 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2369 | bool IsConstPos = |
| 2370 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2371 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2372 | if (UB && (IsConstZero || |
| 2373 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2374 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2375 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2376 | diag::err_omp_loop_incr_not_compatible) |
| 2377 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2378 | SemaRef.Diag(ConditionLoc, |
| 2379 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2380 | << TestIsLessOp << ConditionSrcRange; |
| 2381 | return true; |
| 2382 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2383 | if (TestIsLessOp == Subtract) { |
| 2384 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2385 | NewStep).get(); |
| 2386 | Subtract = !Subtract; |
| 2387 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
| 2390 | Step = NewStep; |
| 2391 | SubtractStep = Subtract; |
| 2392 | return false; |
| 2393 | } |
| 2394 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2395 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2396 | // Check init-expr for canonical loop form and save loop counter |
| 2397 | // variable - #Var and its initialization value - #LB. |
| 2398 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2399 | // var = lb |
| 2400 | // integer-type var = lb |
| 2401 | // random-access-iterator-type var = lb |
| 2402 | // pointer-type var = lb |
| 2403 | // |
| 2404 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2405 | if (EmitDiags) { |
| 2406 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2407 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2408 | return true; |
| 2409 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2410 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2411 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2412 | S = E->IgnoreParens(); |
| 2413 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2414 | if (BO->getOpcode() == BO_Assign) |
| 2415 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2416 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2417 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2418 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2419 | if (DS->isSingleDecl()) { |
| 2420 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2421 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2422 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2423 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2424 | SemaRef.Diag(S->getLocStart(), |
| 2425 | diag::ext_omp_loop_not_canonical_init) |
| 2426 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2427 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2428 | } |
| 2429 | } |
| 2430 | } |
| 2431 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2432 | if (CE->getOperator() == OO_Equal) |
| 2433 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2434 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2435 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2436 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2437 | if (EmitDiags) { |
| 2438 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2439 | << S->getSourceRange(); |
| 2440 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2441 | return true; |
| 2442 | } |
| 2443 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2444 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2445 | /// variable (which may be the loop variable) if possible. |
| 2446 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2447 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2448 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2449 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2450 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2451 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2452 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2453 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2454 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2455 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2456 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2457 | if (!DRE) |
| 2458 | return nullptr; |
| 2459 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2460 | } |
| 2461 | |
| 2462 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2463 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2464 | // less/greater and for strict/non-strict comparison. |
| 2465 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2466 | // var relational-op b |
| 2467 | // b relational-op var |
| 2468 | // |
| 2469 | if (!S) { |
| 2470 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2471 | return true; |
| 2472 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2473 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2474 | SourceLocation CondLoc = S->getLocStart(); |
| 2475 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2476 | if (BO->isRelationalOp()) { |
| 2477 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2478 | return SetUB(BO->getRHS(), |
| 2479 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2480 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2481 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2482 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2483 | return SetUB(BO->getLHS(), |
| 2484 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2485 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2486 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2487 | } |
| 2488 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2489 | if (CE->getNumArgs() == 2) { |
| 2490 | auto Op = CE->getOperator(); |
| 2491 | switch (Op) { |
| 2492 | case OO_Greater: |
| 2493 | case OO_GreaterEqual: |
| 2494 | case OO_Less: |
| 2495 | case OO_LessEqual: |
| 2496 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2497 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2498 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2499 | CE->getOperatorLoc()); |
| 2500 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2501 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2502 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2503 | CE->getOperatorLoc()); |
| 2504 | break; |
| 2505 | default: |
| 2506 | break; |
| 2507 | } |
| 2508 | } |
| 2509 | } |
| 2510 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2511 | << S->getSourceRange() << Var; |
| 2512 | return true; |
| 2513 | } |
| 2514 | |
| 2515 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2516 | // RHS of canonical loop form increment can be: |
| 2517 | // var + incr |
| 2518 | // incr + var |
| 2519 | // var - incr |
| 2520 | // |
| 2521 | RHS = RHS->IgnoreParenImpCasts(); |
| 2522 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2523 | if (BO->isAdditiveOp()) { |
| 2524 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2525 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2526 | return SetStep(BO->getRHS(), !IsAdd); |
| 2527 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2528 | return SetStep(BO->getLHS(), false); |
| 2529 | } |
| 2530 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2531 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2532 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2533 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2534 | return SetStep(CE->getArg(1), !IsAdd); |
| 2535 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2536 | return SetStep(CE->getArg(0), false); |
| 2537 | } |
| 2538 | } |
| 2539 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2540 | << RHS->getSourceRange() << Var; |
| 2541 | return true; |
| 2542 | } |
| 2543 | |
| 2544 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2545 | // Check incr-expr for canonical loop form and return true if it |
| 2546 | // does not conform. |
| 2547 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2548 | // ++var |
| 2549 | // var++ |
| 2550 | // --var |
| 2551 | // var-- |
| 2552 | // var += incr |
| 2553 | // var -= incr |
| 2554 | // var = var + incr |
| 2555 | // var = incr + var |
| 2556 | // var = var - incr |
| 2557 | // |
| 2558 | if (!S) { |
| 2559 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2560 | return true; |
| 2561 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2562 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2563 | S = S->IgnoreParens(); |
| 2564 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2565 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2566 | return SetStep( |
| 2567 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2568 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2569 | false); |
| 2570 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2571 | switch (BO->getOpcode()) { |
| 2572 | case BO_AddAssign: |
| 2573 | case BO_SubAssign: |
| 2574 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2575 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2576 | break; |
| 2577 | case BO_Assign: |
| 2578 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2579 | return CheckIncRHS(BO->getRHS()); |
| 2580 | break; |
| 2581 | default: |
| 2582 | break; |
| 2583 | } |
| 2584 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2585 | switch (CE->getOperator()) { |
| 2586 | case OO_PlusPlus: |
| 2587 | case OO_MinusMinus: |
| 2588 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2589 | return SetStep( |
| 2590 | SemaRef.ActOnIntegerConstant( |
| 2591 | CE->getLocStart(), |
| 2592 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2593 | false); |
| 2594 | break; |
| 2595 | case OO_PlusEqual: |
| 2596 | case OO_MinusEqual: |
| 2597 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2598 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2599 | break; |
| 2600 | case OO_Equal: |
| 2601 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2602 | return CheckIncRHS(CE->getArg(1)); |
| 2603 | break; |
| 2604 | default: |
| 2605 | break; |
| 2606 | } |
| 2607 | } |
| 2608 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2609 | << S->getSourceRange() << Var; |
| 2610 | return true; |
| 2611 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2612 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2613 | namespace { |
| 2614 | // Transform variables declared in GNU statement expressions to new ones to |
| 2615 | // avoid crash on codegen. |
| 2616 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 2617 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 2618 | |
| 2619 | public: |
| 2620 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 2621 | |
| 2622 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 2623 | if (auto *VD = cast<VarDecl>(D)) |
| 2624 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 2625 | !isa<ImplicitParamDecl>(D)) { |
| 2626 | auto *NewVD = VarDecl::Create( |
| 2627 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 2628 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 2629 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 2630 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 2631 | NewVD->setInit(VD->getInit()); |
| 2632 | NewVD->setInitStyle(VD->getInitStyle()); |
| 2633 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 2634 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 2635 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 2636 | NewVD->setConstexpr(VD->isConstexpr()); |
| 2637 | NewVD->setInitCapture(VD->isInitCapture()); |
| 2638 | NewVD->setPreviousDeclInSameBlockScope( |
| 2639 | VD->isPreviousDeclInSameBlockScope()); |
| 2640 | VD->getDeclContext()->addHiddenDecl(NewVD); |
| 2641 | transformedLocalDecl(VD, NewVD); |
| 2642 | return NewVD; |
| 2643 | } |
| 2644 | return BaseTransform::TransformDefinition(Loc, D); |
| 2645 | } |
| 2646 | |
| 2647 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 2648 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 2649 | if (E->getDecl() != NewD) { |
| 2650 | NewD->setReferenced(); |
| 2651 | NewD->markUsed(SemaRef.Context); |
| 2652 | return DeclRefExpr::Create( |
| 2653 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 2654 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 2655 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 2656 | } |
| 2657 | return BaseTransform::TransformDeclRefExpr(E); |
| 2658 | } |
| 2659 | }; |
| 2660 | } |
| 2661 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2662 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2663 | Expr * |
| 2664 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2665 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2666 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2667 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2668 | auto VarType = Var->getType().getNonReferenceType(); |
| 2669 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2670 | SemaRef.getLangOpts().CPlusPlus) { |
| 2671 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2672 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 2673 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 2674 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 2675 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 2676 | if (!Upper || !Lower) |
| 2677 | return nullptr; |
| 2678 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 2679 | Sema::AA_Converting, |
| 2680 | /*AllowExplicit=*/true) |
| 2681 | .get(); |
| 2682 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 2683 | Sema::AA_Converting, |
| 2684 | /*AllowExplicit=*/true) |
| 2685 | .get(); |
| 2686 | if (!Upper || !Lower) |
| 2687 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2688 | |
| 2689 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2690 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2691 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2692 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2693 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2694 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2695 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2696 | return nullptr; |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | if (!Diff.isUsable()) |
| 2701 | return nullptr; |
| 2702 | |
| 2703 | // Upper - Lower [- 1] |
| 2704 | if (TestIsStrictOp) |
| 2705 | Diff = SemaRef.BuildBinOp( |
| 2706 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2707 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2708 | if (!Diff.isUsable()) |
| 2709 | return nullptr; |
| 2710 | |
| 2711 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2712 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2713 | if (NewStep.isInvalid()) |
| 2714 | return nullptr; |
| 2715 | NewStep = SemaRef.PerformImplicitConversion( |
| 2716 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2717 | /*AllowExplicit=*/true); |
| 2718 | if (NewStep.isInvalid()) |
| 2719 | return nullptr; |
| 2720 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2721 | if (!Diff.isUsable()) |
| 2722 | return nullptr; |
| 2723 | |
| 2724 | // Parentheses (for dumping/debugging purposes only). |
| 2725 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 2726 | if (!Diff.isUsable()) |
| 2727 | return nullptr; |
| 2728 | |
| 2729 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2730 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2731 | if (NewStep.isInvalid()) |
| 2732 | return nullptr; |
| 2733 | NewStep = SemaRef.PerformImplicitConversion( |
| 2734 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2735 | /*AllowExplicit=*/true); |
| 2736 | if (NewStep.isInvalid()) |
| 2737 | return nullptr; |
| 2738 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2739 | if (!Diff.isUsable()) |
| 2740 | return nullptr; |
| 2741 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2742 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2743 | QualType Type = Diff.get()->getType(); |
| 2744 | auto &C = SemaRef.Context; |
| 2745 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 2746 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 2747 | if (!Type->isIntegerType() || UseVarType) { |
| 2748 | unsigned NewSize = |
| 2749 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 2750 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 2751 | : Type->hasSignedIntegerRepresentation(); |
| 2752 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 2753 | Diff = SemaRef.PerformImplicitConversion( |
| 2754 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 2755 | if (!Diff.isUsable()) |
| 2756 | return nullptr; |
| 2757 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2758 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2759 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 2760 | if (NewSize != C.getTypeSize(Type)) { |
| 2761 | if (NewSize < C.getTypeSize(Type)) { |
| 2762 | assert(NewSize == 64 && "incorrect loop var size"); |
| 2763 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 2764 | << InitSrcRange << ConditionSrcRange; |
| 2765 | } |
| 2766 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2767 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 2768 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2769 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 2770 | Sema::AA_Converting, true); |
| 2771 | if (!Diff.isUsable()) |
| 2772 | return nullptr; |
| 2773 | } |
| 2774 | } |
| 2775 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2776 | return Diff.get(); |
| 2777 | } |
| 2778 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2779 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 2780 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 2781 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 2782 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2783 | TransformToNewDefs Transform(SemaRef); |
| 2784 | |
| 2785 | auto NewLB = Transform.TransformExpr(LB); |
| 2786 | auto NewUB = Transform.TransformExpr(UB); |
| 2787 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 2788 | return Cond; |
| 2789 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 2790 | Sema::AA_Converting, |
| 2791 | /*AllowExplicit=*/true); |
| 2792 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 2793 | Sema::AA_Converting, |
| 2794 | /*AllowExplicit=*/true); |
| 2795 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 2796 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2797 | auto CondExpr = SemaRef.BuildBinOp( |
| 2798 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 2799 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2800 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2801 | if (CondExpr.isUsable()) { |
| 2802 | CondExpr = SemaRef.PerformImplicitConversion( |
| 2803 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 2804 | /*AllowExplicit=*/true); |
| 2805 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2806 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 2807 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 2808 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 2809 | } |
| 2810 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2811 | /// \brief Build reference expression to the counter be used for codegen. |
| 2812 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2813 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 2814 | DefaultLoc); |
| 2815 | } |
| 2816 | |
| 2817 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 2818 | if (Var && !Var->isInvalidDecl()) { |
| 2819 | auto Type = Var->getType().getNonReferenceType(); |
| 2820 | auto *PrivateVar = buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName()); |
| 2821 | if (PrivateVar->isInvalidDecl()) |
| 2822 | return nullptr; |
| 2823 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 2824 | } |
| 2825 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2826 | } |
| 2827 | |
| 2828 | /// \brief Build initization of the counter be used for codegen. |
| 2829 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 2830 | |
| 2831 | /// \brief Build step of the counter be used for codegen. |
| 2832 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 2833 | |
| 2834 | /// \brief Iteration space of a single for loop. |
| 2835 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2836 | /// \brief Condition of the loop. |
| 2837 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2838 | /// \brief This expression calculates the number of iterations in the loop. |
| 2839 | /// It is always possible to calculate it before starting the loop. |
| 2840 | Expr *NumIterations; |
| 2841 | /// \brief The loop counter variable. |
| 2842 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2843 | /// \brief Private loop counter variable. |
| 2844 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2845 | /// \brief This is initializer for the initial value of #CounterVar. |
| 2846 | Expr *CounterInit; |
| 2847 | /// \brief This is step for the #CounterVar used to generate its update: |
| 2848 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 2849 | Expr *CounterStep; |
| 2850 | /// \brief Should step be subtracted? |
| 2851 | bool Subtract; |
| 2852 | /// \brief Source range of the loop init. |
| 2853 | SourceRange InitSrcRange; |
| 2854 | /// \brief Source range of the loop condition. |
| 2855 | SourceRange CondSrcRange; |
| 2856 | /// \brief Source range of the loop increment. |
| 2857 | SourceRange IncSrcRange; |
| 2858 | }; |
| 2859 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2860 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2861 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2862 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 2863 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 2864 | assert(Init && "Expected loop in canonical form."); |
| 2865 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 2866 | if (CollapseIteration > 0 && |
| 2867 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 2868 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 2869 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 2870 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 2871 | } |
| 2872 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 2873 | } |
| 2874 | } |
| 2875 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2876 | /// \brief Called on a for stmt to check and extract its iteration space |
| 2877 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2878 | static bool CheckOpenMPIterationSpace( |
| 2879 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 2880 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2881 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2882 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 2883 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2884 | // OpenMP [2.6, Canonical Loop Form] |
| 2885 | // for (init-expr; test-expr; incr-expr) structured-block |
| 2886 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 2887 | if (!For) { |
| 2888 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2889 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 2890 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 2891 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 2892 | if (NestedLoopCount > 1) { |
| 2893 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 2894 | SemaRef.Diag(DSA.getConstructLoc(), |
| 2895 | diag::note_omp_collapse_ordered_expr) |
| 2896 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 2897 | << OrderedLoopCountExpr->getSourceRange(); |
| 2898 | else if (CollapseLoopCountExpr) |
| 2899 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 2900 | diag::note_omp_collapse_ordered_expr) |
| 2901 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 2902 | else |
| 2903 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 2904 | diag::note_omp_collapse_ordered_expr) |
| 2905 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 2906 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2907 | return true; |
| 2908 | } |
| 2909 | assert(For->getBody()); |
| 2910 | |
| 2911 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 2912 | |
| 2913 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2914 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2915 | if (ISC.CheckInit(Init)) { |
| 2916 | return true; |
| 2917 | } |
| 2918 | |
| 2919 | bool HasErrors = false; |
| 2920 | |
| 2921 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 2922 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2923 | |
| 2924 | // OpenMP [2.6, Canonical Loop Form] |
| 2925 | // Var is one of the following: |
| 2926 | // A variable of signed or unsigned integer type. |
| 2927 | // For C++, a variable of a random access iterator type. |
| 2928 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2929 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2930 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 2931 | !VarType->isPointerType() && |
| 2932 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 2933 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 2934 | << SemaRef.getLangOpts().CPlusPlus; |
| 2935 | HasErrors = true; |
| 2936 | } |
| 2937 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2938 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 2939 | // Construct |
| 2940 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2941 | // parallel for construct is (are) private. |
| 2942 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2943 | // with just one associated for-loop is linear with a constant-linear-step |
| 2944 | // that is the increment of the associated for-loop. |
| 2945 | // Exclude loop var from the list of variables with implicitly defined data |
| 2946 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 2947 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2948 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2949 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 2950 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 2951 | // The loop iteration variable in the associated for-loop of a simd construct |
| 2952 | // with just one associated for-loop may be listed in a linear clause with a |
| 2953 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2954 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 2955 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2956 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2957 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 2958 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 2959 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2960 | auto PredeterminedCKind = |
| 2961 | isOpenMPSimdDirective(DKind) |
| 2962 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 2963 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2964 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 2965 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2966 | (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && |
| 2967 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 2968 | DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) && |
| 2969 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 2970 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2971 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2972 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 2973 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 2974 | if (DVar.RefExpr == nullptr) |
| 2975 | DVar.CKind = PredeterminedCKind; |
| 2976 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2977 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2978 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2979 | // Make the loop iteration variable private (for worksharing constructs), |
| 2980 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2981 | // lastprivate (for simd directives with several collapsed or ordered |
| 2982 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 2983 | if (DVar.CKind == OMPC_unknown) |
| 2984 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 2985 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2986 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2987 | } |
| 2988 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 2989 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2990 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2991 | // Check test-expr. |
| 2992 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 2993 | |
| 2994 | // Check incr-expr. |
| 2995 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 2996 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2997 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2998 | return HasErrors; |
| 2999 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3000 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3001 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3002 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
| 3003 | DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3004 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3005 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3006 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3007 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3008 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3009 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3010 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3011 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3012 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3013 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3014 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3015 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3016 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3017 | ResultIterSpace.CounterInit == nullptr || |
| 3018 | ResultIterSpace.CounterStep == nullptr); |
| 3019 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3020 | return HasErrors; |
| 3021 | } |
| 3022 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3023 | /// \brief Build 'VarRef = Start. |
| 3024 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3025 | ExprResult VarRef, ExprResult Start) { |
| 3026 | TransformToNewDefs Transform(SemaRef); |
| 3027 | // Build 'VarRef = Start. |
| 3028 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3029 | if (NewStart.isInvalid()) |
| 3030 | return ExprError(); |
| 3031 | NewStart = SemaRef.PerformImplicitConversion( |
| 3032 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3033 | Sema::AA_Converting, |
| 3034 | /*AllowExplicit=*/true); |
| 3035 | if (NewStart.isInvalid()) |
| 3036 | return ExprError(); |
| 3037 | NewStart = SemaRef.PerformImplicitConversion( |
| 3038 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3039 | /*AllowExplicit=*/true); |
| 3040 | if (!NewStart.isUsable()) |
| 3041 | return ExprError(); |
| 3042 | |
| 3043 | auto Init = |
| 3044 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3045 | return Init; |
| 3046 | } |
| 3047 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3048 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3049 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3050 | SourceLocation Loc, ExprResult VarRef, |
| 3051 | ExprResult Start, ExprResult Iter, |
| 3052 | ExprResult Step, bool Subtract) { |
| 3053 | // Add parentheses (for debugging purposes only). |
| 3054 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3055 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3056 | !Step.isUsable()) |
| 3057 | return ExprError(); |
| 3058 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3059 | TransformToNewDefs Transform(SemaRef); |
| 3060 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3061 | if (NewStep.isInvalid()) |
| 3062 | return ExprError(); |
| 3063 | NewStep = SemaRef.PerformImplicitConversion( |
| 3064 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3065 | Sema::AA_Converting, |
| 3066 | /*AllowExplicit=*/true); |
| 3067 | if (NewStep.isInvalid()) |
| 3068 | return ExprError(); |
| 3069 | ExprResult Update = |
| 3070 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3071 | if (!Update.isUsable()) |
| 3072 | return ExprError(); |
| 3073 | |
| 3074 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3075 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3076 | if (NewStart.isInvalid()) |
| 3077 | return ExprError(); |
| 3078 | NewStart = SemaRef.PerformImplicitConversion( |
| 3079 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3080 | Sema::AA_Converting, |
| 3081 | /*AllowExplicit=*/true); |
| 3082 | if (NewStart.isInvalid()) |
| 3083 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3084 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3085 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3086 | if (!Update.isUsable()) |
| 3087 | return ExprError(); |
| 3088 | |
| 3089 | Update = SemaRef.PerformImplicitConversion( |
| 3090 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3091 | if (!Update.isUsable()) |
| 3092 | return ExprError(); |
| 3093 | |
| 3094 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3095 | return Update; |
| 3096 | } |
| 3097 | |
| 3098 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3099 | /// bits. |
| 3100 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3101 | Sema &SemaRef) { |
| 3102 | if (E == nullptr) |
| 3103 | return ExprError(); |
| 3104 | auto &C = SemaRef.Context; |
| 3105 | QualType OldType = E->getType(); |
| 3106 | unsigned HasBits = C.getTypeSize(OldType); |
| 3107 | if (HasBits >= Bits) |
| 3108 | return ExprResult(E); |
| 3109 | // OK to convert to signed, because new type has more bits than old. |
| 3110 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3111 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3112 | true); |
| 3113 | } |
| 3114 | |
| 3115 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3116 | /// into \a Bits bits. |
| 3117 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3118 | if (E == nullptr) |
| 3119 | return false; |
| 3120 | llvm::APSInt Result; |
| 3121 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3122 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3123 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3124 | } |
| 3125 | |
| 3126 | /// \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] | 3127 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3128 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3129 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3130 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3131 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3132 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3133 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3134 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3135 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3136 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3137 | // Found 'collapse' clause - calculate collapse number. |
| 3138 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3139 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 3140 | NestedLoopCount += Result.getLimitedValue() - 1; |
| 3141 | } |
| 3142 | if (OrderedLoopCountExpr) { |
| 3143 | // Found 'ordered' clause - calculate collapse number. |
| 3144 | llvm::APSInt Result; |
| 3145 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 3146 | NestedLoopCount += Result.getLimitedValue() - 1; |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3147 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3148 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3149 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3150 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3151 | IterSpaces.resize(NestedLoopCount); |
| 3152 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3153 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3154 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3155 | NestedLoopCount, CollapseLoopCountExpr, |
| 3156 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3157 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3158 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3159 | // 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] | 3160 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3161 | // All loops associated with the construct must be perfectly nested; that |
| 3162 | // is, there must be no intervening code nor any OpenMP directive between |
| 3163 | // any two loops. |
| 3164 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3165 | } |
| 3166 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3167 | Built.clear(/* size */ NestedLoopCount); |
| 3168 | |
| 3169 | if (SemaRef.CurContext->isDependentContext()) |
| 3170 | return NestedLoopCount; |
| 3171 | |
| 3172 | // An example of what is generated for the following code: |
| 3173 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3174 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3175 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3176 | // for (k = 0; k < NK; ++k) |
| 3177 | // for (j = J0; j < NJ; j+=2) { |
| 3178 | // <loop body> |
| 3179 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3180 | // |
| 3181 | // We generate the code below. |
| 3182 | // Note: the loop body may be outlined in CodeGen. |
| 3183 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3184 | // iterations and operator+= to calculate counter value. |
| 3185 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3186 | // or i64 is currently supported). |
| 3187 | // |
| 3188 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3189 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3190 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3191 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3192 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3193 | // <loop body (using local i and j)> |
| 3194 | // } |
| 3195 | // i = NI; // assign final values of counters |
| 3196 | // j = NJ; |
| 3197 | // |
| 3198 | |
| 3199 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3200 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3201 | // Precondition tests if there is at least one iteration (all conditions are |
| 3202 | // true). |
| 3203 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3204 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3205 | ExprResult LastIteration32 = WidenIterationCount( |
| 3206 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3207 | N0->IgnoreImpCasts(), N0->getType(), |
| 3208 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3209 | .get(), |
| 3210 | SemaRef); |
| 3211 | ExprResult LastIteration64 = WidenIterationCount( |
| 3212 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3213 | N0->IgnoreImpCasts(), N0->getType(), |
| 3214 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3215 | .get(), |
| 3216 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3217 | |
| 3218 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3219 | return NestedLoopCount; |
| 3220 | |
| 3221 | auto &C = SemaRef.Context; |
| 3222 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3223 | |
| 3224 | Scope *CurScope = DSA.getCurScope(); |
| 3225 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3226 | if (PreCond.isUsable()) { |
| 3227 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3228 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3229 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3230 | auto N = IterSpaces[Cnt].NumIterations; |
| 3231 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3232 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3233 | LastIteration32 = SemaRef.BuildBinOp( |
| 3234 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3235 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3236 | Sema::AA_Converting, |
| 3237 | /*AllowExplicit=*/true) |
| 3238 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3239 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3240 | LastIteration64 = SemaRef.BuildBinOp( |
| 3241 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3242 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3243 | Sema::AA_Converting, |
| 3244 | /*AllowExplicit=*/true) |
| 3245 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | // Choose either the 32-bit or 64-bit version. |
| 3249 | ExprResult LastIteration = LastIteration64; |
| 3250 | if (LastIteration32.isUsable() && |
| 3251 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3252 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3253 | FitsInto( |
| 3254 | 32 /* Bits */, |
| 3255 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3256 | LastIteration64.get(), SemaRef))) |
| 3257 | LastIteration = LastIteration32; |
| 3258 | |
| 3259 | if (!LastIteration.isUsable()) |
| 3260 | return 0; |
| 3261 | |
| 3262 | // Save the number of iterations. |
| 3263 | ExprResult NumIterations = LastIteration; |
| 3264 | { |
| 3265 | LastIteration = SemaRef.BuildBinOp( |
| 3266 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3267 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3268 | if (!LastIteration.isUsable()) |
| 3269 | return 0; |
| 3270 | } |
| 3271 | |
| 3272 | // Calculate the last iteration number beforehand instead of doing this on |
| 3273 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3274 | llvm::APSInt Result; |
| 3275 | bool IsConstant = |
| 3276 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3277 | ExprResult CalcLastIteration; |
| 3278 | if (!IsConstant) { |
| 3279 | SourceLocation SaveLoc; |
| 3280 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3281 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3282 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3283 | ExprResult SaveRef = buildDeclRefExpr( |
| 3284 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3285 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3286 | SaveRef.get(), LastIteration.get()); |
| 3287 | LastIteration = SaveRef; |
| 3288 | |
| 3289 | // Prepare SaveRef + 1. |
| 3290 | NumIterations = SemaRef.BuildBinOp( |
| 3291 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3292 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3293 | if (!NumIterations.isUsable()) |
| 3294 | return 0; |
| 3295 | } |
| 3296 | |
| 3297 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3298 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3299 | QualType VType = LastIteration.get()->getType(); |
| 3300 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3301 | ExprResult LB, UB, IL, ST, EUB; |
| 3302 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3303 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3304 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3305 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3306 | SemaRef.AddInitializerToDecl( |
| 3307 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3308 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3309 | |
| 3310 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3311 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3312 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3313 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3314 | /*DirectInit*/ false, |
| 3315 | /*TypeMayContainAuto*/ false); |
| 3316 | |
| 3317 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3318 | // This will be used to implement clause 'lastprivate'. |
| 3319 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3320 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3321 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3322 | SemaRef.AddInitializerToDecl( |
| 3323 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3324 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3325 | |
| 3326 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3327 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3328 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3329 | SemaRef.AddInitializerToDecl( |
| 3330 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3331 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3332 | |
| 3333 | // Build expression: UB = min(UB, LastIteration) |
| 3334 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3335 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3336 | UB.get(), LastIteration.get()); |
| 3337 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3338 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3339 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3340 | CondOp.get()); |
| 3341 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3342 | } |
| 3343 | |
| 3344 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3345 | ExprResult IV; |
| 3346 | ExprResult Init; |
| 3347 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3348 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3349 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3350 | Expr *RHS = isOpenMPWorksharingDirective(DKind) |
| 3351 | ? LB.get() |
| 3352 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3353 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3354 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3357 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3358 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3359 | ExprResult Cond = |
| 3360 | isOpenMPWorksharingDirective(DKind) |
| 3361 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3362 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3363 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3364 | |
| 3365 | // Loop increment (IV = IV + 1) |
| 3366 | SourceLocation IncLoc; |
| 3367 | ExprResult Inc = |
| 3368 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3369 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3370 | if (!Inc.isUsable()) |
| 3371 | return 0; |
| 3372 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3373 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3374 | if (!Inc.isUsable()) |
| 3375 | return 0; |
| 3376 | |
| 3377 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3378 | // Used for directives with static scheduling. |
| 3379 | ExprResult NextLB, NextUB; |
| 3380 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3381 | // LB + ST |
| 3382 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3383 | if (!NextLB.isUsable()) |
| 3384 | return 0; |
| 3385 | // LB = LB + ST |
| 3386 | NextLB = |
| 3387 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3388 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3389 | if (!NextLB.isUsable()) |
| 3390 | return 0; |
| 3391 | // UB + ST |
| 3392 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3393 | if (!NextUB.isUsable()) |
| 3394 | return 0; |
| 3395 | // UB = UB + ST |
| 3396 | NextUB = |
| 3397 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3398 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3399 | if (!NextUB.isUsable()) |
| 3400 | return 0; |
| 3401 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3402 | |
| 3403 | // Build updates and final values of the loop counters. |
| 3404 | bool HasErrors = false; |
| 3405 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3406 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3407 | Built.Updates.resize(NestedLoopCount); |
| 3408 | Built.Finals.resize(NestedLoopCount); |
| 3409 | { |
| 3410 | ExprResult Div; |
| 3411 | // Go from inner nested loop to outer. |
| 3412 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3413 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3414 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3415 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3416 | // where Div is product of previous iterations' IS.NumIters. |
| 3417 | ExprResult Iter; |
| 3418 | if (Div.isUsable()) { |
| 3419 | Iter = |
| 3420 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3421 | } else { |
| 3422 | Iter = IV; |
| 3423 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3424 | "unusable div expected on first iteration only"); |
| 3425 | } |
| 3426 | |
| 3427 | if (Cnt != 0 && Iter.isUsable()) |
| 3428 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3429 | IS.NumIterations); |
| 3430 | if (!Iter.isUsable()) { |
| 3431 | HasErrors = true; |
| 3432 | break; |
| 3433 | } |
| 3434 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3435 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3436 | auto *CounterVar = buildDeclRefExpr( |
| 3437 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3438 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3439 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3440 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3441 | IS.CounterInit); |
| 3442 | if (!Init.isUsable()) { |
| 3443 | HasErrors = true; |
| 3444 | break; |
| 3445 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3446 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3447 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3448 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3449 | if (!Update.isUsable()) { |
| 3450 | HasErrors = true; |
| 3451 | break; |
| 3452 | } |
| 3453 | |
| 3454 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3455 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3456 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3457 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3458 | if (!Final.isUsable()) { |
| 3459 | HasErrors = true; |
| 3460 | break; |
| 3461 | } |
| 3462 | |
| 3463 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3464 | if (Cnt != 0) { |
| 3465 | if (Div.isUnset()) |
| 3466 | Div = IS.NumIterations; |
| 3467 | else |
| 3468 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3469 | IS.NumIterations); |
| 3470 | |
| 3471 | // Add parentheses (for debugging purposes only). |
| 3472 | if (Div.isUsable()) |
| 3473 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3474 | if (!Div.isUsable()) { |
| 3475 | HasErrors = true; |
| 3476 | break; |
| 3477 | } |
| 3478 | } |
| 3479 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3480 | HasErrors = true; |
| 3481 | break; |
| 3482 | } |
| 3483 | // Save results |
| 3484 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3485 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3486 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3487 | Built.Updates[Cnt] = Update.get(); |
| 3488 | Built.Finals[Cnt] = Final.get(); |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | if (HasErrors) |
| 3493 | return 0; |
| 3494 | |
| 3495 | // Save results |
| 3496 | Built.IterationVarRef = IV.get(); |
| 3497 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3498 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3499 | Built.CalcLastIteration = |
| 3500 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3501 | Built.PreCond = PreCond.get(); |
| 3502 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3503 | Built.Init = Init.get(); |
| 3504 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3505 | Built.LB = LB.get(); |
| 3506 | Built.UB = UB.get(); |
| 3507 | Built.IL = IL.get(); |
| 3508 | Built.ST = ST.get(); |
| 3509 | Built.EUB = EUB.get(); |
| 3510 | Built.NLB = NextLB.get(); |
| 3511 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3512 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3513 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3514 | } |
| 3515 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3516 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 3517 | auto &&CollapseFilter = [](const OMPClause *C) -> bool { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3518 | return C->getClauseKind() == OMPC_collapse; |
| 3519 | }; |
| 3520 | OMPExecutableDirective::filtered_clause_iterator<decltype(CollapseFilter)> I( |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 3521 | Clauses, std::move(CollapseFilter)); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3522 | if (I) |
| 3523 | return cast<OMPCollapseClause>(*I)->getNumForLoops(); |
| 3524 | return nullptr; |
| 3525 | } |
| 3526 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3527 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
| 3528 | auto &&OrderedFilter = [](const OMPClause *C) -> bool { |
| 3529 | return C->getClauseKind() == OMPC_ordered; |
| 3530 | }; |
| 3531 | OMPExecutableDirective::filtered_clause_iterator<decltype(OrderedFilter)> I( |
| 3532 | Clauses, std::move(OrderedFilter)); |
| 3533 | if (I) |
| 3534 | return cast<OMPOrderedClause>(*I)->getNumForLoops(); |
| 3535 | return nullptr; |
| 3536 | } |
| 3537 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3538 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3539 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3540 | SourceLocation EndLoc, |
| 3541 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3542 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3543 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3544 | // define the nested loops number. |
| 3545 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3546 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3547 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3548 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3549 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3550 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3551 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3552 | "omp simd loop exprs were not built"); |
| 3553 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3554 | if (!CurContext->isDependentContext()) { |
| 3555 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3556 | for (auto C : Clauses) { |
| 3557 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3558 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3559 | B.NumIterations, *this, CurScope)) |
| 3560 | return StmtError(); |
| 3561 | } |
| 3562 | } |
| 3563 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3564 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3565 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3566 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3567 | } |
| 3568 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3569 | StmtResult Sema::ActOnOpenMPForDirective( |
| 3570 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3571 | SourceLocation EndLoc, |
| 3572 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3573 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3574 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3575 | // define the nested loops number. |
| 3576 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3577 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3578 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3579 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3580 | return StmtError(); |
| 3581 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3582 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3583 | "omp for loop exprs were not built"); |
| 3584 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 3585 | if (!CurContext->isDependentContext()) { |
| 3586 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3587 | for (auto C : Clauses) { |
| 3588 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3589 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3590 | B.NumIterations, *this, CurScope)) |
| 3591 | return StmtError(); |
| 3592 | } |
| 3593 | } |
| 3594 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3595 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3596 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3597 | Clauses, AStmt, B); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3598 | } |
| 3599 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3600 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 3601 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3602 | SourceLocation EndLoc, |
| 3603 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3604 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3605 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3606 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3607 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3608 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 3609 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3610 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3611 | if (NestedLoopCount == 0) |
| 3612 | return StmtError(); |
| 3613 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3614 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3615 | "omp for simd loop exprs were not built"); |
| 3616 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 3617 | if (!CurContext->isDependentContext()) { |
| 3618 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3619 | for (auto C : Clauses) { |
| 3620 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3621 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3622 | B.NumIterations, *this, CurScope)) |
| 3623 | return StmtError(); |
| 3624 | } |
| 3625 | } |
| 3626 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3627 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3628 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3629 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3632 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3633 | Stmt *AStmt, |
| 3634 | SourceLocation StartLoc, |
| 3635 | SourceLocation EndLoc) { |
| 3636 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3637 | auto BaseStmt = AStmt; |
| 3638 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3639 | BaseStmt = CS->getCapturedStmt(); |
| 3640 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3641 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3642 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3643 | return StmtError(); |
| 3644 | // All associated statements must be '#pragma omp section' except for |
| 3645 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3646 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3647 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3648 | if (SectionStmt) |
| 3649 | Diag(SectionStmt->getLocStart(), |
| 3650 | diag::err_omp_sections_substmt_not_section); |
| 3651 | return StmtError(); |
| 3652 | } |
| 3653 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3654 | } else { |
| 3655 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 3656 | return StmtError(); |
| 3657 | } |
| 3658 | |
| 3659 | getCurFunction()->setHasBranchProtectedScope(); |
| 3660 | |
| 3661 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 3662 | AStmt); |
| 3663 | } |
| 3664 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3665 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 3666 | SourceLocation StartLoc, |
| 3667 | SourceLocation EndLoc) { |
| 3668 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3669 | |
| 3670 | getCurFunction()->setHasBranchProtectedScope(); |
| 3671 | |
| 3672 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3673 | } |
| 3674 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3675 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 3676 | Stmt *AStmt, |
| 3677 | SourceLocation StartLoc, |
| 3678 | SourceLocation EndLoc) { |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3679 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3680 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3681 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3682 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 3683 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 3684 | // The copyprivate clause must not be used with the nowait clause. |
| 3685 | OMPClause *Nowait = nullptr; |
| 3686 | OMPClause *Copyprivate = nullptr; |
| 3687 | for (auto *Clause : Clauses) { |
| 3688 | if (Clause->getClauseKind() == OMPC_nowait) |
| 3689 | Nowait = Clause; |
| 3690 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 3691 | Copyprivate = Clause; |
| 3692 | if (Copyprivate && Nowait) { |
| 3693 | Diag(Copyprivate->getLocStart(), |
| 3694 | diag::err_omp_single_copyprivate_with_nowait); |
| 3695 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 3696 | return StmtError(); |
| 3697 | } |
| 3698 | } |
| 3699 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3700 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3701 | } |
| 3702 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3703 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 3704 | SourceLocation StartLoc, |
| 3705 | SourceLocation EndLoc) { |
| 3706 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3707 | |
| 3708 | getCurFunction()->setHasBranchProtectedScope(); |
| 3709 | |
| 3710 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3711 | } |
| 3712 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3713 | StmtResult |
| 3714 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 3715 | Stmt *AStmt, SourceLocation StartLoc, |
| 3716 | SourceLocation EndLoc) { |
| 3717 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3718 | |
| 3719 | getCurFunction()->setHasBranchProtectedScope(); |
| 3720 | |
| 3721 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 3722 | AStmt); |
| 3723 | } |
| 3724 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3725 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 3726 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3727 | SourceLocation EndLoc, |
| 3728 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3729 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3730 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3731 | // 1.2.2 OpenMP Language Terminology |
| 3732 | // Structured block - An executable statement with a single entry at the |
| 3733 | // top and a single exit at the bottom. |
| 3734 | // The point of exit cannot be a branch out of the structured block. |
| 3735 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3736 | CS->getCapturedDecl()->setNothrow(); |
| 3737 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3738 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3739 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3740 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3741 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3742 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 3743 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3744 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3745 | if (NestedLoopCount == 0) |
| 3746 | return StmtError(); |
| 3747 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3748 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3749 | "omp parallel for loop exprs were not built"); |
| 3750 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 3751 | if (!CurContext->isDependentContext()) { |
| 3752 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3753 | for (auto C : Clauses) { |
| 3754 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3755 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3756 | B.NumIterations, *this, CurScope)) |
| 3757 | return StmtError(); |
| 3758 | } |
| 3759 | } |
| 3760 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3761 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3762 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 3763 | NestedLoopCount, Clauses, AStmt, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3764 | } |
| 3765 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3766 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 3767 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3768 | SourceLocation EndLoc, |
| 3769 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
| 3770 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3771 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3772 | // 1.2.2 OpenMP Language Terminology |
| 3773 | // Structured block - An executable statement with a single entry at the |
| 3774 | // top and a single exit at the bottom. |
| 3775 | // The point of exit cannot be a branch out of the structured block. |
| 3776 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3777 | CS->getCapturedDecl()->setNothrow(); |
| 3778 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3779 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3780 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3781 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3782 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3783 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 3784 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3785 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3786 | if (NestedLoopCount == 0) |
| 3787 | return StmtError(); |
| 3788 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 3789 | if (!CurContext->isDependentContext()) { |
| 3790 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3791 | for (auto C : Clauses) { |
| 3792 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3793 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3794 | B.NumIterations, *this, CurScope)) |
| 3795 | return StmtError(); |
| 3796 | } |
| 3797 | } |
| 3798 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3799 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3800 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3801 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3804 | StmtResult |
| 3805 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3806 | Stmt *AStmt, SourceLocation StartLoc, |
| 3807 | SourceLocation EndLoc) { |
| 3808 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3809 | auto BaseStmt = AStmt; |
| 3810 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3811 | BaseStmt = CS->getCapturedStmt(); |
| 3812 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3813 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3814 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3815 | return StmtError(); |
| 3816 | // All associated statements must be '#pragma omp section' except for |
| 3817 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3818 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3819 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3820 | if (SectionStmt) |
| 3821 | Diag(SectionStmt->getLocStart(), |
| 3822 | diag::err_omp_parallel_sections_substmt_not_section); |
| 3823 | return StmtError(); |
| 3824 | } |
| 3825 | } |
| 3826 | } else { |
| 3827 | Diag(AStmt->getLocStart(), |
| 3828 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 3829 | return StmtError(); |
| 3830 | } |
| 3831 | |
| 3832 | getCurFunction()->setHasBranchProtectedScope(); |
| 3833 | |
| 3834 | return OMPParallelSectionsDirective::Create(Context, StartLoc, EndLoc, |
| 3835 | Clauses, AStmt); |
| 3836 | } |
| 3837 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3838 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 3839 | Stmt *AStmt, SourceLocation StartLoc, |
| 3840 | SourceLocation EndLoc) { |
| 3841 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3842 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3843 | // 1.2.2 OpenMP Language Terminology |
| 3844 | // Structured block - An executable statement with a single entry at the |
| 3845 | // top and a single exit at the bottom. |
| 3846 | // The point of exit cannot be a branch out of the structured block. |
| 3847 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3848 | CS->getCapturedDecl()->setNothrow(); |
| 3849 | |
| 3850 | getCurFunction()->setHasBranchProtectedScope(); |
| 3851 | |
| 3852 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3853 | } |
| 3854 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3855 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 3856 | SourceLocation EndLoc) { |
| 3857 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 3858 | } |
| 3859 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3860 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 3861 | SourceLocation EndLoc) { |
| 3862 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 3863 | } |
| 3864 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3865 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 3866 | SourceLocation EndLoc) { |
| 3867 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 3868 | } |
| 3869 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3870 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 3871 | SourceLocation StartLoc, |
| 3872 | SourceLocation EndLoc) { |
| 3873 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3874 | |
| 3875 | getCurFunction()->setHasBranchProtectedScope(); |
| 3876 | |
| 3877 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3878 | } |
| 3879 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3880 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 3881 | SourceLocation StartLoc, |
| 3882 | SourceLocation EndLoc) { |
| 3883 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 3884 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 3885 | } |
| 3886 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3887 | StmtResult Sema::ActOnOpenMPOrderedDirective(Stmt *AStmt, |
| 3888 | SourceLocation StartLoc, |
| 3889 | SourceLocation EndLoc) { |
| 3890 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3891 | |
| 3892 | getCurFunction()->setHasBranchProtectedScope(); |
| 3893 | |
| 3894 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3895 | } |
| 3896 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3897 | namespace { |
| 3898 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 3899 | /// construct. |
| 3900 | class OpenMPAtomicUpdateChecker { |
| 3901 | /// \brief Error results for atomic update expressions. |
| 3902 | enum ExprAnalysisErrorCode { |
| 3903 | /// \brief A statement is not an expression statement. |
| 3904 | NotAnExpression, |
| 3905 | /// \brief Expression is not builtin binary or unary operation. |
| 3906 | NotABinaryOrUnaryExpression, |
| 3907 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 3908 | NotAnUnaryIncDecExpression, |
| 3909 | /// \brief An expression is not of scalar type. |
| 3910 | NotAScalarType, |
| 3911 | /// \brief A binary operation is not an assignment operation. |
| 3912 | NotAnAssignmentOp, |
| 3913 | /// \brief RHS part of the binary operation is not a binary expression. |
| 3914 | NotABinaryExpression, |
| 3915 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 3916 | /// expression. |
| 3917 | NotABinaryOperator, |
| 3918 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 3919 | /// part. |
| 3920 | NotAnUpdateExpression, |
| 3921 | /// \brief No errors is found. |
| 3922 | NoError |
| 3923 | }; |
| 3924 | /// \brief Reference to Sema. |
| 3925 | Sema &SemaRef; |
| 3926 | /// \brief A location for note diagnostics (when error is found). |
| 3927 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3928 | /// \brief 'x' lvalue part of the source atomic expression. |
| 3929 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3930 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 3931 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3932 | /// \brief Helper expression of the form |
| 3933 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 3934 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 3935 | Expr *UpdateExpr; |
| 3936 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 3937 | /// important for non-associative operations. |
| 3938 | bool IsXLHSInRHSPart; |
| 3939 | BinaryOperatorKind Op; |
| 3940 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3941 | /// \brief true if the source expression is a postfix unary operation, false |
| 3942 | /// if it is a prefix unary operation. |
| 3943 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3944 | |
| 3945 | public: |
| 3946 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3947 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3948 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3949 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 3950 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3951 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 3952 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3953 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 3954 | /// \param NoteId Diagnostic note for the main error message. |
| 3955 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3956 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3957 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 3958 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3959 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 3960 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3961 | /// \brief Return the update expression used in calculation of the updated |
| 3962 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 3963 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 3964 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 3965 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 3966 | /// false otherwise. |
| 3967 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 3968 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3969 | /// \brief true if the source expression is a postfix unary operation, false |
| 3970 | /// if it is a prefix unary operation. |
| 3971 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 3972 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3973 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 3974 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 3975 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3976 | }; |
| 3977 | } // namespace |
| 3978 | |
| 3979 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 3980 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 3981 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 3982 | SourceLocation ErrorLoc, NoteLoc; |
| 3983 | SourceRange ErrorRange, NoteRange; |
| 3984 | // Allowed constructs are: |
| 3985 | // x = x binop expr; |
| 3986 | // x = expr binop x; |
| 3987 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 3988 | X = AtomicBinOp->getLHS(); |
| 3989 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 3990 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 3991 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 3992 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 3993 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 3994 | Op = AtomicInnerBinOp->getOpcode(); |
| 3995 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 3996 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 3997 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 3998 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 3999 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4000 | /*Canonical=*/true); |
| 4001 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4002 | /*Canonical=*/true); |
| 4003 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4004 | /*Canonical=*/true); |
| 4005 | if (XId == LHSId) { |
| 4006 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4007 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4008 | } else if (XId == RHSId) { |
| 4009 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4010 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4011 | } else { |
| 4012 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4013 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4014 | NoteLoc = X->getExprLoc(); |
| 4015 | NoteRange = X->getSourceRange(); |
| 4016 | ErrorFound = NotAnUpdateExpression; |
| 4017 | } |
| 4018 | } else { |
| 4019 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4020 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4021 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4022 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4023 | ErrorFound = NotABinaryOperator; |
| 4024 | } |
| 4025 | } else { |
| 4026 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4027 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4028 | ErrorFound = NotABinaryExpression; |
| 4029 | } |
| 4030 | } else { |
| 4031 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4032 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4033 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4034 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4035 | ErrorFound = NotAnAssignmentOp; |
| 4036 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4037 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4038 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4039 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4040 | return true; |
| 4041 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4042 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4043 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4047 | unsigned NoteId) { |
| 4048 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4049 | SourceLocation ErrorLoc, NoteLoc; |
| 4050 | SourceRange ErrorRange, NoteRange; |
| 4051 | // Allowed constructs are: |
| 4052 | // x++; |
| 4053 | // x--; |
| 4054 | // ++x; |
| 4055 | // --x; |
| 4056 | // x binop= expr; |
| 4057 | // x = x binop expr; |
| 4058 | // x = expr binop x; |
| 4059 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4060 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4061 | if (AtomicBody->getType()->isScalarType() || |
| 4062 | AtomicBody->isInstantiationDependent()) { |
| 4063 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4064 | AtomicBody->IgnoreParenImpCasts())) { |
| 4065 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4066 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4067 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4068 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4069 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4070 | X = AtomicCompAssignOp->getLHS(); |
| 4071 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4072 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4073 | AtomicBody->IgnoreParenImpCasts())) { |
| 4074 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4075 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4076 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4077 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4078 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4079 | // Check for Unary Operation |
| 4080 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4081 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4082 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4083 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4084 | X = AtomicUnaryOp->getSubExpr(); |
| 4085 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4086 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4087 | } else { |
| 4088 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4089 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4090 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4091 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4092 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4093 | } |
| 4094 | } else { |
| 4095 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4096 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4097 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4098 | } |
| 4099 | } else { |
| 4100 | ErrorFound = NotAScalarType; |
| 4101 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4102 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4103 | } |
| 4104 | } else { |
| 4105 | ErrorFound = NotAnExpression; |
| 4106 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4107 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4108 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4109 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4110 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4111 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4112 | return true; |
| 4113 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4114 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4115 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4116 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4117 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4118 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4119 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4120 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4121 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4122 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4123 | auto Update = |
| 4124 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4125 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4126 | if (Update.isInvalid()) |
| 4127 | return true; |
| 4128 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4129 | Sema::AA_Casting); |
| 4130 | if (Update.isInvalid()) |
| 4131 | return true; |
| 4132 | UpdateExpr = Update.get(); |
| 4133 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4134 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4135 | } |
| 4136 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4137 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4138 | Stmt *AStmt, |
| 4139 | SourceLocation StartLoc, |
| 4140 | SourceLocation EndLoc) { |
| 4141 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4142 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4143 | // 1.2.2 OpenMP Language Terminology |
| 4144 | // Structured block - An executable statement with a single entry at the |
| 4145 | // top and a single exit at the bottom. |
| 4146 | // The point of exit cannot be a branch out of the structured block. |
| 4147 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4148 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4149 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4150 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4151 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4152 | C->getClauseKind() == OMPC_update || |
| 4153 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4154 | if (AtomicKind != OMPC_unknown) { |
| 4155 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4156 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4157 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4158 | << getOpenMPClauseName(AtomicKind); |
| 4159 | } else { |
| 4160 | AtomicKind = C->getClauseKind(); |
| 4161 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4162 | } |
| 4163 | } |
| 4164 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4165 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4166 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4167 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4168 | Body = EWC->getSubExpr(); |
| 4169 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4170 | Expr *X = nullptr; |
| 4171 | Expr *V = nullptr; |
| 4172 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4173 | Expr *UE = nullptr; |
| 4174 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4175 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4176 | // OpenMP [2.12.6, atomic Construct] |
| 4177 | // In the next expressions: |
| 4178 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4179 | // * During the execution of an atomic region, multiple syntactic |
| 4180 | // occurrences of x must designate the same storage location. |
| 4181 | // * Neither of v and expr (as applicable) may access the storage location |
| 4182 | // designated by x. |
| 4183 | // * Neither of x and expr (as applicable) may access the storage location |
| 4184 | // designated by v. |
| 4185 | // * expr is an expression with scalar type. |
| 4186 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4187 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4188 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4189 | // (expr). This requirement is satisfied if the operators in expr have |
| 4190 | // precedence greater than binop, or by using parentheses around expr or |
| 4191 | // subexpressions of expr. |
| 4192 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4193 | // binop x. This requirement is satisfied if the operators in expr have |
| 4194 | // precedence equal to or greater than binop, or by using parentheses around |
| 4195 | // expr or subexpressions of expr. |
| 4196 | // * For forms that allow multiple occurrences of x, the number of times |
| 4197 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4198 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4199 | enum { |
| 4200 | NotAnExpression, |
| 4201 | NotAnAssignmentOp, |
| 4202 | NotAScalarType, |
| 4203 | NotAnLValue, |
| 4204 | NoError |
| 4205 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4206 | SourceLocation ErrorLoc, NoteLoc; |
| 4207 | SourceRange ErrorRange, NoteRange; |
| 4208 | // If clause is read: |
| 4209 | // v = x; |
| 4210 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4211 | auto AtomicBinOp = |
| 4212 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4213 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4214 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4215 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4216 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4217 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4218 | if (!X->isLValue() || !V->isLValue()) { |
| 4219 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4220 | ErrorFound = NotAnLValue; |
| 4221 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4222 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4223 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4224 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4225 | } |
| 4226 | } else if (!X->isInstantiationDependent() || |
| 4227 | !V->isInstantiationDependent()) { |
| 4228 | auto NotScalarExpr = |
| 4229 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4230 | ? V |
| 4231 | : X; |
| 4232 | ErrorFound = NotAScalarType; |
| 4233 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4234 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4235 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4236 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4237 | } |
| 4238 | } else { |
| 4239 | ErrorFound = NotAnAssignmentOp; |
| 4240 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4241 | ErrorRange = AtomicBody->getSourceRange(); |
| 4242 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4243 | : AtomicBody->getExprLoc(); |
| 4244 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4245 | : AtomicBody->getSourceRange(); |
| 4246 | } |
| 4247 | } else { |
| 4248 | ErrorFound = NotAnExpression; |
| 4249 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4250 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4251 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4252 | if (ErrorFound != NoError) { |
| 4253 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4254 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4255 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4256 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4257 | return StmtError(); |
| 4258 | } else if (CurContext->isDependentContext()) |
| 4259 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4260 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4261 | enum { |
| 4262 | NotAnExpression, |
| 4263 | NotAnAssignmentOp, |
| 4264 | NotAScalarType, |
| 4265 | NotAnLValue, |
| 4266 | NoError |
| 4267 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4268 | SourceLocation ErrorLoc, NoteLoc; |
| 4269 | SourceRange ErrorRange, NoteRange; |
| 4270 | // If clause is write: |
| 4271 | // x = expr; |
| 4272 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4273 | auto AtomicBinOp = |
| 4274 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4275 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4276 | X = AtomicBinOp->getLHS(); |
| 4277 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4278 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4279 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4280 | if (!X->isLValue()) { |
| 4281 | ErrorFound = NotAnLValue; |
| 4282 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4283 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4284 | NoteLoc = X->getExprLoc(); |
| 4285 | NoteRange = X->getSourceRange(); |
| 4286 | } |
| 4287 | } else if (!X->isInstantiationDependent() || |
| 4288 | !E->isInstantiationDependent()) { |
| 4289 | auto NotScalarExpr = |
| 4290 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4291 | ? E |
| 4292 | : X; |
| 4293 | ErrorFound = NotAScalarType; |
| 4294 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4295 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4296 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4297 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4298 | } |
| 4299 | } else { |
| 4300 | ErrorFound = NotAnAssignmentOp; |
| 4301 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4302 | ErrorRange = AtomicBody->getSourceRange(); |
| 4303 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4304 | : AtomicBody->getExprLoc(); |
| 4305 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4306 | : AtomicBody->getSourceRange(); |
| 4307 | } |
| 4308 | } else { |
| 4309 | ErrorFound = NotAnExpression; |
| 4310 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4311 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4312 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4313 | if (ErrorFound != NoError) { |
| 4314 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4315 | << ErrorRange; |
| 4316 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4317 | << NoteRange; |
| 4318 | return StmtError(); |
| 4319 | } else if (CurContext->isDependentContext()) |
| 4320 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4321 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4322 | // If clause is update: |
| 4323 | // x++; |
| 4324 | // x--; |
| 4325 | // ++x; |
| 4326 | // --x; |
| 4327 | // x binop= expr; |
| 4328 | // x = x binop expr; |
| 4329 | // x = expr binop x; |
| 4330 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4331 | if (Checker.checkStatement( |
| 4332 | Body, (AtomicKind == OMPC_update) |
| 4333 | ? diag::err_omp_atomic_update_not_expression_statement |
| 4334 | : diag::err_omp_atomic_not_expression_statement, |
| 4335 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4336 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4337 | if (!CurContext->isDependentContext()) { |
| 4338 | E = Checker.getExpr(); |
| 4339 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4340 | UE = Checker.getUpdateExpr(); |
| 4341 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4342 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4343 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4344 | enum { |
| 4345 | NotAnAssignmentOp, |
| 4346 | NotACompoundStatement, |
| 4347 | NotTwoSubstatements, |
| 4348 | NotASpecificExpression, |
| 4349 | NoError |
| 4350 | } ErrorFound = NoError; |
| 4351 | SourceLocation ErrorLoc, NoteLoc; |
| 4352 | SourceRange ErrorRange, NoteRange; |
| 4353 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 4354 | // If clause is a capture: |
| 4355 | // v = x++; |
| 4356 | // v = x--; |
| 4357 | // v = ++x; |
| 4358 | // v = --x; |
| 4359 | // v = x binop= expr; |
| 4360 | // v = x = x binop expr; |
| 4361 | // v = x = expr binop x; |
| 4362 | auto *AtomicBinOp = |
| 4363 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4364 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4365 | V = AtomicBinOp->getLHS(); |
| 4366 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4367 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4368 | if (Checker.checkStatement( |
| 4369 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 4370 | diag::note_omp_atomic_update)) |
| 4371 | return StmtError(); |
| 4372 | E = Checker.getExpr(); |
| 4373 | X = Checker.getX(); |
| 4374 | UE = Checker.getUpdateExpr(); |
| 4375 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 4376 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
| 4377 | } else { |
| 4378 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4379 | ErrorRange = AtomicBody->getSourceRange(); |
| 4380 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4381 | : AtomicBody->getExprLoc(); |
| 4382 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4383 | : AtomicBody->getSourceRange(); |
| 4384 | ErrorFound = NotAnAssignmentOp; |
| 4385 | } |
| 4386 | if (ErrorFound != NoError) { |
| 4387 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 4388 | << ErrorRange; |
| 4389 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4390 | return StmtError(); |
| 4391 | } else if (CurContext->isDependentContext()) { |
| 4392 | UE = V = E = X = nullptr; |
| 4393 | } |
| 4394 | } else { |
| 4395 | // If clause is a capture: |
| 4396 | // { v = x; x = expr; } |
| 4397 | // { v = x; x++; } |
| 4398 | // { v = x; x--; } |
| 4399 | // { v = x; ++x; } |
| 4400 | // { v = x; --x; } |
| 4401 | // { v = x; x binop= expr; } |
| 4402 | // { v = x; x = x binop expr; } |
| 4403 | // { v = x; x = expr binop x; } |
| 4404 | // { x++; v = x; } |
| 4405 | // { x--; v = x; } |
| 4406 | // { ++x; v = x; } |
| 4407 | // { --x; v = x; } |
| 4408 | // { x binop= expr; v = x; } |
| 4409 | // { x = x binop expr; v = x; } |
| 4410 | // { x = expr binop x; v = x; } |
| 4411 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 4412 | // Check that this is { expr1; expr2; } |
| 4413 | if (CS->size() == 2) { |
| 4414 | auto *First = CS->body_front(); |
| 4415 | auto *Second = CS->body_back(); |
| 4416 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 4417 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4418 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 4419 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4420 | // Need to find what subexpression is 'v' and what is 'x'. |
| 4421 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4422 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 4423 | BinaryOperator *BinOp = nullptr; |
| 4424 | if (IsUpdateExprFound) { |
| 4425 | BinOp = dyn_cast<BinaryOperator>(First); |
| 4426 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4427 | } |
| 4428 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4429 | // { v = x; x++; } |
| 4430 | // { v = x; x--; } |
| 4431 | // { v = x; ++x; } |
| 4432 | // { v = x; --x; } |
| 4433 | // { v = x; x binop= expr; } |
| 4434 | // { v = x; x = x binop expr; } |
| 4435 | // { v = x; x = expr binop x; } |
| 4436 | // Check that the first expression has form v = x. |
| 4437 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4438 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4439 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4440 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4441 | IsUpdateExprFound = XId == PossibleXId; |
| 4442 | if (IsUpdateExprFound) { |
| 4443 | V = BinOp->getLHS(); |
| 4444 | X = Checker.getX(); |
| 4445 | E = Checker.getExpr(); |
| 4446 | UE = Checker.getUpdateExpr(); |
| 4447 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4448 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | if (!IsUpdateExprFound) { |
| 4452 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 4453 | BinOp = nullptr; |
| 4454 | if (IsUpdateExprFound) { |
| 4455 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 4456 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4457 | } |
| 4458 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4459 | // { x++; v = x; } |
| 4460 | // { x--; v = x; } |
| 4461 | // { ++x; v = x; } |
| 4462 | // { --x; v = x; } |
| 4463 | // { x binop= expr; v = x; } |
| 4464 | // { x = x binop expr; v = x; } |
| 4465 | // { x = expr binop x; v = x; } |
| 4466 | // Check that the second expression has form v = x. |
| 4467 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4468 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4469 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4470 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4471 | IsUpdateExprFound = XId == PossibleXId; |
| 4472 | if (IsUpdateExprFound) { |
| 4473 | V = BinOp->getLHS(); |
| 4474 | X = Checker.getX(); |
| 4475 | E = Checker.getExpr(); |
| 4476 | UE = Checker.getUpdateExpr(); |
| 4477 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4478 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4479 | } |
| 4480 | } |
| 4481 | } |
| 4482 | if (!IsUpdateExprFound) { |
| 4483 | // { v = x; x = expr; } |
| 4484 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 4485 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
| 4486 | ErrorFound = NotAnAssignmentOp; |
| 4487 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 4488 | : First->getLocStart(); |
| 4489 | NoteRange = ErrorRange = FirstBinOp |
| 4490 | ? FirstBinOp->getSourceRange() |
| 4491 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4492 | } else { |
| 4493 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 4494 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 4495 | ErrorFound = NotAnAssignmentOp; |
| 4496 | NoteLoc = ErrorLoc = SecondBinOp ? SecondBinOp->getOperatorLoc() |
| 4497 | : Second->getLocStart(); |
| 4498 | NoteRange = ErrorRange = SecondBinOp |
| 4499 | ? SecondBinOp->getSourceRange() |
| 4500 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4501 | } else { |
| 4502 | auto *PossibleXRHSInFirst = |
| 4503 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4504 | auto *PossibleXLHSInSecond = |
| 4505 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4506 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 4507 | PossibleXRHSInFirst->Profile(X1Id, Context, /*Canonical=*/true); |
| 4508 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 4509 | /*Canonical=*/true); |
| 4510 | IsUpdateExprFound = X1Id == X2Id; |
| 4511 | if (IsUpdateExprFound) { |
| 4512 | V = FirstBinOp->getLHS(); |
| 4513 | X = SecondBinOp->getLHS(); |
| 4514 | E = SecondBinOp->getRHS(); |
| 4515 | UE = nullptr; |
| 4516 | IsXLHSInRHSPart = false; |
| 4517 | IsPostfixUpdate = true; |
| 4518 | } else { |
| 4519 | ErrorFound = NotASpecificExpression; |
| 4520 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 4521 | ErrorRange = FirstBinOp->getSourceRange(); |
| 4522 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 4523 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 4524 | } |
| 4525 | } |
| 4526 | } |
| 4527 | } |
| 4528 | } else { |
| 4529 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4530 | NoteRange = ErrorRange = |
| 4531 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4532 | ErrorFound = NotTwoSubstatements; |
| 4533 | } |
| 4534 | } else { |
| 4535 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4536 | NoteRange = ErrorRange = |
| 4537 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4538 | ErrorFound = NotACompoundStatement; |
| 4539 | } |
| 4540 | if (ErrorFound != NoError) { |
| 4541 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 4542 | << ErrorRange; |
| 4543 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4544 | return StmtError(); |
| 4545 | } else if (CurContext->isDependentContext()) { |
| 4546 | UE = V = E = X = nullptr; |
| 4547 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4548 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4549 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4550 | |
| 4551 | getCurFunction()->setHasBranchProtectedScope(); |
| 4552 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4553 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4554 | X, V, E, UE, IsXLHSInRHSPart, |
| 4555 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4556 | } |
| 4557 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4558 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 4559 | Stmt *AStmt, |
| 4560 | SourceLocation StartLoc, |
| 4561 | SourceLocation EndLoc) { |
| 4562 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4563 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4564 | // OpenMP [2.16, Nesting of Regions] |
| 4565 | // If specified, a teams construct must be contained within a target |
| 4566 | // construct. That target construct must contain no statements or directives |
| 4567 | // outside of the teams construct. |
| 4568 | if (DSAStack->hasInnerTeamsRegion()) { |
| 4569 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 4570 | bool OMPTeamsFound = true; |
| 4571 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 4572 | auto I = CS->body_begin(); |
| 4573 | while (I != CS->body_end()) { |
| 4574 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 4575 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 4576 | OMPTeamsFound = false; |
| 4577 | break; |
| 4578 | } |
| 4579 | ++I; |
| 4580 | } |
| 4581 | assert(I != CS->body_end() && "Not found statement"); |
| 4582 | S = *I; |
| 4583 | } |
| 4584 | if (!OMPTeamsFound) { |
| 4585 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 4586 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 4587 | diag::note_omp_nested_teams_construct_here); |
| 4588 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 4589 | << isa<OMPExecutableDirective>(S); |
| 4590 | return StmtError(); |
| 4591 | } |
| 4592 | } |
| 4593 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4594 | getCurFunction()->setHasBranchProtectedScope(); |
| 4595 | |
| 4596 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4597 | } |
| 4598 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4599 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 4600 | Stmt *AStmt, |
| 4601 | SourceLocation StartLoc, |
| 4602 | SourceLocation EndLoc) { |
| 4603 | getCurFunction()->setHasBranchProtectedScope(); |
| 4604 | |
| 4605 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 4606 | AStmt); |
| 4607 | } |
| 4608 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4609 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 4610 | Stmt *AStmt, SourceLocation StartLoc, |
| 4611 | SourceLocation EndLoc) { |
| 4612 | assert(AStmt && isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4613 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4614 | // 1.2.2 OpenMP Language Terminology |
| 4615 | // Structured block - An executable statement with a single entry at the |
| 4616 | // top and a single exit at the bottom. |
| 4617 | // The point of exit cannot be a branch out of the structured block. |
| 4618 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4619 | CS->getCapturedDecl()->setNothrow(); |
| 4620 | |
| 4621 | getCurFunction()->setHasBranchProtectedScope(); |
| 4622 | |
| 4623 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4624 | } |
| 4625 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4626 | StmtResult |
| 4627 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 4628 | SourceLocation EndLoc, |
| 4629 | OpenMPDirectiveKind CancelRegion) { |
| 4630 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4631 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4632 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4633 | << getOpenMPDirectiveName(CancelRegion); |
| 4634 | return StmtError(); |
| 4635 | } |
| 4636 | if (DSAStack->isParentNowaitRegion()) { |
| 4637 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 4638 | return StmtError(); |
| 4639 | } |
| 4640 | if (DSAStack->isParentOrderedRegion()) { |
| 4641 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 4642 | return StmtError(); |
| 4643 | } |
| 4644 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 4645 | CancelRegion); |
| 4646 | } |
| 4647 | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4648 | StmtResult Sema::ActOnOpenMPCancelDirective(SourceLocation StartLoc, |
| 4649 | SourceLocation EndLoc, |
| 4650 | OpenMPDirectiveKind CancelRegion) { |
| 4651 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4652 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4653 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4654 | << getOpenMPDirectiveName(CancelRegion); |
| 4655 | return StmtError(); |
| 4656 | } |
| 4657 | if (DSAStack->isParentNowaitRegion()) { |
| 4658 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 4659 | return StmtError(); |
| 4660 | } |
| 4661 | if (DSAStack->isParentOrderedRegion()) { |
| 4662 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 4663 | return StmtError(); |
| 4664 | } |
| 4665 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, CancelRegion); |
| 4666 | } |
| 4667 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4668 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4669 | SourceLocation StartLoc, |
| 4670 | SourceLocation LParenLoc, |
| 4671 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4672 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4673 | switch (Kind) { |
| 4674 | case OMPC_if: |
| 4675 | Res = ActOnOpenMPIfClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4676 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4677 | case OMPC_final: |
| 4678 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4679 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4680 | case OMPC_num_threads: |
| 4681 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4682 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4683 | case OMPC_safelen: |
| 4684 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4685 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4686 | case OMPC_collapse: |
| 4687 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4688 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4689 | case OMPC_ordered: |
| 4690 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 4691 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 4692 | case OMPC_device: |
| 4693 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4694 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4695 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4696 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4697 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4698 | case OMPC_private: |
| 4699 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4700 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4701 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4702 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4703 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4704 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4705 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4706 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4707 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4708 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4709 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4710 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4711 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4712 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4713 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4714 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4715 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4716 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4717 | case OMPC_depend: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4718 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4719 | llvm_unreachable("Clause is not allowed."); |
| 4720 | } |
| 4721 | return Res; |
| 4722 | } |
| 4723 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4724 | OMPClause *Sema::ActOnOpenMPIfClause(Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4725 | SourceLocation LParenLoc, |
| 4726 | SourceLocation EndLoc) { |
| 4727 | Expr *ValExpr = Condition; |
| 4728 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 4729 | !Condition->isInstantiationDependent() && |
| 4730 | !Condition->containsUnexpandedParameterPack()) { |
| 4731 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4732 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4733 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4734 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4735 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4736 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4737 | } |
| 4738 | |
| 4739 | return new (Context) OMPIfClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 4740 | } |
| 4741 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4742 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 4743 | SourceLocation StartLoc, |
| 4744 | SourceLocation LParenLoc, |
| 4745 | SourceLocation EndLoc) { |
| 4746 | Expr *ValExpr = Condition; |
| 4747 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 4748 | !Condition->isInstantiationDependent() && |
| 4749 | !Condition->containsUnexpandedParameterPack()) { |
| 4750 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 4751 | Condition->getExprLoc(), Condition); |
| 4752 | if (Val.isInvalid()) |
| 4753 | return nullptr; |
| 4754 | |
| 4755 | ValExpr = Val.get(); |
| 4756 | } |
| 4757 | |
| 4758 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 4759 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4760 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 4761 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4762 | if (!Op) |
| 4763 | return ExprError(); |
| 4764 | |
| 4765 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 4766 | public: |
| 4767 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4768 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 4769 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 4770 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4771 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 4772 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4773 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 4774 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4775 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 4776 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4777 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 4778 | QualType T, |
| 4779 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4780 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 4781 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4782 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 4783 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4784 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4785 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4786 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4787 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 4788 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4789 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 4790 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4791 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 4792 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4793 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4794 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4795 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4796 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 4797 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4798 | llvm_unreachable("conversion functions are permitted"); |
| 4799 | } |
| 4800 | } ConvertDiagnoser; |
| 4801 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 4802 | } |
| 4803 | |
| 4804 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 4805 | SourceLocation StartLoc, |
| 4806 | SourceLocation LParenLoc, |
| 4807 | SourceLocation EndLoc) { |
| 4808 | Expr *ValExpr = NumThreads; |
| 4809 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4810 | !NumThreads->containsUnexpandedParameterPack()) { |
| 4811 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 4812 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4813 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4814 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4815 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4816 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4817 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4818 | |
| 4819 | // OpenMP [2.5, Restrictions] |
| 4820 | // The num_threads expression must evaluate to a positive integer value. |
| 4821 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4822 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 4823 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4824 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 4825 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4826 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4827 | } |
| 4828 | } |
| 4829 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4830 | return new (Context) |
| 4831 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4834 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 4835 | OpenMPClauseKind CKind) { |
| 4836 | if (!E) |
| 4837 | return ExprError(); |
| 4838 | if (E->isValueDependent() || E->isTypeDependent() || |
| 4839 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 4840 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4841 | llvm::APSInt Result; |
| 4842 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 4843 | if (ICE.isInvalid()) |
| 4844 | return ExprError(); |
| 4845 | if (!Result.isStrictlyPositive()) { |
| 4846 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 4847 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 4848 | return ExprError(); |
| 4849 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 4850 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 4851 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 4852 | << E->getSourceRange(); |
| 4853 | return ExprError(); |
| 4854 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4855 | if (CKind == OMPC_collapse) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4856 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 4857 | Result.getExtValue()); |
| 4858 | } else if (CKind == OMPC_ordered) { |
| 4859 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 4860 | Result.getExtValue()); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4861 | } |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4862 | return ICE; |
| 4863 | } |
| 4864 | |
| 4865 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 4866 | SourceLocation LParenLoc, |
| 4867 | SourceLocation EndLoc) { |
| 4868 | // OpenMP [2.8.1, simd construct, Description] |
| 4869 | // The parameter of the safelen clause must be a constant |
| 4870 | // positive integer expression. |
| 4871 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 4872 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4873 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4874 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 4875 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4876 | } |
| 4877 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4878 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 4879 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4880 | SourceLocation LParenLoc, |
| 4881 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4882 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4883 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4884 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4885 | // The parameter of the collapse clause must be a constant |
| 4886 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4887 | ExprResult NumForLoopsResult = |
| 4888 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 4889 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4890 | return nullptr; |
| 4891 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 4892 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4893 | } |
| 4894 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4895 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 4896 | SourceLocation EndLoc, |
| 4897 | SourceLocation LParenLoc, |
| 4898 | Expr *NumForLoops) { |
| 4899 | DSAStack->setOrderedRegion(); |
| 4900 | // OpenMP [2.7.1, loop construct, Description] |
| 4901 | // OpenMP [2.8.1, simd construct, Description] |
| 4902 | // OpenMP [2.9.6, distribute construct, Description] |
| 4903 | // The parameter of the ordered clause must be a constant |
| 4904 | // positive integer expression if any. |
| 4905 | if (NumForLoops && LParenLoc.isValid()) { |
| 4906 | ExprResult NumForLoopsResult = |
| 4907 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 4908 | if (NumForLoopsResult.isInvalid()) |
| 4909 | return nullptr; |
| 4910 | NumForLoops = NumForLoopsResult.get(); |
| 4911 | } |
| 4912 | return new (Context) |
| 4913 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 4914 | } |
| 4915 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4916 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 4917 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 4918 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4919 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4920 | switch (Kind) { |
| 4921 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4922 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4923 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 4924 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4925 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4926 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4927 | Res = ActOnOpenMPProcBindClause( |
| 4928 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 4929 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4930 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4931 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4932 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4933 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4934 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4935 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4936 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4937 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 4938 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4939 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4940 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4941 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4942 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4943 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4944 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4945 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 4946 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4947 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4948 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4949 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4950 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4951 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4952 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4953 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4954 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4955 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4956 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4957 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 4958 | case OMPC_device: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4959 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4960 | llvm_unreachable("Clause is not allowed."); |
| 4961 | } |
| 4962 | return Res; |
| 4963 | } |
| 4964 | |
| 4965 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 4966 | SourceLocation KindKwLoc, |
| 4967 | SourceLocation StartLoc, |
| 4968 | SourceLocation LParenLoc, |
| 4969 | SourceLocation EndLoc) { |
| 4970 | if (Kind == OMPC_DEFAULT_unknown) { |
| 4971 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4972 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 4973 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 4974 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4975 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4976 | Values += "'"; |
| 4977 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 4978 | Values += "'"; |
| 4979 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4980 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4981 | Values += " or "; |
| 4982 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 4983 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4984 | break; |
| 4985 | default: |
| 4986 | Values += Sep; |
| 4987 | break; |
| 4988 | } |
| 4989 | } |
| 4990 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4991 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4992 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4993 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4994 | switch (Kind) { |
| 4995 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4996 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 4997 | break; |
| 4998 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4999 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5000 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5001 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5002 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5003 | break; |
| 5004 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5005 | return new (Context) |
| 5006 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5009 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5010 | SourceLocation KindKwLoc, |
| 5011 | SourceLocation StartLoc, |
| 5012 | SourceLocation LParenLoc, |
| 5013 | SourceLocation EndLoc) { |
| 5014 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5015 | std::string Values; |
| 5016 | std::string Sep(", "); |
| 5017 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 5018 | Values += "'"; |
| 5019 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 5020 | Values += "'"; |
| 5021 | switch (i) { |
| 5022 | case OMPC_PROC_BIND_unknown - 2: |
| 5023 | Values += " or "; |
| 5024 | break; |
| 5025 | case OMPC_PROC_BIND_unknown - 1: |
| 5026 | break; |
| 5027 | default: |
| 5028 | Values += Sep; |
| 5029 | break; |
| 5030 | } |
| 5031 | } |
| 5032 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5033 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5034 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5035 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5036 | return new (Context) |
| 5037 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5038 | } |
| 5039 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5040 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 5041 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 5042 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 5043 | SourceLocation ArgumentLoc, SourceLocation CommaLoc, |
| 5044 | SourceLocation EndLoc) { |
| 5045 | OMPClause *Res = nullptr; |
| 5046 | switch (Kind) { |
| 5047 | case OMPC_schedule: |
| 5048 | Res = ActOnOpenMPScheduleClause( |
| 5049 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
| 5050 | LParenLoc, ArgumentLoc, CommaLoc, EndLoc); |
| 5051 | break; |
| 5052 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5053 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5054 | case OMPC_num_threads: |
| 5055 | case OMPC_safelen: |
| 5056 | case OMPC_collapse: |
| 5057 | case OMPC_default: |
| 5058 | case OMPC_proc_bind: |
| 5059 | case OMPC_private: |
| 5060 | case OMPC_firstprivate: |
| 5061 | case OMPC_lastprivate: |
| 5062 | case OMPC_shared: |
| 5063 | case OMPC_reduction: |
| 5064 | case OMPC_linear: |
| 5065 | case OMPC_aligned: |
| 5066 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5067 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5068 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5069 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5070 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5071 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5072 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5073 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5074 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5075 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5076 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5077 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5078 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5079 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5080 | case OMPC_device: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5081 | case OMPC_unknown: |
| 5082 | llvm_unreachable("Clause is not allowed."); |
| 5083 | } |
| 5084 | return Res; |
| 5085 | } |
| 5086 | |
| 5087 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 5088 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 5089 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 5090 | SourceLocation EndLoc) { |
| 5091 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 5092 | std::string Values; |
| 5093 | std::string Sep(", "); |
| 5094 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 5095 | Values += "'"; |
| 5096 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 5097 | Values += "'"; |
| 5098 | switch (i) { |
| 5099 | case OMPC_SCHEDULE_unknown - 2: |
| 5100 | Values += " or "; |
| 5101 | break; |
| 5102 | case OMPC_SCHEDULE_unknown - 1: |
| 5103 | break; |
| 5104 | default: |
| 5105 | Values += Sep; |
| 5106 | break; |
| 5107 | } |
| 5108 | } |
| 5109 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 5110 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 5111 | return nullptr; |
| 5112 | } |
| 5113 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5114 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5115 | if (ChunkSize) { |
| 5116 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 5117 | !ChunkSize->isInstantiationDependent() && |
| 5118 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 5119 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 5120 | ExprResult Val = |
| 5121 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 5122 | if (Val.isInvalid()) |
| 5123 | return nullptr; |
| 5124 | |
| 5125 | ValExpr = Val.get(); |
| 5126 | |
| 5127 | // OpenMP [2.7.1, Restrictions] |
| 5128 | // chunk_size must be a loop invariant integer expression with a positive |
| 5129 | // value. |
| 5130 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5131 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 5132 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 5133 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 5134 | << "schedule" << ChunkSize->getSourceRange(); |
| 5135 | return nullptr; |
| 5136 | } |
| 5137 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 5138 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 5139 | ChunkSize->getType(), ".chunk."); |
| 5140 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 5141 | ChunkSize->getExprLoc(), |
| 5142 | /*RefersToCapture=*/true); |
| 5143 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5144 | } |
| 5145 | } |
| 5146 | } |
| 5147 | |
| 5148 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5149 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5150 | } |
| 5151 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5152 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 5153 | SourceLocation StartLoc, |
| 5154 | SourceLocation EndLoc) { |
| 5155 | OMPClause *Res = nullptr; |
| 5156 | switch (Kind) { |
| 5157 | case OMPC_ordered: |
| 5158 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 5159 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5160 | case OMPC_nowait: |
| 5161 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 5162 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5163 | case OMPC_untied: |
| 5164 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 5165 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5166 | case OMPC_mergeable: |
| 5167 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 5168 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5169 | case OMPC_read: |
| 5170 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 5171 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5172 | case OMPC_write: |
| 5173 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 5174 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5175 | case OMPC_update: |
| 5176 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 5177 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5178 | case OMPC_capture: |
| 5179 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 5180 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5181 | case OMPC_seq_cst: |
| 5182 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 5183 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5184 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5185 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5186 | case OMPC_num_threads: |
| 5187 | case OMPC_safelen: |
| 5188 | case OMPC_collapse: |
| 5189 | case OMPC_schedule: |
| 5190 | case OMPC_private: |
| 5191 | case OMPC_firstprivate: |
| 5192 | case OMPC_lastprivate: |
| 5193 | case OMPC_shared: |
| 5194 | case OMPC_reduction: |
| 5195 | case OMPC_linear: |
| 5196 | case OMPC_aligned: |
| 5197 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5198 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5199 | case OMPC_default: |
| 5200 | case OMPC_proc_bind: |
| 5201 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5202 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5203 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5204 | case OMPC_device: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5205 | case OMPC_unknown: |
| 5206 | llvm_unreachable("Clause is not allowed."); |
| 5207 | } |
| 5208 | return Res; |
| 5209 | } |
| 5210 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5211 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 5212 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5213 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5214 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 5215 | } |
| 5216 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5217 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 5218 | SourceLocation EndLoc) { |
| 5219 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 5220 | } |
| 5221 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5222 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 5223 | SourceLocation EndLoc) { |
| 5224 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 5225 | } |
| 5226 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5227 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 5228 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5229 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 5230 | } |
| 5231 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5232 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 5233 | SourceLocation EndLoc) { |
| 5234 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 5235 | } |
| 5236 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5237 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 5238 | SourceLocation EndLoc) { |
| 5239 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 5240 | } |
| 5241 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5242 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 5243 | SourceLocation EndLoc) { |
| 5244 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 5245 | } |
| 5246 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5247 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 5248 | SourceLocation EndLoc) { |
| 5249 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 5250 | } |
| 5251 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5252 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 5253 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 5254 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 5255 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5256 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5257 | OpenMPLinearClauseKind LinKind, SourceLocation DepLinLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5258 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5259 | switch (Kind) { |
| 5260 | case OMPC_private: |
| 5261 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5262 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5263 | case OMPC_firstprivate: |
| 5264 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5265 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5266 | case OMPC_lastprivate: |
| 5267 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5268 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5269 | case OMPC_shared: |
| 5270 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5271 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5272 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5273 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 5274 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5275 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5276 | case OMPC_linear: |
| 5277 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5278 | LinKind, DepLinLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5279 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5280 | case OMPC_aligned: |
| 5281 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 5282 | ColonLoc, EndLoc); |
| 5283 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5284 | case OMPC_copyin: |
| 5285 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5286 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5287 | case OMPC_copyprivate: |
| 5288 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5289 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5290 | case OMPC_flush: |
| 5291 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5292 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5293 | case OMPC_depend: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5294 | Res = ActOnOpenMPDependClause(DepKind, DepLinLoc, ColonLoc, VarList, StartLoc, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5295 | LParenLoc, EndLoc); |
| 5296 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5297 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5298 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5299 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5300 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5301 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5302 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5303 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5304 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5305 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5306 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5307 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5308 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5309 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5310 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5311 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5312 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5313 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5314 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5315 | case OMPC_device: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5316 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5317 | llvm_unreachable("Clause is not allowed."); |
| 5318 | } |
| 5319 | return Res; |
| 5320 | } |
| 5321 | |
| 5322 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 5323 | SourceLocation StartLoc, |
| 5324 | SourceLocation LParenLoc, |
| 5325 | SourceLocation EndLoc) { |
| 5326 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5327 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5328 | for (auto &RefExpr : VarList) { |
| 5329 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 5330 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5331 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5332 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5333 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5334 | continue; |
| 5335 | } |
| 5336 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5337 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5338 | // OpenMP [2.1, C/C++] |
| 5339 | // A list item is a variable name. |
| 5340 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5341 | // A variable that is part of another variable (as an array or |
| 5342 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5343 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5344 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5345 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5346 | continue; |
| 5347 | } |
| 5348 | Decl *D = DE->getDecl(); |
| 5349 | VarDecl *VD = cast<VarDecl>(D); |
| 5350 | |
| 5351 | QualType Type = VD->getType(); |
| 5352 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5353 | // It will be analyzed later. |
| 5354 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5355 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5356 | continue; |
| 5357 | } |
| 5358 | |
| 5359 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5360 | // A variable that appears in a private clause must not have an incomplete |
| 5361 | // type or a reference type. |
| 5362 | if (RequireCompleteType(ELoc, Type, |
| 5363 | diag::err_omp_private_incomplete_type)) { |
| 5364 | continue; |
| 5365 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5366 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5367 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5368 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5369 | // in a Construct] |
| 5370 | // Variables with the predetermined data-sharing attributes may not be |
| 5371 | // listed in data-sharing attributes clauses, except for the cases |
| 5372 | // listed below. For these exceptions only, listing a predetermined |
| 5373 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5374 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5375 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5376 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5377 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5378 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5379 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5380 | continue; |
| 5381 | } |
| 5382 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5383 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5384 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5385 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5386 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5387 | << getOpenMPClauseName(OMPC_private) << Type |
| 5388 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5389 | bool IsDecl = |
| 5390 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5391 | Diag(VD->getLocation(), |
| 5392 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5393 | << VD; |
| 5394 | continue; |
| 5395 | } |
| 5396 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5397 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 5398 | // A variable of class type (or array thereof) that appears in a private |
| 5399 | // clause requires an accessible, unambiguous default constructor for the |
| 5400 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5401 | // Generate helper private variable and initialize it with the default |
| 5402 | // value. The address of the original variable is replaced by the address of |
| 5403 | // the new private variable in CodeGen. This new variable is not added to |
| 5404 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 5405 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5406 | Type = Type.getUnqualifiedType(); |
| 5407 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName()); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5408 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5409 | if (VDPrivate->isInvalidDecl()) |
| 5410 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5411 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5412 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5413 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5414 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5415 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5416 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5417 | } |
| 5418 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5419 | if (Vars.empty()) |
| 5420 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5421 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5422 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 5423 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5424 | } |
| 5425 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5426 | namespace { |
| 5427 | class DiagsUninitializedSeveretyRAII { |
| 5428 | private: |
| 5429 | DiagnosticsEngine &Diags; |
| 5430 | SourceLocation SavedLoc; |
| 5431 | bool IsIgnored; |
| 5432 | |
| 5433 | public: |
| 5434 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 5435 | bool IsIgnored) |
| 5436 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 5437 | if (!IsIgnored) { |
| 5438 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 5439 | /*Map*/ diag::Severity::Ignored, Loc); |
| 5440 | } |
| 5441 | } |
| 5442 | ~DiagsUninitializedSeveretyRAII() { |
| 5443 | if (!IsIgnored) |
| 5444 | Diags.popMappings(SavedLoc); |
| 5445 | } |
| 5446 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 5447 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5448 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5449 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 5450 | SourceLocation StartLoc, |
| 5451 | SourceLocation LParenLoc, |
| 5452 | SourceLocation EndLoc) { |
| 5453 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5454 | SmallVector<Expr *, 8> PrivateCopies; |
| 5455 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5456 | bool IsImplicitClause = |
| 5457 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 5458 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 5459 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5460 | for (auto &RefExpr : VarList) { |
| 5461 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 5462 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5463 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5464 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5465 | PrivateCopies.push_back(nullptr); |
| 5466 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5467 | continue; |
| 5468 | } |
| 5469 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5470 | SourceLocation ELoc = |
| 5471 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5472 | // OpenMP [2.1, C/C++] |
| 5473 | // A list item is a variable name. |
| 5474 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5475 | // A variable that is part of another variable (as an array or |
| 5476 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5477 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5478 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5479 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5480 | continue; |
| 5481 | } |
| 5482 | Decl *D = DE->getDecl(); |
| 5483 | VarDecl *VD = cast<VarDecl>(D); |
| 5484 | |
| 5485 | QualType Type = VD->getType(); |
| 5486 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5487 | // It will be analyzed later. |
| 5488 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5489 | PrivateCopies.push_back(nullptr); |
| 5490 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5491 | continue; |
| 5492 | } |
| 5493 | |
| 5494 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5495 | // A variable that appears in a private clause must not have an incomplete |
| 5496 | // type or a reference type. |
| 5497 | if (RequireCompleteType(ELoc, Type, |
| 5498 | diag::err_omp_firstprivate_incomplete_type)) { |
| 5499 | continue; |
| 5500 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5501 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5502 | |
| 5503 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 5504 | // 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] | 5505 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5506 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5507 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5508 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5509 | // If an implicit firstprivate variable found it was checked already. |
| 5510 | if (!IsImplicitClause) { |
| 5511 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5512 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5513 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 5514 | // A list item that specifies a given variable may not appear in more |
| 5515 | // than one clause on the same directive, except that a variable may be |
| 5516 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5517 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5518 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5519 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5520 | << getOpenMPClauseName(DVar.CKind) |
| 5521 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5522 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5523 | continue; |
| 5524 | } |
| 5525 | |
| 5526 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5527 | // in a Construct] |
| 5528 | // Variables with the predetermined data-sharing attributes may not be |
| 5529 | // listed in data-sharing attributes clauses, except for the cases |
| 5530 | // listed below. For these exceptions only, listing a predetermined |
| 5531 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5532 | // the variable's predetermined data-sharing attributes. |
| 5533 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5534 | // in a Construct, C/C++, p.2] |
| 5535 | // Variables with const-qualified type having no mutable member may be |
| 5536 | // listed in a firstprivate clause, even if they are static data members. |
| 5537 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 5538 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 5539 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5540 | << getOpenMPClauseName(DVar.CKind) |
| 5541 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5542 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5543 | continue; |
| 5544 | } |
| 5545 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5546 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5547 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 5548 | // A list item that is private within a parallel region must not appear |
| 5549 | // in a firstprivate clause on a worksharing construct if any of the |
| 5550 | // worksharing regions arising from the worksharing construct ever bind |
| 5551 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5552 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5553 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5554 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 5555 | if (DVar.CKind != OMPC_shared && |
| 5556 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5557 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5558 | Diag(ELoc, diag::err_omp_required_access) |
| 5559 | << getOpenMPClauseName(OMPC_firstprivate) |
| 5560 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5561 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5562 | continue; |
| 5563 | } |
| 5564 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5565 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 5566 | // A list item that appears in a reduction clause of a parallel construct |
| 5567 | // must not appear in a firstprivate clause on a worksharing or task |
| 5568 | // construct if any of the worksharing or task regions arising from the |
| 5569 | // worksharing or task construct ever bind to any of the parallel regions |
| 5570 | // arising from the parallel construct. |
| 5571 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 5572 | // A list item that appears in a reduction clause in worksharing |
| 5573 | // construct must not appear in a firstprivate clause in a task construct |
| 5574 | // encountered during execution of any of the worksharing regions arising |
| 5575 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5576 | if (CurrDir == OMPD_task) { |
| 5577 | DVar = |
| 5578 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 5579 | [](OpenMPDirectiveKind K) -> bool { |
| 5580 | return isOpenMPParallelDirective(K) || |
| 5581 | isOpenMPWorksharingDirective(K); |
| 5582 | }, |
| 5583 | false); |
| 5584 | if (DVar.CKind == OMPC_reduction && |
| 5585 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5586 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 5587 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 5588 | << getOpenMPDirectiveName(DVar.DKind); |
| 5589 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 5590 | continue; |
| 5591 | } |
| 5592 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5593 | } |
| 5594 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5595 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5596 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5597 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5598 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5599 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 5600 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5601 | bool IsDecl = |
| 5602 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5603 | Diag(VD->getLocation(), |
| 5604 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5605 | << VD; |
| 5606 | continue; |
| 5607 | } |
| 5608 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5609 | Type = Type.getUnqualifiedType(); |
| 5610 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName()); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5611 | // Generate helper private variable and initialize it with the value of the |
| 5612 | // original variable. The address of the original variable is replaced by |
| 5613 | // the address of the new private variable in the CodeGen. This new variable |
| 5614 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 5615 | // original variable for proper diagnostics and variable capturing. |
| 5616 | Expr *VDInitRefExpr = nullptr; |
| 5617 | // For arrays generate initializer for single element and replace it by the |
| 5618 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5619 | if (Type->isArrayType()) { |
| 5620 | auto VDInit = |
| 5621 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 5622 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5623 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5624 | ElemType = ElemType.getUnqualifiedType(); |
| 5625 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 5626 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5627 | InitializedEntity Entity = |
| 5628 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5629 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 5630 | |
| 5631 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 5632 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 5633 | if (Result.isInvalid()) |
| 5634 | VDPrivate->setInvalidDecl(); |
| 5635 | else |
| 5636 | VDPrivate->setInit(Result.getAs<Expr>()); |
| 5637 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5638 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5639 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5640 | VDInitRefExpr = |
| 5641 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5642 | AddInitializerToDecl(VDPrivate, |
| 5643 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 5644 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5645 | } |
| 5646 | if (VDPrivate->isInvalidDecl()) { |
| 5647 | if (IsImplicitClause) { |
| 5648 | Diag(DE->getExprLoc(), |
| 5649 | diag::note_omp_task_predetermined_firstprivate_here); |
| 5650 | } |
| 5651 | continue; |
| 5652 | } |
| 5653 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5654 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5655 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5656 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 5657 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5658 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 5659 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5662 | if (Vars.empty()) |
| 5663 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5664 | |
| 5665 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5666 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5667 | } |
| 5668 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5669 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 5670 | SourceLocation StartLoc, |
| 5671 | SourceLocation LParenLoc, |
| 5672 | SourceLocation EndLoc) { |
| 5673 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5674 | SmallVector<Expr *, 8> SrcExprs; |
| 5675 | SmallVector<Expr *, 8> DstExprs; |
| 5676 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5677 | for (auto &RefExpr : VarList) { |
| 5678 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 5679 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5680 | // It will be analyzed later. |
| 5681 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5682 | SrcExprs.push_back(nullptr); |
| 5683 | DstExprs.push_back(nullptr); |
| 5684 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5685 | continue; |
| 5686 | } |
| 5687 | |
| 5688 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 5689 | // OpenMP [2.1, C/C++] |
| 5690 | // A list item is a variable name. |
| 5691 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 5692 | // A variable that is part of another variable (as an array or structure |
| 5693 | // element) cannot appear in a lastprivate clause. |
| 5694 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 5695 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5696 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 5697 | continue; |
| 5698 | } |
| 5699 | Decl *D = DE->getDecl(); |
| 5700 | VarDecl *VD = cast<VarDecl>(D); |
| 5701 | |
| 5702 | QualType Type = VD->getType(); |
| 5703 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5704 | // It will be analyzed later. |
| 5705 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5706 | SrcExprs.push_back(nullptr); |
| 5707 | DstExprs.push_back(nullptr); |
| 5708 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5709 | continue; |
| 5710 | } |
| 5711 | |
| 5712 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 5713 | // A variable that appears in a lastprivate clause must not have an |
| 5714 | // incomplete type or a reference type. |
| 5715 | if (RequireCompleteType(ELoc, Type, |
| 5716 | diag::err_omp_lastprivate_incomplete_type)) { |
| 5717 | continue; |
| 5718 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5719 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5720 | |
| 5721 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5722 | // in a Construct] |
| 5723 | // Variables with the predetermined data-sharing attributes may not be |
| 5724 | // listed in data-sharing attributes clauses, except for the cases |
| 5725 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5726 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5727 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 5728 | DVar.CKind != OMPC_firstprivate && |
| 5729 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 5730 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 5731 | << getOpenMPClauseName(DVar.CKind) |
| 5732 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5733 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5734 | continue; |
| 5735 | } |
| 5736 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5737 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 5738 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 5739 | // A list item that is private within a parallel region, or that appears in |
| 5740 | // the reduction clause of a parallel construct, must not appear in a |
| 5741 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 5742 | // worksharing regions ever binds to any of the corresponding parallel |
| 5743 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5744 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5745 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5746 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5747 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5748 | if (DVar.CKind != OMPC_shared) { |
| 5749 | Diag(ELoc, diag::err_omp_required_access) |
| 5750 | << getOpenMPClauseName(OMPC_lastprivate) |
| 5751 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5752 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5753 | continue; |
| 5754 | } |
| 5755 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5756 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5757 | // A variable of class type (or array thereof) that appears in a |
| 5758 | // lastprivate clause requires an accessible, unambiguous default |
| 5759 | // constructor for the class type, unless the list item is also specified |
| 5760 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5761 | // A variable of class type (or array thereof) that appears in a |
| 5762 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 5763 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5764 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5765 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5766 | Type.getUnqualifiedType(), ".lastprivate.src"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5767 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 5768 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5769 | auto *DstVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5770 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst"); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5771 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5772 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5773 | // For arrays generate assignment operation for single element and replace |
| 5774 | // it by the original array element in CodeGen. |
| 5775 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 5776 | PseudoDstExpr, PseudoSrcExpr); |
| 5777 | if (AssignmentOp.isInvalid()) |
| 5778 | continue; |
| 5779 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 5780 | /*DiscardedValue=*/true); |
| 5781 | if (AssignmentOp.isInvalid()) |
| 5782 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5783 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5784 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5785 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5786 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5787 | SrcExprs.push_back(PseudoSrcExpr); |
| 5788 | DstExprs.push_back(PseudoDstExpr); |
| 5789 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | if (Vars.empty()) |
| 5793 | return nullptr; |
| 5794 | |
| 5795 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5796 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5797 | } |
| 5798 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5799 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 5800 | SourceLocation StartLoc, |
| 5801 | SourceLocation LParenLoc, |
| 5802 | SourceLocation EndLoc) { |
| 5803 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5804 | for (auto &RefExpr : VarList) { |
| 5805 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 5806 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5807 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5808 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5809 | continue; |
| 5810 | } |
| 5811 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5812 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5813 | // OpenMP [2.1, C/C++] |
| 5814 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 5815 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 5816 | // A variable that is part of another variable (as an array or structure |
| 5817 | // element) cannot appear in a shared unless it is a static data member |
| 5818 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5819 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5820 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5821 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5822 | continue; |
| 5823 | } |
| 5824 | Decl *D = DE->getDecl(); |
| 5825 | VarDecl *VD = cast<VarDecl>(D); |
| 5826 | |
| 5827 | QualType Type = VD->getType(); |
| 5828 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5829 | // It will be analyzed later. |
| 5830 | Vars.push_back(DE); |
| 5831 | continue; |
| 5832 | } |
| 5833 | |
| 5834 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5835 | // in a Construct] |
| 5836 | // Variables with the predetermined data-sharing attributes may not be |
| 5837 | // listed in data-sharing attributes clauses, except for the cases |
| 5838 | // listed below. For these exceptions only, listing a predetermined |
| 5839 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5840 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5841 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5842 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 5843 | DVar.RefExpr) { |
| 5844 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5845 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5846 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5847 | continue; |
| 5848 | } |
| 5849 | |
| 5850 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 5851 | Vars.push_back(DE); |
| 5852 | } |
| 5853 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5854 | if (Vars.empty()) |
| 5855 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5856 | |
| 5857 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 5858 | } |
| 5859 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5860 | namespace { |
| 5861 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 5862 | DSAStackTy *Stack; |
| 5863 | |
| 5864 | public: |
| 5865 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 5866 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5867 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5868 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 5869 | return false; |
| 5870 | if (DVar.CKind != OMPC_unknown) |
| 5871 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5872 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5873 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5874 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5875 | return true; |
| 5876 | return false; |
| 5877 | } |
| 5878 | return false; |
| 5879 | } |
| 5880 | bool VisitStmt(Stmt *S) { |
| 5881 | for (auto Child : S->children()) { |
| 5882 | if (Child && Visit(Child)) |
| 5883 | return true; |
| 5884 | } |
| 5885 | return false; |
| 5886 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5887 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5888 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5889 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5890 | |
| 5891 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 5892 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 5893 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 5894 | CXXScopeSpec &ReductionIdScopeSpec, |
| 5895 | const DeclarationNameInfo &ReductionId) { |
| 5896 | // TODO: Allow scope specification search when 'declare reduction' is |
| 5897 | // supported. |
| 5898 | assert(ReductionIdScopeSpec.isEmpty() && |
| 5899 | "No support for scoped reduction identifiers yet."); |
| 5900 | |
| 5901 | auto DN = ReductionId.getName(); |
| 5902 | auto OOK = DN.getCXXOverloadedOperator(); |
| 5903 | BinaryOperatorKind BOK = BO_Comma; |
| 5904 | |
| 5905 | // OpenMP [2.14.3.6, reduction clause] |
| 5906 | // C |
| 5907 | // reduction-identifier is either an identifier or one of the following |
| 5908 | // operators: +, -, *, &, |, ^, && and || |
| 5909 | // C++ |
| 5910 | // reduction-identifier is either an id-expression or one of the following |
| 5911 | // operators: +, -, *, &, |, ^, && and || |
| 5912 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 5913 | switch (OOK) { |
| 5914 | case OO_Plus: |
| 5915 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5916 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5917 | break; |
| 5918 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5919 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5920 | break; |
| 5921 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5922 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5923 | break; |
| 5924 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5925 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5926 | break; |
| 5927 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5928 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5929 | break; |
| 5930 | case OO_AmpAmp: |
| 5931 | BOK = BO_LAnd; |
| 5932 | break; |
| 5933 | case OO_PipePipe: |
| 5934 | BOK = BO_LOr; |
| 5935 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5936 | case OO_New: |
| 5937 | case OO_Delete: |
| 5938 | case OO_Array_New: |
| 5939 | case OO_Array_Delete: |
| 5940 | case OO_Slash: |
| 5941 | case OO_Percent: |
| 5942 | case OO_Tilde: |
| 5943 | case OO_Exclaim: |
| 5944 | case OO_Equal: |
| 5945 | case OO_Less: |
| 5946 | case OO_Greater: |
| 5947 | case OO_LessEqual: |
| 5948 | case OO_GreaterEqual: |
| 5949 | case OO_PlusEqual: |
| 5950 | case OO_MinusEqual: |
| 5951 | case OO_StarEqual: |
| 5952 | case OO_SlashEqual: |
| 5953 | case OO_PercentEqual: |
| 5954 | case OO_CaretEqual: |
| 5955 | case OO_AmpEqual: |
| 5956 | case OO_PipeEqual: |
| 5957 | case OO_LessLess: |
| 5958 | case OO_GreaterGreater: |
| 5959 | case OO_LessLessEqual: |
| 5960 | case OO_GreaterGreaterEqual: |
| 5961 | case OO_EqualEqual: |
| 5962 | case OO_ExclaimEqual: |
| 5963 | case OO_PlusPlus: |
| 5964 | case OO_MinusMinus: |
| 5965 | case OO_Comma: |
| 5966 | case OO_ArrowStar: |
| 5967 | case OO_Arrow: |
| 5968 | case OO_Call: |
| 5969 | case OO_Subscript: |
| 5970 | case OO_Conditional: |
| 5971 | case NUM_OVERLOADED_OPERATORS: |
| 5972 | llvm_unreachable("Unexpected reduction identifier"); |
| 5973 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5974 | if (auto II = DN.getAsIdentifierInfo()) { |
| 5975 | if (II->isStr("max")) |
| 5976 | BOK = BO_GT; |
| 5977 | else if (II->isStr("min")) |
| 5978 | BOK = BO_LT; |
| 5979 | } |
| 5980 | break; |
| 5981 | } |
| 5982 | SourceRange ReductionIdRange; |
| 5983 | if (ReductionIdScopeSpec.isValid()) { |
| 5984 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 5985 | } |
| 5986 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 5987 | if (BOK == BO_Comma) { |
| 5988 | // Not allowed reduction identifier is found. |
| 5989 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 5990 | << ReductionIdRange; |
| 5991 | return nullptr; |
| 5992 | } |
| 5993 | |
| 5994 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 5995 | SmallVector<Expr *, 8> LHSs; |
| 5996 | SmallVector<Expr *, 8> RHSs; |
| 5997 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5998 | for (auto RefExpr : VarList) { |
| 5999 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 6000 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6001 | // It will be analyzed later. |
| 6002 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6003 | LHSs.push_back(nullptr); |
| 6004 | RHSs.push_back(nullptr); |
| 6005 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6006 | continue; |
| 6007 | } |
| 6008 | |
| 6009 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6010 | RefExpr->isInstantiationDependent() || |
| 6011 | RefExpr->containsUnexpandedParameterPack()) { |
| 6012 | // It will be analyzed later. |
| 6013 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6014 | LHSs.push_back(nullptr); |
| 6015 | RHSs.push_back(nullptr); |
| 6016 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6017 | continue; |
| 6018 | } |
| 6019 | |
| 6020 | auto ELoc = RefExpr->getExprLoc(); |
| 6021 | auto ERange = RefExpr->getSourceRange(); |
| 6022 | // OpenMP [2.1, C/C++] |
| 6023 | // A list item is a variable or array section, subject to the restrictions |
| 6024 | // specified in Section 2.4 on page 42 and in each of the sections |
| 6025 | // describing clauses and directives for which a list appears. |
| 6026 | // OpenMP [2.14.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. |
| 6029 | auto DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6030 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6031 | Diag(ELoc, diag::err_omp_expected_var_name) << ERange; |
| 6032 | continue; |
| 6033 | } |
| 6034 | auto D = DE->getDecl(); |
| 6035 | auto VD = cast<VarDecl>(D); |
| 6036 | auto Type = VD->getType(); |
| 6037 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6038 | // A variable that appears in a private clause must not have an incomplete |
| 6039 | // type or a reference type. |
| 6040 | if (RequireCompleteType(ELoc, Type, |
| 6041 | diag::err_omp_reduction_incomplete_type)) |
| 6042 | continue; |
| 6043 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6044 | // Arrays may not appear in a reduction clause. |
| 6045 | if (Type.getNonReferenceType()->isArrayType()) { |
| 6046 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
| 6047 | bool IsDecl = |
| 6048 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6049 | Diag(VD->getLocation(), |
| 6050 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6051 | << VD; |
| 6052 | continue; |
| 6053 | } |
| 6054 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6055 | // A list item that appears in a reduction clause must not be |
| 6056 | // const-qualified. |
| 6057 | if (Type.getNonReferenceType().isConstant(Context)) { |
| 6058 | Diag(ELoc, diag::err_omp_const_variable) |
| 6059 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
| 6060 | bool IsDecl = |
| 6061 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6062 | Diag(VD->getLocation(), |
| 6063 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6064 | << VD; |
| 6065 | continue; |
| 6066 | } |
| 6067 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 6068 | // If a list-item is a reference type then it must bind to the same object |
| 6069 | // for all threads of the team. |
| 6070 | VarDecl *VDDef = VD->getDefinition(); |
| 6071 | if (Type->isReferenceType() && VDDef) { |
| 6072 | DSARefChecker Check(DSAStack); |
| 6073 | if (Check.Visit(VDDef->getInit())) { |
| 6074 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 6075 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 6076 | continue; |
| 6077 | } |
| 6078 | } |
| 6079 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6080 | // The type of a list item that appears in a reduction clause must be valid |
| 6081 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 6082 | // of the list item must be an allowed arithmetic data type: char, int, |
| 6083 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 6084 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 6085 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 6086 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 6087 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 6088 | !(Type->isScalarType() || |
| 6089 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 6090 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 6091 | << getLangOpts().CPlusPlus; |
| 6092 | bool IsDecl = |
| 6093 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6094 | Diag(VD->getLocation(), |
| 6095 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6096 | << VD; |
| 6097 | continue; |
| 6098 | } |
| 6099 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 6100 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 6101 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 6102 | bool IsDecl = |
| 6103 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6104 | Diag(VD->getLocation(), |
| 6105 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6106 | << VD; |
| 6107 | continue; |
| 6108 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6109 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6110 | // in a Construct] |
| 6111 | // Variables with the predetermined data-sharing attributes may not be |
| 6112 | // listed in data-sharing attributes clauses, except for the cases |
| 6113 | // listed below. For these exceptions only, listing a predetermined |
| 6114 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6115 | // the variable's predetermined data-sharing attributes. |
| 6116 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 6117 | // Any number of reduction clauses can be specified on the directive, |
| 6118 | // but a list item can appear only once in the reduction clauses for that |
| 6119 | // directive. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6120 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6121 | if (DVar.CKind == OMPC_reduction) { |
| 6122 | Diag(ELoc, diag::err_omp_once_referenced) |
| 6123 | << getOpenMPClauseName(OMPC_reduction); |
| 6124 | if (DVar.RefExpr) { |
| 6125 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 6126 | } |
| 6127 | } else if (DVar.CKind != OMPC_unknown) { |
| 6128 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6129 | << getOpenMPClauseName(DVar.CKind) |
| 6130 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6131 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6132 | continue; |
| 6133 | } |
| 6134 | |
| 6135 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 6136 | // A list item that appears in a reduction clause of a worksharing |
| 6137 | // construct must be shared in the parallel regions to which any of the |
| 6138 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6139 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6140 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6141 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6142 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6143 | if (DVar.CKind != OMPC_shared) { |
| 6144 | Diag(ELoc, diag::err_omp_required_access) |
| 6145 | << getOpenMPClauseName(OMPC_reduction) |
| 6146 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6147 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6148 | continue; |
| 6149 | } |
| 6150 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6151 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6152 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs"); |
| 6153 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6154 | // Add initializer for private variable. |
| 6155 | Expr *Init = nullptr; |
| 6156 | switch (BOK) { |
| 6157 | case BO_Add: |
| 6158 | case BO_Xor: |
| 6159 | case BO_Or: |
| 6160 | case BO_LOr: |
| 6161 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 6162 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6163 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6164 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6165 | break; |
| 6166 | case BO_Mul: |
| 6167 | case BO_LAnd: |
| 6168 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6169 | // '*' and '&&' reduction ops - initializer is '1'. |
| 6170 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 6171 | } |
| 6172 | break; |
| 6173 | case BO_And: { |
| 6174 | // '&' reduction op - initializer is '~0'. |
| 6175 | QualType OrigType = Type; |
| 6176 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 6177 | Type = ComplexTy->getElementType(); |
| 6178 | } |
| 6179 | if (Type->isRealFloatingType()) { |
| 6180 | llvm::APFloat InitValue = |
| 6181 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 6182 | /*isIEEE=*/true); |
| 6183 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6184 | Type, ELoc); |
| 6185 | } else if (Type->isScalarType()) { |
| 6186 | auto Size = Context.getTypeSize(Type); |
| 6187 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 6188 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 6189 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6190 | } |
| 6191 | if (Init && OrigType->isAnyComplexType()) { |
| 6192 | // Init = 0xFFFF + 0xFFFFi; |
| 6193 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 6194 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 6195 | } |
| 6196 | Type = OrigType; |
| 6197 | break; |
| 6198 | } |
| 6199 | case BO_LT: |
| 6200 | case BO_GT: { |
| 6201 | // 'min' reduction op - initializer is 'Largest representable number in |
| 6202 | // the reduction list item type'. |
| 6203 | // 'max' reduction op - initializer is 'Least representable number in |
| 6204 | // the reduction list item type'. |
| 6205 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 6206 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 6207 | auto Size = Context.getTypeSize(Type); |
| 6208 | QualType IntTy = |
| 6209 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 6210 | llvm::APInt InitValue = |
| 6211 | (BOK != BO_LT) |
| 6212 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 6213 | : llvm::APInt::getMinValue(Size) |
| 6214 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 6215 | : llvm::APInt::getMaxValue(Size); |
| 6216 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6217 | if (Type->isPointerType()) { |
| 6218 | // Cast to pointer type. |
| 6219 | auto CastExpr = BuildCStyleCastExpr( |
| 6220 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 6221 | SourceLocation(), Init); |
| 6222 | if (CastExpr.isInvalid()) |
| 6223 | continue; |
| 6224 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6225 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6226 | } else if (Type->isRealFloatingType()) { |
| 6227 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 6228 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 6229 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6230 | Type, ELoc); |
| 6231 | } |
| 6232 | break; |
| 6233 | } |
| 6234 | case BO_PtrMemD: |
| 6235 | case BO_PtrMemI: |
| 6236 | case BO_MulAssign: |
| 6237 | case BO_Div: |
| 6238 | case BO_Rem: |
| 6239 | case BO_Sub: |
| 6240 | case BO_Shl: |
| 6241 | case BO_Shr: |
| 6242 | case BO_LE: |
| 6243 | case BO_GE: |
| 6244 | case BO_EQ: |
| 6245 | case BO_NE: |
| 6246 | case BO_AndAssign: |
| 6247 | case BO_XorAssign: |
| 6248 | case BO_OrAssign: |
| 6249 | case BO_Assign: |
| 6250 | case BO_AddAssign: |
| 6251 | case BO_SubAssign: |
| 6252 | case BO_DivAssign: |
| 6253 | case BO_RemAssign: |
| 6254 | case BO_ShlAssign: |
| 6255 | case BO_ShrAssign: |
| 6256 | case BO_Comma: |
| 6257 | llvm_unreachable("Unexpected reduction operation"); |
| 6258 | } |
| 6259 | if (Init) { |
| 6260 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 6261 | /*TypeMayContainAuto=*/false); |
| 6262 | } else { |
| 6263 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
| 6264 | } |
| 6265 | if (!RHSVD->hasInit()) { |
| 6266 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 6267 | << ReductionIdRange; |
| 6268 | bool IsDecl = |
| 6269 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6270 | Diag(VD->getLocation(), |
| 6271 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6272 | << VD; |
| 6273 | continue; |
| 6274 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6275 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 6276 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6277 | ExprResult ReductionOp = |
| 6278 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 6279 | LHSDRE, RHSDRE); |
| 6280 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 6281 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6282 | ReductionOp = |
| 6283 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6284 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 6285 | } else { |
| 6286 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 6287 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 6288 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 6289 | ReductionOp = |
| 6290 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6291 | BO_Assign, LHSDRE, ConditionalOp); |
| 6292 | } |
| 6293 | if (ReductionOp.isUsable()) { |
| 6294 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6295 | } |
| 6296 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6297 | if (ReductionOp.isInvalid()) |
| 6298 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6299 | |
| 6300 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 6301 | Vars.push_back(DE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6302 | LHSs.push_back(LHSDRE); |
| 6303 | RHSs.push_back(RHSDRE); |
| 6304 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6305 | } |
| 6306 | |
| 6307 | if (Vars.empty()) |
| 6308 | return nullptr; |
| 6309 | |
| 6310 | return OMPReductionClause::Create( |
| 6311 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6312 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, LHSs, |
| 6313 | RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6314 | } |
| 6315 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6316 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 6317 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 6318 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 6319 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6320 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6321 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6322 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6323 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 6324 | LinKind == OMPC_LINEAR_unknown) { |
| 6325 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 6326 | LinKind = OMPC_LINEAR_val; |
| 6327 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6328 | for (auto &RefExpr : VarList) { |
| 6329 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 6330 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6331 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6332 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6333 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6334 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6335 | continue; |
| 6336 | } |
| 6337 | |
| 6338 | // OpenMP [2.14.3.7, linear clause] |
| 6339 | // A list item that appears in a linear clause is subject to the private |
| 6340 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 6341 | // noted. In addition, the value of the new list item on each iteration |
| 6342 | // of the associated loop(s) corresponds to the value of the original |
| 6343 | // list item before entering the construct plus the logical number of |
| 6344 | // the iteration times linear-step. |
| 6345 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6346 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6347 | // OpenMP [2.1, C/C++] |
| 6348 | // A list item is a variable name. |
| 6349 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6350 | // A variable that is part of another variable (as an array or |
| 6351 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6352 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6353 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6354 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6355 | continue; |
| 6356 | } |
| 6357 | |
| 6358 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6359 | |
| 6360 | // OpenMP [2.14.3.7, linear clause] |
| 6361 | // A list-item cannot appear in more than one linear clause. |
| 6362 | // A list-item that appears in a linear clause cannot appear in any |
| 6363 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6364 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6365 | if (DVar.RefExpr) { |
| 6366 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6367 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6368 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6369 | continue; |
| 6370 | } |
| 6371 | |
| 6372 | QualType QType = VD->getType(); |
| 6373 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 6374 | // It will be analyzed later. |
| 6375 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6376 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6377 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6378 | continue; |
| 6379 | } |
| 6380 | |
| 6381 | // A variable must not have an incomplete type or a reference type. |
| 6382 | if (RequireCompleteType(ELoc, QType, |
| 6383 | diag::err_omp_linear_incomplete_type)) { |
| 6384 | continue; |
| 6385 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame^] | 6386 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 6387 | !QType->isReferenceType()) { |
| 6388 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 6389 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 6390 | continue; |
| 6391 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6392 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6393 | |
| 6394 | // A list item must not be const-qualified. |
| 6395 | if (QType.isConstant(Context)) { |
| 6396 | Diag(ELoc, diag::err_omp_const_variable) |
| 6397 | << getOpenMPClauseName(OMPC_linear); |
| 6398 | bool IsDecl = |
| 6399 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6400 | Diag(VD->getLocation(), |
| 6401 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6402 | << VD; |
| 6403 | continue; |
| 6404 | } |
| 6405 | |
| 6406 | // A list item must be of integral or pointer type. |
| 6407 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 6408 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6409 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 6410 | !Ty->isPointerType())) { |
| 6411 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 6412 | bool IsDecl = |
| 6413 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6414 | Diag(VD->getLocation(), |
| 6415 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6416 | << VD; |
| 6417 | continue; |
| 6418 | } |
| 6419 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6420 | // Build private copy of original var. |
| 6421 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName()); |
| 6422 | auto *PrivateRef = buildDeclRefExpr( |
| 6423 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6424 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6425 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6426 | AddInitializerToDecl(Init, DefaultLvalueConversion(DE).get(), |
| 6427 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6428 | auto InitRef = buildDeclRefExpr( |
| 6429 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6430 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 6431 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6432 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6433 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6434 | } |
| 6435 | |
| 6436 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6437 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6438 | |
| 6439 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6440 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6441 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 6442 | !Step->isInstantiationDependent() && |
| 6443 | !Step->containsUnexpandedParameterPack()) { |
| 6444 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6445 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6446 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6447 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6448 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6449 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6450 | // Build var to save the step value. |
| 6451 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6452 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6453 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6454 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6455 | ExprResult CalcStep = |
| 6456 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
| 6457 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6458 | // Warn about zero linear step (it would be probably better specified as |
| 6459 | // making corresponding variables 'const'). |
| 6460 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6461 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 6462 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6463 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 6464 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6465 | if (!IsConstant && CalcStep.isUsable()) { |
| 6466 | // Calculate the step beforehand instead of doing this on each iteration. |
| 6467 | // (This is not used if the number of iterations may be kfold-ed). |
| 6468 | CalcStepExpr = CalcStep.get(); |
| 6469 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6470 | } |
| 6471 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6472 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 6473 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 6474 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 6478 | Expr *NumIterations, Sema &SemaRef, |
| 6479 | Scope *S) { |
| 6480 | // Walk the vars and build update/final expressions for the CodeGen. |
| 6481 | SmallVector<Expr *, 8> Updates; |
| 6482 | SmallVector<Expr *, 8> Finals; |
| 6483 | Expr *Step = Clause.getStep(); |
| 6484 | Expr *CalcStep = Clause.getCalcStep(); |
| 6485 | // OpenMP [2.14.3.7, linear clause] |
| 6486 | // If linear-step is not specified it is assumed to be 1. |
| 6487 | if (Step == nullptr) |
| 6488 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 6489 | else if (CalcStep) |
| 6490 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 6491 | bool HasErrors = false; |
| 6492 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6493 | auto CurPrivate = Clause.privates().begin(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6494 | for (auto &RefExpr : Clause.varlists()) { |
| 6495 | Expr *InitExpr = *CurInit; |
| 6496 | |
| 6497 | // Build privatized reference to the current linear var. |
| 6498 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6499 | auto CapturedRef = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6500 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 6501 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 6502 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6503 | |
| 6504 | // Build update: Var = InitExpr + IV * Step |
| 6505 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6506 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6507 | InitExpr, IV, Step, /* Subtract */ false); |
| 6508 | Update = SemaRef.ActOnFinishFullExpr(Update.get()); |
| 6509 | |
| 6510 | // Build final: Var = InitExpr + NumIterations * Step |
| 6511 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6512 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6513 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6514 | Final = SemaRef.ActOnFinishFullExpr(Final.get()); |
| 6515 | if (!Update.isUsable() || !Final.isUsable()) { |
| 6516 | Updates.push_back(nullptr); |
| 6517 | Finals.push_back(nullptr); |
| 6518 | HasErrors = true; |
| 6519 | } else { |
| 6520 | Updates.push_back(Update.get()); |
| 6521 | Finals.push_back(Final.get()); |
| 6522 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6523 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6524 | } |
| 6525 | Clause.setUpdates(Updates); |
| 6526 | Clause.setFinals(Finals); |
| 6527 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6528 | } |
| 6529 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6530 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 6531 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 6532 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 6533 | |
| 6534 | SmallVector<Expr *, 8> Vars; |
| 6535 | for (auto &RefExpr : VarList) { |
| 6536 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 6537 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6538 | // It will be analyzed later. |
| 6539 | Vars.push_back(RefExpr); |
| 6540 | continue; |
| 6541 | } |
| 6542 | |
| 6543 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6544 | // OpenMP [2.1, C/C++] |
| 6545 | // A list item is a variable name. |
| 6546 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6547 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6548 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6549 | continue; |
| 6550 | } |
| 6551 | |
| 6552 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6553 | |
| 6554 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6555 | // The type of list items appearing in the aligned clause must be |
| 6556 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6557 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6558 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6559 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6560 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 6561 | !Ty->isPointerType())) { |
| 6562 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 6563 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 6564 | bool IsDecl = |
| 6565 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6566 | Diag(VD->getLocation(), |
| 6567 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6568 | << VD; |
| 6569 | continue; |
| 6570 | } |
| 6571 | |
| 6572 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6573 | // A list-item cannot appear in more than one aligned clause. |
| 6574 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 6575 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 6576 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 6577 | << getOpenMPClauseName(OMPC_aligned); |
| 6578 | continue; |
| 6579 | } |
| 6580 | |
| 6581 | Vars.push_back(DE); |
| 6582 | } |
| 6583 | |
| 6584 | // OpenMP [2.8.1, simd construct, Description] |
| 6585 | // The parameter of the aligned clause, alignment, must be a constant |
| 6586 | // positive integer expression. |
| 6587 | // If no optional parameter is specified, implementation-defined default |
| 6588 | // alignments for SIMD instructions on the target platforms are assumed. |
| 6589 | if (Alignment != nullptr) { |
| 6590 | ExprResult AlignResult = |
| 6591 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 6592 | if (AlignResult.isInvalid()) |
| 6593 | return nullptr; |
| 6594 | Alignment = AlignResult.get(); |
| 6595 | } |
| 6596 | if (Vars.empty()) |
| 6597 | return nullptr; |
| 6598 | |
| 6599 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 6600 | EndLoc, Vars, Alignment); |
| 6601 | } |
| 6602 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6603 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 6604 | SourceLocation StartLoc, |
| 6605 | SourceLocation LParenLoc, |
| 6606 | SourceLocation EndLoc) { |
| 6607 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6608 | SmallVector<Expr *, 8> SrcExprs; |
| 6609 | SmallVector<Expr *, 8> DstExprs; |
| 6610 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6611 | for (auto &RefExpr : VarList) { |
| 6612 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 6613 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6614 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6615 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6616 | SrcExprs.push_back(nullptr); |
| 6617 | DstExprs.push_back(nullptr); |
| 6618 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6619 | continue; |
| 6620 | } |
| 6621 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6622 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6623 | // OpenMP [2.1, C/C++] |
| 6624 | // A list item is a variable name. |
| 6625 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6626 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6627 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6628 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6629 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6630 | continue; |
| 6631 | } |
| 6632 | |
| 6633 | Decl *D = DE->getDecl(); |
| 6634 | VarDecl *VD = cast<VarDecl>(D); |
| 6635 | |
| 6636 | QualType Type = VD->getType(); |
| 6637 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6638 | // It will be analyzed later. |
| 6639 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6640 | SrcExprs.push_back(nullptr); |
| 6641 | DstExprs.push_back(nullptr); |
| 6642 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6643 | continue; |
| 6644 | } |
| 6645 | |
| 6646 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 6647 | // A list item that appears in a copyin clause must be threadprivate. |
| 6648 | if (!DSAStack->isThreadPrivate(VD)) { |
| 6649 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6650 | << getOpenMPClauseName(OMPC_copyin) |
| 6651 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6652 | continue; |
| 6653 | } |
| 6654 | |
| 6655 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6656 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6657 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6658 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6659 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6660 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6661 | ElemType.getUnqualifiedType(), ".copyin.src"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6662 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6663 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 6664 | auto *DstVD = |
| 6665 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst"); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6666 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6667 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6668 | // For arrays generate assignment operation for single element and replace |
| 6669 | // it by the original array element in CodeGen. |
| 6670 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6671 | PseudoDstExpr, PseudoSrcExpr); |
| 6672 | if (AssignmentOp.isInvalid()) |
| 6673 | continue; |
| 6674 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6675 | /*DiscardedValue=*/true); |
| 6676 | if (AssignmentOp.isInvalid()) |
| 6677 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6678 | |
| 6679 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 6680 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6681 | SrcExprs.push_back(PseudoSrcExpr); |
| 6682 | DstExprs.push_back(PseudoDstExpr); |
| 6683 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6684 | } |
| 6685 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6686 | if (Vars.empty()) |
| 6687 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6688 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6689 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 6690 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6691 | } |
| 6692 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6693 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 6694 | SourceLocation StartLoc, |
| 6695 | SourceLocation LParenLoc, |
| 6696 | SourceLocation EndLoc) { |
| 6697 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6698 | SmallVector<Expr *, 8> SrcExprs; |
| 6699 | SmallVector<Expr *, 8> DstExprs; |
| 6700 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6701 | for (auto &RefExpr : VarList) { |
| 6702 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 6703 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6704 | // It will be analyzed later. |
| 6705 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6706 | SrcExprs.push_back(nullptr); |
| 6707 | DstExprs.push_back(nullptr); |
| 6708 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6709 | continue; |
| 6710 | } |
| 6711 | |
| 6712 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6713 | // OpenMP [2.1, C/C++] |
| 6714 | // A list item is a variable name. |
| 6715 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6716 | // A list item that appears in a copyin clause must be threadprivate. |
| 6717 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6718 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6719 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6720 | continue; |
| 6721 | } |
| 6722 | |
| 6723 | Decl *D = DE->getDecl(); |
| 6724 | VarDecl *VD = cast<VarDecl>(D); |
| 6725 | |
| 6726 | QualType Type = VD->getType(); |
| 6727 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6728 | // It will be analyzed later. |
| 6729 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6730 | SrcExprs.push_back(nullptr); |
| 6731 | DstExprs.push_back(nullptr); |
| 6732 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6733 | continue; |
| 6734 | } |
| 6735 | |
| 6736 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 6737 | // A list item that appears in a copyprivate clause may not appear in a |
| 6738 | // private or firstprivate clause on the single construct. |
| 6739 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6740 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6741 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 6742 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6743 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6744 | << getOpenMPClauseName(DVar.CKind) |
| 6745 | << getOpenMPClauseName(OMPC_copyprivate); |
| 6746 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6747 | continue; |
| 6748 | } |
| 6749 | |
| 6750 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 6751 | // All list items that appear in a copyprivate clause must be either |
| 6752 | // threadprivate or private in the enclosing context. |
| 6753 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6754 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6755 | if (DVar.CKind == OMPC_shared) { |
| 6756 | Diag(ELoc, diag::err_omp_required_access) |
| 6757 | << getOpenMPClauseName(OMPC_copyprivate) |
| 6758 | << "threadprivate or private in the enclosing context"; |
| 6759 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 6760 | continue; |
| 6761 | } |
| 6762 | } |
| 6763 | } |
| 6764 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6765 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 6766 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6767 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6768 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 6769 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 6770 | bool IsDecl = |
| 6771 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6772 | Diag(VD->getLocation(), |
| 6773 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6774 | << VD; |
| 6775 | continue; |
| 6776 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 6777 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6778 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6779 | // A variable of class type (or array thereof) that appears in a |
| 6780 | // copyin clause requires an accessible, unambiguous copy assignment |
| 6781 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6782 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 6783 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6784 | auto *SrcVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6785 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src"); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6786 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6787 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6788 | auto *DstVD = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6789 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst"); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 6790 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6791 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6792 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6793 | PseudoDstExpr, PseudoSrcExpr); |
| 6794 | if (AssignmentOp.isInvalid()) |
| 6795 | continue; |
| 6796 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6797 | /*DiscardedValue=*/true); |
| 6798 | if (AssignmentOp.isInvalid()) |
| 6799 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6800 | |
| 6801 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 6802 | // implicitly private. |
| 6803 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6804 | SrcExprs.push_back(PseudoSrcExpr); |
| 6805 | DstExprs.push_back(PseudoDstExpr); |
| 6806 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6807 | } |
| 6808 | |
| 6809 | if (Vars.empty()) |
| 6810 | return nullptr; |
| 6811 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 6812 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 6813 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6814 | } |
| 6815 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6816 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 6817 | SourceLocation StartLoc, |
| 6818 | SourceLocation LParenLoc, |
| 6819 | SourceLocation EndLoc) { |
| 6820 | if (VarList.empty()) |
| 6821 | return nullptr; |
| 6822 | |
| 6823 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 6824 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6825 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6826 | OMPClause * |
| 6827 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 6828 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 6829 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 6830 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 6831 | if (DepKind == OMPC_DEPEND_unknown) { |
| 6832 | std::string Values; |
| 6833 | std::string Sep(", "); |
| 6834 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 6835 | Values += "'"; |
| 6836 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 6837 | Values += "'"; |
| 6838 | switch (i) { |
| 6839 | case OMPC_DEPEND_unknown - 2: |
| 6840 | Values += " or "; |
| 6841 | break; |
| 6842 | case OMPC_DEPEND_unknown - 1: |
| 6843 | break; |
| 6844 | default: |
| 6845 | Values += Sep; |
| 6846 | break; |
| 6847 | } |
| 6848 | } |
| 6849 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 6850 | << Values << getOpenMPClauseName(OMPC_depend); |
| 6851 | return nullptr; |
| 6852 | } |
| 6853 | SmallVector<Expr *, 8> Vars; |
| 6854 | for (auto &RefExpr : VarList) { |
| 6855 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6856 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6857 | // It will be analyzed later. |
| 6858 | Vars.push_back(RefExpr); |
| 6859 | continue; |
| 6860 | } |
| 6861 | |
| 6862 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6863 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 6864 | // A variable that is part of another variable (such as a field of a |
| 6865 | // structure) but is not an array element or an array section cannot appear |
| 6866 | // in a depend clause. |
| 6867 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 6868 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 6869 | ArraySubscriptExpr *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 6870 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || (!ASE && !DE) || |
| 6871 | (DE && !isa<VarDecl>(DE->getDecl())) || |
| 6872 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 6873 | !ASE->getBase()->getType()->isArrayType())) { |
| 6874 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 6875 | << RefExpr->getSourceRange(); |
| 6876 | continue; |
| 6877 | } |
| 6878 | |
| 6879 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 6880 | } |
| 6881 | |
| 6882 | if (Vars.empty()) |
| 6883 | return nullptr; |
| 6884 | |
| 6885 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 6886 | DepLoc, ColonLoc, Vars); |
| 6887 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6888 | |
| 6889 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 6890 | SourceLocation LParenLoc, |
| 6891 | SourceLocation EndLoc) { |
| 6892 | Expr *ValExpr = Device; |
| 6893 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6894 | !ValExpr->isInstantiationDependent()) { |
| 6895 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6896 | ExprResult Value = PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6897 | if (Value.isInvalid()) |
| 6898 | return nullptr; |
| 6899 | |
| 6900 | // OpenMP [2.9.1, Restrictions] |
| 6901 | // The device expression must evaluate to a non-negative integer value. |
| 6902 | llvm::APSInt Result; |
| 6903 | if (Value.get()->isIntegerConstantExpr(Result, Context) && |
| 6904 | Result.isSigned() && !Result.isStrictlyPositive()) { |
| 6905 | Diag(Loc, diag::err_omp_negative_expression_in_clause) |
| 6906 | << "device" << ValExpr->getSourceRange(); |
| 6907 | return nullptr; |
| 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6912 | } |