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 | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 101 | bool CancelRegion; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 102 | unsigned CollapseNumber; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 103 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 104 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 105 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 106 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 107 | Directive(DKind), DirectiveName(std::move(Name)), CurScope(CurScope), |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 108 | ConstructLoc(Loc), OrderedRegion(false), NowaitRegion(false), |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 109 | CancelRegion(false), CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 110 | SharingMapTy() |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 111 | : SharingMap(), AlignedMap(), LCVSet(), DefaultAttr(DSA_unspecified), |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 112 | Directive(OMPD_unknown), DirectiveName(), CurScope(nullptr), |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 113 | ConstructLoc(), OrderedRegion(false), NowaitRegion(false), |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 114 | CancelRegion(false), CollapseNumber(1), InnerTeamsRegionLoc() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | typedef SmallVector<SharingMapTy, 64> StackTy; |
| 118 | |
| 119 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 120 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 121 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 122 | /// from current directive. |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 123 | OpenMPClauseKind ClauseKindMode; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 124 | Sema &SemaRef; |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 125 | bool ForceCapturing; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 126 | |
| 127 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 128 | |
| 129 | DSAVarData getDSA(StackTy::reverse_iterator Iter, VarDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 130 | |
| 131 | /// \brief Checks if the variable is a local for OpenMP region. |
| 132 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 133 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 134 | public: |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 135 | explicit DSAStackTy(Sema &S) |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 136 | : Stack(1), ClauseKindMode(OMPC_unknown), SemaRef(S), |
| 137 | ForceCapturing(false) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 138 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 139 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 140 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 141 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 142 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 143 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 144 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 145 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 146 | Scope *CurScope, SourceLocation Loc) { |
| 147 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 148 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void pop() { |
| 152 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 153 | Stack.pop_back(); |
| 154 | } |
| 155 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 156 | /// \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] | 157 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 158 | /// for diagnostics. |
| 159 | DeclRefExpr *addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE); |
| 160 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 161 | /// \brief Register specified variable as loop control variable. |
| 162 | void addLoopControlVariable(VarDecl *D); |
| 163 | /// \brief Check if the specified variable is a loop control variable for |
| 164 | /// current region. |
| 165 | bool isLoopControlVariable(VarDecl *D); |
| 166 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 167 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
| 168 | void addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A); |
| 169 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 170 | /// \brief Returns data sharing attributes from top of the stack for the |
| 171 | /// specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 172 | DSAVarData getTopDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 173 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 174 | DSAVarData getImplicitDSA(VarDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 175 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 176 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 177 | /// predicate. |
| 178 | template <class ClausesPredicate, class DirectivesPredicate> |
| 179 | DSAVarData hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 180 | DirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 181 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 182 | /// match specified \a CPred predicate in any innermost directive which |
| 183 | /// matches \a DPred predicate. |
| 184 | template <class ClausesPredicate, class DirectivesPredicate> |
| 185 | DSAVarData hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 186 | DirectivesPredicate DPred, |
| 187 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 188 | /// \brief Checks if the specified variables has explicit data-sharing |
| 189 | /// attributes which match specified \a CPred predicate at the specified |
| 190 | /// OpenMP region. |
| 191 | bool hasExplicitDSA(VarDecl *D, |
| 192 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 193 | unsigned Level); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 194 | /// \brief Finds a directive which matches specified \a DPred predicate. |
| 195 | template <class NamedDirectivesPredicate> |
| 196 | bool hasDirective(NamedDirectivesPredicate DPred, bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 197 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 198 | /// \brief Returns currently analyzed directive. |
| 199 | OpenMPDirectiveKind getCurrentDirective() const { |
| 200 | return Stack.back().Directive; |
| 201 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 202 | /// \brief Returns parent directive. |
| 203 | OpenMPDirectiveKind getParentDirective() const { |
| 204 | if (Stack.size() > 2) |
| 205 | return Stack[Stack.size() - 2].Directive; |
| 206 | return OMPD_unknown; |
| 207 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 208 | |
| 209 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 210 | void setDefaultDSANone(SourceLocation Loc) { |
| 211 | Stack.back().DefaultAttr = DSA_none; |
| 212 | Stack.back().DefaultAttrLoc = Loc; |
| 213 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 214 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 215 | void setDefaultDSAShared(SourceLocation Loc) { |
| 216 | Stack.back().DefaultAttr = DSA_shared; |
| 217 | Stack.back().DefaultAttrLoc = Loc; |
| 218 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 219 | |
| 220 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 221 | return Stack.back().DefaultAttr; |
| 222 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 223 | SourceLocation getDefaultDSALocation() const { |
| 224 | return Stack.back().DefaultAttrLoc; |
| 225 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 226 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 227 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 228 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 229 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 230 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 233 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
| 234 | void setOrderedRegion(bool IsOrdered = true) { |
| 235 | Stack.back().OrderedRegion = IsOrdered; |
| 236 | } |
| 237 | /// \brief Returns true, if parent region is ordered (has associated |
| 238 | /// 'ordered' clause), false - otherwise. |
| 239 | bool isParentOrderedRegion() const { |
| 240 | if (Stack.size() > 2) |
| 241 | return Stack[Stack.size() - 2].OrderedRegion; |
| 242 | return false; |
| 243 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 244 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 245 | void setNowaitRegion(bool IsNowait = true) { |
| 246 | Stack.back().NowaitRegion = IsNowait; |
| 247 | } |
| 248 | /// \brief Returns true, if parent region is nowait (has associated |
| 249 | /// 'nowait' clause), false - otherwise. |
| 250 | bool isParentNowaitRegion() const { |
| 251 | if (Stack.size() > 2) |
| 252 | return Stack[Stack.size() - 2].NowaitRegion; |
| 253 | return false; |
| 254 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 255 | /// \brief Marks parent region as cancel region. |
| 256 | void setParentCancelRegion(bool Cancel = true) { |
| 257 | if (Stack.size() > 2) |
| 258 | Stack[Stack.size() - 2].CancelRegion = |
| 259 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 260 | } |
| 261 | /// \brief Return true if current region has inner cancel construct. |
| 262 | bool isCancelRegion() const { |
| 263 | return Stack.back().CancelRegion; |
| 264 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 265 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 266 | /// \brief Set collapse value for the region. |
| 267 | void setCollapseNumber(unsigned Val) { Stack.back().CollapseNumber = Val; } |
| 268 | /// \brief Return collapse value for region. |
| 269 | unsigned getCollapseNumber() const { |
| 270 | return Stack.back().CollapseNumber; |
| 271 | } |
| 272 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 273 | /// \brief Marks current target region as one with closely nested teams |
| 274 | /// region. |
| 275 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 276 | if (Stack.size() > 2) |
| 277 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 278 | } |
| 279 | /// \brief Returns true, if current region has closely nested teams region. |
| 280 | bool hasInnerTeamsRegion() const { |
| 281 | return getInnerTeamsRegionLoc().isValid(); |
| 282 | } |
| 283 | /// \brief Returns location of the nested teams region (if any). |
| 284 | SourceLocation getInnerTeamsRegionLoc() const { |
| 285 | if (Stack.size() > 1) |
| 286 | return Stack.back().InnerTeamsRegionLoc; |
| 287 | return SourceLocation(); |
| 288 | } |
| 289 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 290 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 291 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 292 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 293 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 294 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
| 295 | return isOpenMPParallelDirective(DKind) || DKind == OMPD_task || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 296 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 297 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 298 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 299 | |
| 300 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter, |
| 301 | VarDecl *D) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 302 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 303 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 304 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 305 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 306 | // in a region but not in construct] |
| 307 | // File-scope or namespace-scope variables referenced in called routines |
| 308 | // in the region are shared unless they appear in a threadprivate |
| 309 | // directive. |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 310 | if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 311 | DVar.CKind = OMPC_shared; |
| 312 | |
| 313 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 314 | // in a region but not in construct] |
| 315 | // Variables with static storage duration that are declared in called |
| 316 | // routines in the region are shared. |
| 317 | if (D->hasGlobalStorage()) |
| 318 | DVar.CKind = OMPC_shared; |
| 319 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 320 | return DVar; |
| 321 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 322 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 323 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 324 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 325 | // in a Construct, C/C++, predetermined, p.1] |
| 326 | // Variables with automatic storage duration that are declared in a scope |
| 327 | // inside the construct are private. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 328 | if (isOpenMPLocal(D, Iter) && D->isLocalVarDecl() && |
| 329 | (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) { |
| 330 | DVar.CKind = OMPC_private; |
| 331 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 334 | // Explicitly specified attributes and local variables with predetermined |
| 335 | // attributes. |
| 336 | if (Iter->SharingMap.count(D)) { |
| 337 | DVar.RefExpr = Iter->SharingMap[D].RefExpr; |
| 338 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 339 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 340 | return DVar; |
| 341 | } |
| 342 | |
| 343 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 344 | // in a Construct, C/C++, implicitly determined, p.1] |
| 345 | // In a parallel or task construct, the data-sharing attributes of these |
| 346 | // variables are determined by the default clause, if present. |
| 347 | switch (Iter->DefaultAttr) { |
| 348 | case DSA_shared: |
| 349 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 350 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 351 | return DVar; |
| 352 | case DSA_none: |
| 353 | return DVar; |
| 354 | case DSA_unspecified: |
| 355 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 356 | // in a Construct, implicitly determined, p.2] |
| 357 | // In a parallel construct, if no default clause is present, these |
| 358 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 359 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 360 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 361 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 362 | DVar.CKind = OMPC_shared; |
| 363 | return DVar; |
| 364 | } |
| 365 | |
| 366 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 367 | // in a Construct, implicitly determined, p.4] |
| 368 | // In a task construct, if no default clause is present, a variable that in |
| 369 | // the enclosing context is determined to be shared by all implicit tasks |
| 370 | // bound to the current team is shared. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 371 | if (DVar.DKind == OMPD_task) { |
| 372 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 373 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 374 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 375 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
| 376 | // Referenced |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 377 | // in a Construct, implicitly determined, p.6] |
| 378 | // In a task construct, if no default clause is present, a variable |
| 379 | // whose data-sharing attribute is not determined by the rules above is |
| 380 | // firstprivate. |
| 381 | DVarTemp = getDSA(I, D); |
| 382 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 383 | DVar.RefExpr = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 384 | DVar.DKind = OMPD_task; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 385 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 386 | return DVar; |
| 387 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 388 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 389 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 390 | } |
| 391 | DVar.DKind = OMPD_task; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 392 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 393 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 394 | return DVar; |
| 395 | } |
| 396 | } |
| 397 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 398 | // in a Construct, implicitly determined, p.3] |
| 399 | // For constructs other than task, if no default clause is present, these |
| 400 | // variables inherit their data-sharing attributes from the enclosing |
| 401 | // context. |
Benjamin Kramer | 167e999 | 2014-03-02 12:20:24 +0000 | [diff] [blame] | 402 | return getDSA(std::next(Iter), D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 403 | } |
| 404 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 405 | DeclRefExpr *DSAStackTy::addUniqueAligned(VarDecl *D, DeclRefExpr *NewDE) { |
| 406 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 407 | D = D->getCanonicalDecl(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 408 | auto It = Stack.back().AlignedMap.find(D); |
| 409 | if (It == Stack.back().AlignedMap.end()) { |
| 410 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 411 | Stack.back().AlignedMap[D] = NewDE; |
| 412 | return nullptr; |
| 413 | } else { |
| 414 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 415 | return It->second; |
| 416 | } |
| 417 | return nullptr; |
| 418 | } |
| 419 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 420 | void DSAStackTy::addLoopControlVariable(VarDecl *D) { |
| 421 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 422 | D = D->getCanonicalDecl(); |
| 423 | Stack.back().LCVSet.insert(D); |
| 424 | } |
| 425 | |
| 426 | bool DSAStackTy::isLoopControlVariable(VarDecl *D) { |
| 427 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 428 | D = D->getCanonicalDecl(); |
| 429 | return Stack.back().LCVSet.count(D) > 0; |
| 430 | } |
| 431 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 432 | void DSAStackTy::addDSA(VarDecl *D, DeclRefExpr *E, OpenMPClauseKind A) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 433 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 434 | if (A == OMPC_threadprivate) { |
| 435 | Stack[0].SharingMap[D].Attributes = A; |
| 436 | Stack[0].SharingMap[D].RefExpr = E; |
| 437 | } else { |
| 438 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
| 439 | Stack.back().SharingMap[D].Attributes = A; |
| 440 | Stack.back().SharingMap[D].RefExpr = E; |
| 441 | } |
| 442 | } |
| 443 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 444 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 445 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 446 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 447 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 448 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 449 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 450 | ++I; |
| 451 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 452 | if (I == E) |
| 453 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 454 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 455 | Scope *CurScope = getCurScope(); |
| 456 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 457 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 458 | } |
| 459 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 460 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 461 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 464 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 465 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 466 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 467 | DeclContext *DC = SemaRef.CurContext; |
| 468 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 469 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 470 | VarDecl *Decl = |
| 471 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 472 | if (Attrs) { |
| 473 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 474 | I != E; ++I) |
| 475 | Decl->addAttr(*I); |
| 476 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 477 | Decl->setImplicit(); |
| 478 | return Decl; |
| 479 | } |
| 480 | |
| 481 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 482 | SourceLocation Loc, |
| 483 | bool RefersToCapture = false) { |
| 484 | D->setReferenced(); |
| 485 | D->markUsed(S.Context); |
| 486 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 487 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 488 | VK_LValue); |
| 489 | } |
| 490 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 491 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 492 | D = D->getCanonicalDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 493 | DSAVarData DVar; |
| 494 | |
| 495 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 496 | // in a Construct, C/C++, predetermined, p.1] |
| 497 | // Variables appearing in threadprivate directives are threadprivate. |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 498 | if ((D->getTLSKind() != VarDecl::TLS_None && |
| 499 | !(D->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 500 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 501 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 502 | (D->getStorageClass() == SC_Register && D->hasAttr<AsmLabelAttr>() && |
| 503 | !D->isLocalVarDecl())) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 504 | addDSA(D, buildDeclRefExpr(SemaRef, D, D->getType().getNonReferenceType(), |
| 505 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 506 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 507 | } |
| 508 | if (Stack[0].SharingMap.count(D)) { |
| 509 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; |
| 510 | DVar.CKind = OMPC_threadprivate; |
| 511 | return DVar; |
| 512 | } |
| 513 | |
| 514 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 515 | // in a Construct, C/C++, predetermined, p.1] |
| 516 | // Variables with automatic storage duration that are declared in a scope |
| 517 | // inside the construct are private. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 518 | OpenMPDirectiveKind Kind = |
| 519 | FromParent ? getParentDirective() : getCurrentDirective(); |
| 520 | auto StartI = std::next(Stack.rbegin()); |
| 521 | auto EndI = std::prev(Stack.rend()); |
| 522 | if (FromParent && StartI != EndI) { |
| 523 | StartI = std::next(StartI); |
| 524 | } |
| 525 | if (!isParallelOrTaskRegion(Kind)) { |
Alexey Bataev | 8b9cb98 | 2014-07-24 02:33:58 +0000 | [diff] [blame] | 526 | if (isOpenMPLocal(D, StartI) && |
| 527 | ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || |
| 528 | D->getStorageClass() == SC_None)) || |
| 529 | isa<ParmVarDecl>(D))) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 530 | DVar.CKind = OMPC_private; |
| 531 | return DVar; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 532 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 533 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 534 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 535 | // in a Construct, C/C++, predetermined, p.4] |
| 536 | // Static data members are shared. |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 537 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 538 | // in a Construct, C/C++, predetermined, p.7] |
| 539 | // Variables with static storage duration that are declared in a scope |
| 540 | // inside the construct are shared. |
Kelvin Li | 4eea8c6 | 2015-09-15 18:56:58 +0000 | [diff] [blame] | 541 | if (D->isStaticDataMember()) { |
Alexey Bataev | 42971a3 | 2015-01-20 07:03:46 +0000 | [diff] [blame] | 542 | DSAVarData DVarTemp = |
| 543 | hasDSA(D, isOpenMPPrivate, MatchesAlways(), FromParent); |
| 544 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
| 545 | return DVar; |
| 546 | |
Alexey Bataev | 24b04aa | 2015-01-16 07:11:33 +0000 | [diff] [blame] | 547 | DVar.CKind = OMPC_shared; |
| 548 | return DVar; |
| 549 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 553 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 554 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 555 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 556 | // in a Construct, C/C++, predetermined, p.6] |
| 557 | // Variables with const qualified type having no mutable member are |
| 558 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 559 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 560 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 561 | if (IsConstant && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 562 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 563 | // Variables with const-qualified type having no mutable member may be |
| 564 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 565 | DSAVarData DVarTemp = hasDSA(D, MatchesAnyClause(OMPC_firstprivate), |
| 566 | MatchesAlways(), FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 567 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 568 | return DVar; |
| 569 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 570 | DVar.CKind = OMPC_shared; |
| 571 | return DVar; |
| 572 | } |
| 573 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 574 | // Explicitly specified attributes and local variables with predetermined |
| 575 | // attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 576 | auto I = std::prev(StartI); |
| 577 | if (I->SharingMap.count(D)) { |
| 578 | DVar.RefExpr = I->SharingMap[D].RefExpr; |
| 579 | DVar.CKind = I->SharingMap[D].Attributes; |
| 580 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | return DVar; |
| 584 | } |
| 585 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 586 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(VarDecl *D, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 587 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 588 | auto StartI = Stack.rbegin(); |
| 589 | auto EndI = std::prev(Stack.rend()); |
| 590 | if (FromParent && StartI != EndI) { |
| 591 | StartI = std::next(StartI); |
| 592 | } |
| 593 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 596 | template <class ClausesPredicate, class DirectivesPredicate> |
| 597 | DSAStackTy::DSAVarData DSAStackTy::hasDSA(VarDecl *D, ClausesPredicate CPred, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 598 | DirectivesPredicate DPred, |
| 599 | bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 600 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 601 | auto StartI = std::next(Stack.rbegin()); |
| 602 | auto EndI = std::prev(Stack.rend()); |
| 603 | if (FromParent && StartI != EndI) { |
| 604 | StartI = std::next(StartI); |
| 605 | } |
| 606 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 607 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 608 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 609 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 610 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 611 | return DVar; |
| 612 | } |
| 613 | return DSAVarData(); |
| 614 | } |
| 615 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 616 | template <class ClausesPredicate, class DirectivesPredicate> |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 617 | DSAStackTy::DSAVarData |
| 618 | DSAStackTy::hasInnermostDSA(VarDecl *D, ClausesPredicate CPred, |
| 619 | DirectivesPredicate DPred, bool FromParent) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 620 | D = D->getCanonicalDecl(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 621 | auto StartI = std::next(Stack.rbegin()); |
| 622 | auto EndI = std::prev(Stack.rend()); |
| 623 | if (FromParent && StartI != EndI) { |
| 624 | StartI = std::next(StartI); |
| 625 | } |
| 626 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 627 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 628 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 629 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 630 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 631 | return DVar; |
| 632 | return DSAVarData(); |
| 633 | } |
| 634 | return DSAVarData(); |
| 635 | } |
| 636 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 637 | bool DSAStackTy::hasExplicitDSA( |
| 638 | VarDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 639 | unsigned Level) { |
| 640 | if (CPred(ClauseKindMode)) |
| 641 | return true; |
| 642 | if (isClauseParsingMode()) |
| 643 | ++Level; |
| 644 | D = D->getCanonicalDecl(); |
| 645 | auto StartI = Stack.rbegin(); |
| 646 | auto EndI = std::prev(Stack.rend()); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 647 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 648 | return false; |
| 649 | std::advance(StartI, Level); |
| 650 | return (StartI->SharingMap.count(D) > 0) && StartI->SharingMap[D].RefExpr && |
| 651 | CPred(StartI->SharingMap[D].Attributes); |
| 652 | } |
| 653 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 654 | template <class NamedDirectivesPredicate> |
| 655 | bool DSAStackTy::hasDirective(NamedDirectivesPredicate DPred, bool FromParent) { |
| 656 | auto StartI = std::next(Stack.rbegin()); |
| 657 | auto EndI = std::prev(Stack.rend()); |
| 658 | if (FromParent && StartI != EndI) { |
| 659 | StartI = std::next(StartI); |
| 660 | } |
| 661 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 662 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 663 | return true; |
| 664 | } |
| 665 | return false; |
| 666 | } |
| 667 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 668 | void Sema::InitDataSharingAttributesStack() { |
| 669 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 670 | } |
| 671 | |
| 672 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 673 | |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 674 | bool Sema::IsOpenMPCapturedVar(VarDecl *VD) { |
| 675 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 676 | VD = VD->getCanonicalDecl(); |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 677 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 678 | (!DSAStack->isClauseParsingMode() || |
| 679 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 680 | if (DSAStack->isLoopControlVariable(VD) || |
| 681 | (VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 682 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
| 683 | DSAStack->isForceVarCapturing()) |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 684 | return true; |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 685 | auto DVarPrivate = DSAStack->getTopDSA(VD, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 686 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
| 687 | return true; |
| 688 | DVarPrivate = DSAStack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 689 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 690 | return DVarPrivate.CKind != OMPC_unknown; |
| 691 | } |
| 692 | return false; |
| 693 | } |
| 694 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 695 | bool Sema::isOpenMPPrivateVar(VarDecl *VD, unsigned Level) { |
| 696 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 697 | return DSAStack->hasExplicitDSA( |
| 698 | VD, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
| 699 | } |
| 700 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 701 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 702 | |
| 703 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 704 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 705 | Scope *CurScope, SourceLocation Loc) { |
| 706 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 707 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 708 | } |
| 709 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 710 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 711 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 714 | void Sema::EndOpenMPClause() { |
| 715 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 718 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 719 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 720 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 721 | // clause requires an accessible, unambiguous default constructor for the |
| 722 | // class type, unless the list item is also specified in a firstprivate |
| 723 | // clause. |
| 724 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 725 | for (auto *C : D->clauses()) { |
| 726 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 727 | SmallVector<Expr *, 8> PrivateCopies; |
| 728 | for (auto *DE : Clause->varlists()) { |
| 729 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 730 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 731 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 732 | } |
| 733 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(DE)->getDecl()); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 734 | QualType Type = VD->getType().getNonReferenceType(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 735 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 736 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 737 | // Generate helper private variable and initialize it with the |
| 738 | // default value. The address of the original variable is replaced |
| 739 | // by the address of the new private variable in CodeGen. This new |
| 740 | // variable is not added to IdResolver, so the code in the OpenMP |
| 741 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 742 | auto *VDPrivate = buildVarDecl( |
| 743 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
| 744 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 745 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 746 | if (VDPrivate->isInvalidDecl()) |
| 747 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 748 | PrivateCopies.push_back(buildDeclRefExpr( |
| 749 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 750 | } else { |
| 751 | // The variable is also a firstprivate, so initialization sequence |
| 752 | // for private copy is generated already. |
| 753 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 754 | } |
| 755 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 756 | // Set initializers to private copies if no errors were found. |
| 757 | if (PrivateCopies.size() == Clause->varlist_size()) { |
| 758 | Clause->setPrivateCopies(PrivateCopies); |
| 759 | } |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 764 | DSAStack->pop(); |
| 765 | DiscardCleanupsInEvaluationContext(); |
| 766 | PopExpressionEvaluationContext(); |
| 767 | } |
| 768 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 769 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 770 | Expr *NumIterations, Sema &SemaRef, |
| 771 | Scope *S); |
| 772 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 773 | namespace { |
| 774 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 775 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 776 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 777 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 778 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 779 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 780 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 781 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 782 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 783 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 784 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 785 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 786 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 787 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 788 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 789 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 790 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 791 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 792 | |
| 793 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 794 | CXXScopeSpec &ScopeSpec, |
| 795 | const DeclarationNameInfo &Id) { |
| 796 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 797 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 798 | |
| 799 | if (Lookup.isAmbiguous()) |
| 800 | return ExprError(); |
| 801 | |
| 802 | VarDecl *VD; |
| 803 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 804 | if (TypoCorrection Corrected = CorrectTypo( |
| 805 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 806 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 807 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 808 | PDiag(Lookup.empty() |
| 809 | ? diag::err_undeclared_var_use_suggest |
| 810 | : diag::err_omp_expected_var_arg_suggest) |
| 811 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 812 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 813 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 814 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 815 | : diag::err_omp_expected_var_arg) |
| 816 | << Id.getName(); |
| 817 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 818 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 819 | } else { |
| 820 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 821 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 822 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 823 | return ExprError(); |
| 824 | } |
| 825 | } |
| 826 | Lookup.suppressDiagnostics(); |
| 827 | |
| 828 | // OpenMP [2.9.2, Syntax, C/C++] |
| 829 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 830 | if (!VD->hasGlobalStorage()) { |
| 831 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 832 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 833 | bool IsDecl = |
| 834 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 835 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 836 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 837 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 838 | return ExprError(); |
| 839 | } |
| 840 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 841 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 842 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 843 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 844 | // A threadprivate directive for file-scope variables must appear outside |
| 845 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 846 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 847 | !getCurLexicalContext()->isTranslationUnit()) { |
| 848 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 849 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 850 | bool IsDecl = |
| 851 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 852 | Diag(VD->getLocation(), |
| 853 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 854 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 855 | return ExprError(); |
| 856 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 857 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 858 | // A threadprivate directive for static class member variables must appear |
| 859 | // in the class definition, in the same scope in which the member |
| 860 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 861 | if (CanonicalVD->isStaticDataMember() && |
| 862 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 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.4] |
| 873 | // A threadprivate directive for namespace-scope variables must appear |
| 874 | // outside any definition or declaration other than the namespace |
| 875 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 876 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 877 | (!getCurLexicalContext()->isFileContext() || |
| 878 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 879 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 880 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 881 | bool IsDecl = |
| 882 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 883 | Diag(VD->getLocation(), |
| 884 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 885 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 886 | return ExprError(); |
| 887 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 888 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 889 | // A threadprivate directive for static block-scope variables must appear |
| 890 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 891 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 892 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 893 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 894 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 895 | bool IsDecl = |
| 896 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 897 | Diag(VD->getLocation(), |
| 898 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 899 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 900 | return ExprError(); |
| 901 | } |
| 902 | |
| 903 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 904 | // A threadprivate directive must lexically precede all references to any |
| 905 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 906 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 907 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 908 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 909 | return ExprError(); |
| 910 | } |
| 911 | |
| 912 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 913 | ExprResult DE = buildDeclRefExpr(*this, VD, ExprType, Id.getLoc()); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 914 | return DE; |
| 915 | } |
| 916 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 917 | Sema::DeclGroupPtrTy |
| 918 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 919 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 920 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 921 | CurContext->addDecl(D); |
| 922 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 923 | } |
| 924 | return DeclGroupPtrTy(); |
| 925 | } |
| 926 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 927 | namespace { |
| 928 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 929 | Sema &SemaRef; |
| 930 | |
| 931 | public: |
| 932 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 933 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 934 | if (VD->hasLocalStorage()) { |
| 935 | SemaRef.Diag(E->getLocStart(), |
| 936 | diag::err_omp_local_var_in_threadprivate_init) |
| 937 | << E->getSourceRange(); |
| 938 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 939 | << VD << VD->getSourceRange(); |
| 940 | return true; |
| 941 | } |
| 942 | } |
| 943 | return false; |
| 944 | } |
| 945 | bool VisitStmt(const Stmt *S) { |
| 946 | for (auto Child : S->children()) { |
| 947 | if (Child && Visit(Child)) |
| 948 | return true; |
| 949 | } |
| 950 | return false; |
| 951 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 952 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 953 | }; |
| 954 | } // namespace |
| 955 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 956 | OMPThreadPrivateDecl * |
| 957 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 958 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 959 | for (auto &RefExpr : VarList) { |
| 960 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 961 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 962 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 963 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 964 | QualType QType = VD->getType(); |
| 965 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 966 | // It will be analyzed later. |
| 967 | Vars.push_back(DE); |
| 968 | continue; |
| 969 | } |
| 970 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 971 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 972 | // A threadprivate variable must not have an incomplete type. |
| 973 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 974 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 975 | continue; |
| 976 | } |
| 977 | |
| 978 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 979 | // A threadprivate variable must not have a reference type. |
| 980 | if (VD->getType()->isReferenceType()) { |
| 981 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 982 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 983 | bool IsDecl = |
| 984 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 985 | Diag(VD->getLocation(), |
| 986 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 987 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 988 | continue; |
| 989 | } |
| 990 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 991 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 992 | // the corresponding diagnostic. |
| 993 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 994 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 995 | getLangOpts().OpenMPUseTLS && |
| 996 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 997 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 998 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 999 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1000 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1001 | bool IsDecl = |
| 1002 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1003 | Diag(VD->getLocation(), |
| 1004 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1005 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1006 | continue; |
| 1007 | } |
| 1008 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1009 | // Check if initial value of threadprivate variable reference variable with |
| 1010 | // local storage (it is not supported by runtime). |
| 1011 | if (auto Init = VD->getAnyInitializer()) { |
| 1012 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1013 | if (Checker.Visit(Init)) |
| 1014 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1015 | } |
| 1016 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1017 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1018 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1019 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1020 | Context, SourceRange(Loc, Loc))); |
| 1021 | if (auto *ML = Context.getASTMutationListener()) |
| 1022 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1023 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1024 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1025 | if (!Vars.empty()) { |
| 1026 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1027 | Vars); |
| 1028 | D->setAccess(AS_public); |
| 1029 | } |
| 1030 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1031 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1032 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1033 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
| 1034 | const VarDecl *VD, DSAStackTy::DSAVarData DVar, |
| 1035 | bool IsLoopIterVar = false) { |
| 1036 | if (DVar.RefExpr) { |
| 1037 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1038 | << getOpenMPClauseName(DVar.CKind); |
| 1039 | return; |
| 1040 | } |
| 1041 | enum { |
| 1042 | PDSA_StaticMemberShared, |
| 1043 | PDSA_StaticLocalVarShared, |
| 1044 | PDSA_LoopIterVarPrivate, |
| 1045 | PDSA_LoopIterVarLinear, |
| 1046 | PDSA_LoopIterVarLastprivate, |
| 1047 | PDSA_ConstVarShared, |
| 1048 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1049 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1050 | PDSA_LocalVarPrivate, |
| 1051 | PDSA_Implicit |
| 1052 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1053 | bool ReportHint = false; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1054 | auto ReportLoc = VD->getLocation(); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1055 | if (IsLoopIterVar) { |
| 1056 | if (DVar.CKind == OMPC_private) |
| 1057 | Reason = PDSA_LoopIterVarPrivate; |
| 1058 | else if (DVar.CKind == OMPC_lastprivate) |
| 1059 | Reason = PDSA_LoopIterVarLastprivate; |
| 1060 | else |
| 1061 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1062 | } else if (DVar.DKind == OMPD_task && DVar.CKind == OMPC_firstprivate) { |
| 1063 | Reason = PDSA_TaskVarFirstprivate; |
| 1064 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1065 | } else if (VD->isStaticLocal()) |
| 1066 | Reason = PDSA_StaticLocalVarShared; |
| 1067 | else if (VD->isStaticDataMember()) |
| 1068 | Reason = PDSA_StaticMemberShared; |
| 1069 | else if (VD->isFileVarDecl()) |
| 1070 | Reason = PDSA_GlobalVarShared; |
| 1071 | else if (VD->getType().isConstant(SemaRef.getASTContext())) |
| 1072 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1073 | else if (VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1074 | ReportHint = true; |
| 1075 | Reason = PDSA_LocalVarPrivate; |
| 1076 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1077 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1078 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1079 | << Reason << ReportHint |
| 1080 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1081 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1082 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1083 | << getOpenMPClauseName(DVar.CKind); |
| 1084 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1087 | namespace { |
| 1088 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1089 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1090 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1091 | bool ErrorFound; |
| 1092 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1093 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1094 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1095 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1096 | public: |
| 1097 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1098 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1099 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1100 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1101 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1102 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1103 | auto DVar = Stack->getTopDSA(VD, false); |
| 1104 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1105 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1106 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1107 | auto ELoc = E->getExprLoc(); |
| 1108 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1109 | // The default(none) clause requires that each variable that is referenced |
| 1110 | // in the construct, and does not have a predetermined data-sharing |
| 1111 | // attribute, must have its data-sharing attribute explicitly determined |
| 1112 | // by being listed in a data-sharing attribute clause. |
| 1113 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1114 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1115 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1116 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1117 | return; |
| 1118 | } |
| 1119 | |
| 1120 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1121 | // A list item that appears in a reduction clause of the innermost |
| 1122 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1123 | // explicit task. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1124 | DVar = Stack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1125 | [](OpenMPDirectiveKind K) -> bool { |
| 1126 | return isOpenMPParallelDirective(K) || |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1127 | isOpenMPWorksharingDirective(K) || |
| 1128 | isOpenMPTeamsDirective(K); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1129 | }, |
| 1130 | false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1131 | if (DKind == OMPD_task && DVar.CKind == OMPC_reduction) { |
| 1132 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1133 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1134 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1135 | return; |
| 1136 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1137 | |
| 1138 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1139 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1140 | if (DKind == OMPD_task && DVar.CKind != OMPC_shared) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1141 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1145 | for (auto *C : S->clauses()) { |
| 1146 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1147 | // for task directives. |
| 1148 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1149 | for (auto *CC : C->children()) { |
| 1150 | if (CC) |
| 1151 | Visit(CC); |
| 1152 | } |
| 1153 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1154 | } |
| 1155 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1156 | for (auto *C : S->children()) { |
| 1157 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1158 | Visit(C); |
| 1159 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1160 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1161 | |
| 1162 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1163 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1164 | llvm::DenseMap<VarDecl *, Expr *> &getVarsWithInheritedDSA() { |
| 1165 | return VarsWithInheritedDSA; |
| 1166 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1167 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1168 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1169 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1170 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1171 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1172 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1173 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1174 | switch (DKind) { |
| 1175 | case OMPD_parallel: { |
| 1176 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1177 | QualType KmpInt32PtrTy = |
| 1178 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1179 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1180 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1181 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1182 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1183 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1184 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1185 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1186 | break; |
| 1187 | } |
| 1188 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1189 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1190 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1191 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1192 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1193 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1194 | break; |
| 1195 | } |
| 1196 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1197 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1198 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1199 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1200 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1201 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1202 | break; |
| 1203 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1204 | case OMPD_for_simd: { |
| 1205 | Sema::CapturedParamNameType Params[] = { |
| 1206 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1207 | }; |
| 1208 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1209 | Params); |
| 1210 | break; |
| 1211 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1212 | case OMPD_sections: { |
| 1213 | Sema::CapturedParamNameType Params[] = { |
| 1214 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1215 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1216 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1217 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1218 | break; |
| 1219 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1220 | case OMPD_section: { |
| 1221 | Sema::CapturedParamNameType Params[] = { |
| 1222 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1223 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1224 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1225 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1226 | break; |
| 1227 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1228 | case OMPD_single: { |
| 1229 | Sema::CapturedParamNameType Params[] = { |
| 1230 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1231 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1232 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1233 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1234 | break; |
| 1235 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1236 | case OMPD_master: { |
| 1237 | Sema::CapturedParamNameType Params[] = { |
| 1238 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1239 | }; |
| 1240 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1241 | Params); |
| 1242 | break; |
| 1243 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1244 | case OMPD_critical: { |
| 1245 | Sema::CapturedParamNameType Params[] = { |
| 1246 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1247 | }; |
| 1248 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1249 | Params); |
| 1250 | break; |
| 1251 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1252 | case OMPD_parallel_for: { |
| 1253 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1254 | QualType KmpInt32PtrTy = |
| 1255 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1256 | Sema::CapturedParamNameType Params[] = { |
| 1257 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1258 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1259 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1260 | }; |
| 1261 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1262 | Params); |
| 1263 | break; |
| 1264 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1265 | case OMPD_parallel_for_simd: { |
| 1266 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1267 | QualType KmpInt32PtrTy = |
| 1268 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1269 | Sema::CapturedParamNameType Params[] = { |
| 1270 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1271 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1272 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1273 | }; |
| 1274 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1275 | Params); |
| 1276 | break; |
| 1277 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1278 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1279 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1280 | QualType KmpInt32PtrTy = |
| 1281 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1282 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1283 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1284 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1285 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1286 | }; |
| 1287 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1288 | Params); |
| 1289 | break; |
| 1290 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1291 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1292 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1293 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1294 | FunctionProtoType::ExtProtoInfo EPI; |
| 1295 | EPI.Variadic = true; |
| 1296 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1297 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1298 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1299 | std::make_pair(".part_id.", KmpInt32Ty), |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1300 | std::make_pair(".privates.", |
| 1301 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1302 | std::make_pair( |
| 1303 | ".copy_fn.", |
| 1304 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1305 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1306 | }; |
| 1307 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1308 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1309 | // Mark this captured region as inlined, because we don't use outlined |
| 1310 | // function directly. |
| 1311 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1312 | AlwaysInlineAttr::CreateImplicit( |
| 1313 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1314 | break; |
| 1315 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1316 | case OMPD_ordered: { |
| 1317 | Sema::CapturedParamNameType Params[] = { |
| 1318 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1319 | }; |
| 1320 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1321 | Params); |
| 1322 | break; |
| 1323 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1324 | case OMPD_atomic: { |
| 1325 | Sema::CapturedParamNameType Params[] = { |
| 1326 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1327 | }; |
| 1328 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1329 | Params); |
| 1330 | break; |
| 1331 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1332 | case OMPD_target_data: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1333 | case OMPD_target: { |
| 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 | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1341 | case OMPD_teams: { |
| 1342 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1343 | QualType KmpInt32PtrTy = |
| 1344 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1345 | Sema::CapturedParamNameType Params[] = { |
| 1346 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1347 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1348 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1349 | }; |
| 1350 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1351 | Params); |
| 1352 | break; |
| 1353 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1354 | case OMPD_taskgroup: { |
| 1355 | Sema::CapturedParamNameType Params[] = { |
| 1356 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1357 | }; |
| 1358 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1359 | Params); |
| 1360 | break; |
| 1361 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1362 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1363 | case OMPD_taskyield: |
| 1364 | case OMPD_barrier: |
| 1365 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1366 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1367 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1368 | case OMPD_flush: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1369 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1370 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1371 | llvm_unreachable("Unknown OpenMP directive"); |
| 1372 | } |
| 1373 | } |
| 1374 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1375 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1376 | ArrayRef<OMPClause *> Clauses) { |
| 1377 | if (!S.isUsable()) { |
| 1378 | ActOnCapturedRegionError(); |
| 1379 | return StmtError(); |
| 1380 | } |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1381 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1382 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1383 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1384 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1385 | (getLangOpts().OpenMPUseTLS && |
| 1386 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1387 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1388 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1389 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1390 | for (auto *VarRef : Clause->children()) { |
| 1391 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1392 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1393 | } |
| 1394 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1395 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1396 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 1397 | Clause->getClauseKind() == OMPC_schedule) { |
| 1398 | // Mark all variables in private list clauses as used in inner region. |
| 1399 | // Required for proper codegen of combined directives. |
| 1400 | // TODO: add processing for other clauses. |
| 1401 | if (auto *E = cast_or_null<Expr>( |
| 1402 | cast<OMPScheduleClause>(Clause)->getHelperChunkSize())) { |
| 1403 | MarkDeclarationsReferencedInExpr(E); |
| 1404 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1405 | } |
| 1406 | } |
| 1407 | return ActOnCapturedRegionEnd(S.get()); |
| 1408 | } |
| 1409 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1410 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1411 | OpenMPDirectiveKind CurrentRegion, |
| 1412 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1413 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1414 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1415 | // Allowed nesting of constructs |
| 1416 | // +------------------+-----------------+------------------------------------+ |
| 1417 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1418 | // +------------------+-----------------+------------------------------------+ |
| 1419 | // | parallel | parallel | * | |
| 1420 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1421 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1422 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1423 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1424 | // | parallel | simd | * | |
| 1425 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1426 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1427 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1428 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1429 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1430 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1431 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1432 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1433 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1434 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1435 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1436 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1437 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1438 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1439 | // | parallel | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1440 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1441 | // | parallel | cancellation | | |
| 1442 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1443 | // | parallel | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1444 | // +------------------+-----------------+------------------------------------+ |
| 1445 | // | for | parallel | * | |
| 1446 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1447 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1448 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1449 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1450 | // | for | simd | * | |
| 1451 | // | for | sections | + | |
| 1452 | // | for | section | + | |
| 1453 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1454 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1455 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1456 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1457 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1458 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1459 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1460 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1461 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1462 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1463 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1464 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1465 | // | for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1466 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1467 | // | for | cancellation | | |
| 1468 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1469 | // | for | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1470 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1471 | // | master | parallel | * | |
| 1472 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1473 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1474 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1475 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1476 | // | master | simd | * | |
| 1477 | // | master | sections | + | |
| 1478 | // | master | section | + | |
| 1479 | // | master | single | + | |
| 1480 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1481 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1482 | // | master |parallel sections| * | |
| 1483 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1484 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1485 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1486 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1487 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1488 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1489 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1490 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1491 | // | master | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1492 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1493 | // | master | cancellation | | |
| 1494 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1495 | // | master | cancel | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1496 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1497 | // | critical | parallel | * | |
| 1498 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1499 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1500 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1501 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1502 | // | critical | simd | * | |
| 1503 | // | critical | sections | + | |
| 1504 | // | critical | section | + | |
| 1505 | // | critical | single | + | |
| 1506 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1507 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1508 | // | critical |parallel sections| * | |
| 1509 | // | critical | task | * | |
| 1510 | // | critical | taskyield | * | |
| 1511 | // | critical | barrier | + | |
| 1512 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1513 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1514 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1515 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1516 | // | critical | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1517 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1518 | // | critical | cancellation | | |
| 1519 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1520 | // | critical | cancel | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1521 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1522 | // | simd | parallel | | |
| 1523 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1524 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1525 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1526 | // | simd | critical | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1527 | // | simd | simd | | |
| 1528 | // | simd | sections | | |
| 1529 | // | simd | section | | |
| 1530 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1531 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1532 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1533 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1534 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1535 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1536 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1537 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1538 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1539 | // | simd | flush | | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1540 | // | simd | ordered | | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1541 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1542 | // | simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1543 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1544 | // | simd | cancellation | | |
| 1545 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1546 | // | simd | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1547 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1548 | // | for simd | parallel | | |
| 1549 | // | for simd | for | | |
| 1550 | // | for simd | for simd | | |
| 1551 | // | for simd | master | | |
| 1552 | // | for simd | critical | | |
| 1553 | // | for simd | simd | | |
| 1554 | // | for simd | sections | | |
| 1555 | // | for simd | section | | |
| 1556 | // | for simd | single | | |
| 1557 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1558 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1559 | // | for simd |parallel sections| | |
| 1560 | // | for simd | task | | |
| 1561 | // | for simd | taskyield | | |
| 1562 | // | for simd | barrier | | |
| 1563 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1564 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1565 | // | for simd | flush | | |
| 1566 | // | for simd | ordered | | |
| 1567 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1568 | // | for simd | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1569 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1570 | // | for simd | cancellation | | |
| 1571 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1572 | // | for simd | cancel | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1573 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1574 | // | parallel for simd| parallel | | |
| 1575 | // | parallel for simd| for | | |
| 1576 | // | parallel for simd| for simd | | |
| 1577 | // | parallel for simd| master | | |
| 1578 | // | parallel for simd| critical | | |
| 1579 | // | parallel for simd| simd | | |
| 1580 | // | parallel for simd| sections | | |
| 1581 | // | parallel for simd| section | | |
| 1582 | // | parallel for simd| single | | |
| 1583 | // | parallel for simd| parallel for | | |
| 1584 | // | parallel for simd|parallel for simd| | |
| 1585 | // | parallel for simd|parallel sections| | |
| 1586 | // | parallel for simd| task | | |
| 1587 | // | parallel for simd| taskyield | | |
| 1588 | // | parallel for simd| barrier | | |
| 1589 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1590 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1591 | // | parallel for simd| flush | | |
| 1592 | // | parallel for simd| ordered | | |
| 1593 | // | parallel for simd| atomic | | |
| 1594 | // | parallel for simd| target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1595 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1596 | // | parallel for simd| cancellation | | |
| 1597 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1598 | // | parallel for simd| cancel | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1599 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1600 | // | sections | parallel | * | |
| 1601 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1602 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1603 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1604 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1605 | // | sections | simd | * | |
| 1606 | // | sections | sections | + | |
| 1607 | // | sections | section | * | |
| 1608 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1609 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1610 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1611 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1612 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1613 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1614 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1615 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1616 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1617 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1618 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1619 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1620 | // | sections | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1621 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1622 | // | sections | cancellation | | |
| 1623 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1624 | // | sections | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1625 | // +------------------+-----------------+------------------------------------+ |
| 1626 | // | section | parallel | * | |
| 1627 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1628 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1629 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1630 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1631 | // | section | simd | * | |
| 1632 | // | section | sections | + | |
| 1633 | // | section | section | + | |
| 1634 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1635 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1636 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1637 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1638 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1639 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1640 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1641 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1642 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1643 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1644 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1645 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1646 | // | section | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1647 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1648 | // | section | cancellation | | |
| 1649 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1650 | // | section | cancel | ! | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1651 | // +------------------+-----------------+------------------------------------+ |
| 1652 | // | single | parallel | * | |
| 1653 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1654 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1655 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1656 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1657 | // | single | simd | * | |
| 1658 | // | single | sections | + | |
| 1659 | // | single | section | + | |
| 1660 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1661 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1662 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1663 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1664 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1665 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1666 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1667 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1668 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1669 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1670 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1671 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1672 | // | single | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1673 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1674 | // | single | cancellation | | |
| 1675 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1676 | // | single | cancel | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1677 | // +------------------+-----------------+------------------------------------+ |
| 1678 | // | parallel for | parallel | * | |
| 1679 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1680 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1681 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1682 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1683 | // | parallel for | simd | * | |
| 1684 | // | parallel for | sections | + | |
| 1685 | // | parallel for | section | + | |
| 1686 | // | parallel for | single | + | |
| 1687 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1688 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1689 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1690 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1691 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1692 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1693 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1694 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1695 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1696 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1697 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1698 | // | parallel for | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1699 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1700 | // | parallel for | cancellation | | |
| 1701 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1702 | // | parallel for | cancel | ! | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1703 | // +------------------+-----------------+------------------------------------+ |
| 1704 | // | parallel sections| parallel | * | |
| 1705 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1706 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1707 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1708 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1709 | // | parallel sections| simd | * | |
| 1710 | // | parallel sections| sections | + | |
| 1711 | // | parallel sections| section | * | |
| 1712 | // | parallel sections| single | + | |
| 1713 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1714 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1715 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1716 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1717 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1718 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1719 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1720 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1721 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1722 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1723 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1724 | // | parallel sections| target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1725 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1726 | // | parallel sections| cancellation | | |
| 1727 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1728 | // | parallel sections| cancel | ! | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1729 | // +------------------+-----------------+------------------------------------+ |
| 1730 | // | task | parallel | * | |
| 1731 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1732 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1733 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1734 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1735 | // | task | simd | * | |
| 1736 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1737 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1738 | // | task | single | + | |
| 1739 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1740 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1741 | // | task |parallel sections| * | |
| 1742 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1743 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1744 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1745 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1746 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1747 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1748 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1749 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1750 | // | task | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1751 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1752 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1753 | // | | point | ! | |
| 1754 | // | task | cancel | ! | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1755 | // +------------------+-----------------+------------------------------------+ |
| 1756 | // | ordered | parallel | * | |
| 1757 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1758 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1759 | // | ordered | master | * | |
| 1760 | // | ordered | critical | * | |
| 1761 | // | ordered | simd | * | |
| 1762 | // | ordered | sections | + | |
| 1763 | // | ordered | section | + | |
| 1764 | // | ordered | single | + | |
| 1765 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1766 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1767 | // | ordered |parallel sections| * | |
| 1768 | // | ordered | task | * | |
| 1769 | // | ordered | taskyield | * | |
| 1770 | // | ordered | barrier | + | |
| 1771 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1772 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1773 | // | ordered | flush | * | |
| 1774 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1775 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1776 | // | ordered | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1777 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1778 | // | ordered | cancellation | | |
| 1779 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1780 | // | ordered | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1781 | // +------------------+-----------------+------------------------------------+ |
| 1782 | // | atomic | parallel | | |
| 1783 | // | atomic | for | | |
| 1784 | // | atomic | for simd | | |
| 1785 | // | atomic | master | | |
| 1786 | // | atomic | critical | | |
| 1787 | // | atomic | simd | | |
| 1788 | // | atomic | sections | | |
| 1789 | // | atomic | section | | |
| 1790 | // | atomic | single | | |
| 1791 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1792 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1793 | // | atomic |parallel sections| | |
| 1794 | // | atomic | task | | |
| 1795 | // | atomic | taskyield | | |
| 1796 | // | atomic | barrier | | |
| 1797 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1798 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1799 | // | atomic | flush | | |
| 1800 | // | atomic | ordered | | |
| 1801 | // | atomic | atomic | | |
| 1802 | // | atomic | target | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1803 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1804 | // | atomic | cancellation | | |
| 1805 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1806 | // | atomic | cancel | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1807 | // +------------------+-----------------+------------------------------------+ |
| 1808 | // | target | parallel | * | |
| 1809 | // | target | for | * | |
| 1810 | // | target | for simd | * | |
| 1811 | // | target | master | * | |
| 1812 | // | target | critical | * | |
| 1813 | // | target | simd | * | |
| 1814 | // | target | sections | * | |
| 1815 | // | target | section | * | |
| 1816 | // | target | single | * | |
| 1817 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1818 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1819 | // | target |parallel sections| * | |
| 1820 | // | target | task | * | |
| 1821 | // | target | taskyield | * | |
| 1822 | // | target | barrier | * | |
| 1823 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1824 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1825 | // | target | flush | * | |
| 1826 | // | target | ordered | * | |
| 1827 | // | target | atomic | * | |
| 1828 | // | target | target | * | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1829 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1830 | // | target | cancellation | | |
| 1831 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1832 | // | target | cancel | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1833 | // +------------------+-----------------+------------------------------------+ |
| 1834 | // | teams | parallel | * | |
| 1835 | // | teams | for | + | |
| 1836 | // | teams | for simd | + | |
| 1837 | // | teams | master | + | |
| 1838 | // | teams | critical | + | |
| 1839 | // | teams | simd | + | |
| 1840 | // | teams | sections | + | |
| 1841 | // | teams | section | + | |
| 1842 | // | teams | single | + | |
| 1843 | // | teams | parallel for | * | |
| 1844 | // | teams |parallel for simd| * | |
| 1845 | // | teams |parallel sections| * | |
| 1846 | // | teams | task | + | |
| 1847 | // | teams | taskyield | + | |
| 1848 | // | teams | barrier | + | |
| 1849 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1850 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1851 | // | teams | flush | + | |
| 1852 | // | teams | ordered | + | |
| 1853 | // | teams | atomic | + | |
| 1854 | // | teams | target | + | |
| 1855 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1856 | // | teams | cancellation | | |
| 1857 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1858 | // | teams | cancel | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1859 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1860 | if (Stack->getCurScope()) { |
| 1861 | auto ParentRegion = Stack->getParentDirective(); |
| 1862 | bool NestingProhibited = false; |
| 1863 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1864 | enum { |
| 1865 | NoRecommend, |
| 1866 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1867 | ShouldBeInOrderedRegion, |
| 1868 | ShouldBeInTargetRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1869 | } Recommend = NoRecommend; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1870 | if (isOpenMPSimdDirective(ParentRegion)) { |
| 1871 | // OpenMP [2.16, Nesting of Regions] |
| 1872 | // OpenMP constructs may not be nested inside a simd region. |
| 1873 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
| 1874 | return true; |
| 1875 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1876 | if (ParentRegion == OMPD_atomic) { |
| 1877 | // OpenMP [2.16, Nesting of Regions] |
| 1878 | // OpenMP constructs may not be nested inside an atomic region. |
| 1879 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1880 | return true; |
| 1881 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1882 | if (CurrentRegion == OMPD_section) { |
| 1883 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1884 | // Orphaned section directives are prohibited. That is, the section |
| 1885 | // directives must appear within the sections construct and must not be |
| 1886 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1887 | if (ParentRegion != OMPD_sections && |
| 1888 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1889 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1890 | << (ParentRegion != OMPD_unknown) |
| 1891 | << getOpenMPDirectiveName(ParentRegion); |
| 1892 | return true; |
| 1893 | } |
| 1894 | return false; |
| 1895 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1896 | // Allow some constructs to be orphaned (they could be used in functions, |
| 1897 | // called from OpenMP regions with the required preconditions). |
| 1898 | if (ParentRegion == OMPD_unknown) |
| 1899 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1900 | if (CurrentRegion == OMPD_cancellation_point || |
| 1901 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1902 | // OpenMP [2.16, Nesting of Regions] |
| 1903 | // A cancellation point construct for which construct-type-clause is |
| 1904 | // taskgroup must be nested inside a task construct. A cancellation |
| 1905 | // point construct for which construct-type-clause is not taskgroup must |
| 1906 | // be closely nested inside an OpenMP construct that matches the type |
| 1907 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1908 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 1909 | // nested inside a task construct. A cancel construct for which |
| 1910 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 1911 | // OpenMP construct that matches the type specified in |
| 1912 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1913 | NestingProhibited = |
| 1914 | !((CancelRegion == OMPD_parallel && ParentRegion == OMPD_parallel) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 1915 | (CancelRegion == OMPD_for && |
| 1916 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1917 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 1918 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 1919 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 1920 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1921 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1922 | // OpenMP [2.16, Nesting of Regions] |
| 1923 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1924 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1925 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 1926 | ParentRegion == OMPD_task; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1927 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 1928 | // OpenMP [2.16, Nesting of Regions] |
| 1929 | // A critical region may not be nested (closely or otherwise) inside a |
| 1930 | // critical region with the same name. Note that this restriction is not |
| 1931 | // sufficient to prevent deadlock. |
| 1932 | SourceLocation PreviousCriticalLoc; |
| 1933 | bool DeadLock = |
| 1934 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 1935 | OpenMPDirectiveKind K, |
| 1936 | const DeclarationNameInfo &DNI, |
| 1937 | SourceLocation Loc) |
| 1938 | ->bool { |
| 1939 | if (K == OMPD_critical && |
| 1940 | DNI.getName() == CurrentName.getName()) { |
| 1941 | PreviousCriticalLoc = Loc; |
| 1942 | return true; |
| 1943 | } else |
| 1944 | return false; |
| 1945 | }, |
| 1946 | false /* skip top directive */); |
| 1947 | if (DeadLock) { |
| 1948 | SemaRef.Diag(StartLoc, |
| 1949 | diag::err_omp_prohibited_region_critical_same_name) |
| 1950 | << CurrentName.getName(); |
| 1951 | if (PreviousCriticalLoc.isValid()) |
| 1952 | SemaRef.Diag(PreviousCriticalLoc, |
| 1953 | diag::note_omp_previous_critical_region); |
| 1954 | return true; |
| 1955 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1956 | } else if (CurrentRegion == OMPD_barrier) { |
| 1957 | // OpenMP [2.16, Nesting of Regions] |
| 1958 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1959 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1960 | NestingProhibited = |
| 1961 | isOpenMPWorksharingDirective(ParentRegion) || |
| 1962 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1963 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1964 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1965 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1966 | // OpenMP [2.16, Nesting of Regions] |
| 1967 | // A worksharing region may not be closely nested inside a worksharing, |
| 1968 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1969 | NestingProhibited = |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1970 | isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1971 | ParentRegion == OMPD_task || ParentRegion == OMPD_master || |
| 1972 | ParentRegion == OMPD_critical || ParentRegion == OMPD_ordered; |
| 1973 | Recommend = ShouldBeInParallelRegion; |
| 1974 | } else if (CurrentRegion == OMPD_ordered) { |
| 1975 | // OpenMP [2.16, Nesting of Regions] |
| 1976 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1977 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1978 | // An ordered region must be closely nested inside a loop region (or |
| 1979 | // parallel loop region) with an ordered clause. |
| 1980 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1981 | ParentRegion == OMPD_task || |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1982 | !Stack->isParentOrderedRegion(); |
| 1983 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1984 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 1985 | // OpenMP [2.16, Nesting of Regions] |
| 1986 | // If specified, a teams construct must be contained within a target |
| 1987 | // construct. |
| 1988 | NestingProhibited = ParentRegion != OMPD_target; |
| 1989 | Recommend = ShouldBeInTargetRegion; |
| 1990 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 1991 | } |
| 1992 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 1993 | // OpenMP [2.16, Nesting of Regions] |
| 1994 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 1995 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 1996 | // constructs that can be closely nested in the teams region. |
| 1997 | // TODO: add distribute directive. |
| 1998 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion); |
| 1999 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2000 | } |
| 2001 | if (NestingProhibited) { |
| 2002 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2003 | << CloseNesting << getOpenMPDirectiveName(ParentRegion) << Recommend |
| 2004 | << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2005 | return true; |
| 2006 | } |
| 2007 | } |
| 2008 | return false; |
| 2009 | } |
| 2010 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2011 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2012 | ArrayRef<OMPClause *> Clauses, |
| 2013 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2014 | bool ErrorFound = false; |
| 2015 | unsigned NamedModifiersNumber = 0; |
| 2016 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2017 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2018 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2019 | for (const auto *C : Clauses) { |
| 2020 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2021 | // At most one if clause without a directive-name-modifier can appear on |
| 2022 | // the directive. |
| 2023 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2024 | if (FoundNameModifiers[CurNM]) { |
| 2025 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2026 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2027 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2028 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2029 | } else if (CurNM != OMPD_unknown) { |
| 2030 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2031 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2032 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2033 | FoundNameModifiers[CurNM] = IC; |
| 2034 | if (CurNM == OMPD_unknown) |
| 2035 | continue; |
| 2036 | // Check if the specified name modifier is allowed for the current |
| 2037 | // directive. |
| 2038 | // At most one if clause with the particular directive-name-modifier can |
| 2039 | // appear on the directive. |
| 2040 | bool MatchFound = false; |
| 2041 | for (auto NM : AllowedNameModifiers) { |
| 2042 | if (CurNM == NM) { |
| 2043 | MatchFound = true; |
| 2044 | break; |
| 2045 | } |
| 2046 | } |
| 2047 | if (!MatchFound) { |
| 2048 | S.Diag(IC->getNameModifierLoc(), |
| 2049 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2050 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2051 | ErrorFound = true; |
| 2052 | } |
| 2053 | } |
| 2054 | } |
| 2055 | // If any if clause on the directive includes a directive-name-modifier then |
| 2056 | // all if clauses on the directive must include a directive-name-modifier. |
| 2057 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2058 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2059 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2060 | diag::err_omp_no_more_if_clause); |
| 2061 | } else { |
| 2062 | std::string Values; |
| 2063 | std::string Sep(", "); |
| 2064 | unsigned AllowedCnt = 0; |
| 2065 | unsigned TotalAllowedNum = |
| 2066 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2067 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2068 | ++Cnt) { |
| 2069 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2070 | if (!FoundNameModifiers[NM]) { |
| 2071 | Values += "'"; |
| 2072 | Values += getOpenMPDirectiveName(NM); |
| 2073 | Values += "'"; |
| 2074 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2075 | Values += " or "; |
| 2076 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2077 | Values += Sep; |
| 2078 | ++AllowedCnt; |
| 2079 | } |
| 2080 | } |
| 2081 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2082 | diag::err_omp_unnamed_if_clause) |
| 2083 | << (TotalAllowedNum > 1) << Values; |
| 2084 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2085 | for (auto Loc : NameModifierLoc) { |
| 2086 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2087 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2088 | ErrorFound = true; |
| 2089 | } |
| 2090 | return ErrorFound; |
| 2091 | } |
| 2092 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2093 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2094 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2095 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2096 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2097 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2098 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2099 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2100 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2101 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2102 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2103 | llvm::DenseMap<VarDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2104 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2105 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2106 | if (AStmt) { |
| 2107 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2108 | |
| 2109 | // Check default data sharing attributes for referenced variables. |
| 2110 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2111 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2112 | if (DSAChecker.isErrorFound()) |
| 2113 | return StmtError(); |
| 2114 | // Generate list of implicitly defined firstprivate variables. |
| 2115 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2116 | |
| 2117 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2118 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2119 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2120 | SourceLocation(), SourceLocation())) { |
| 2121 | ClausesWithImplicit.push_back(Implicit); |
| 2122 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2123 | DSAChecker.getImplicitFirstprivate().size(); |
| 2124 | } else |
| 2125 | ErrorFound = true; |
| 2126 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2127 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2128 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2129 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2130 | switch (Kind) { |
| 2131 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2132 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2133 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2134 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2135 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2136 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2137 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2138 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2139 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2140 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2141 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2142 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2143 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2144 | case OMPD_for_simd: |
| 2145 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2146 | EndLoc, VarsWithInheritedDSA); |
| 2147 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2148 | case OMPD_sections: |
| 2149 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2150 | EndLoc); |
| 2151 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2152 | case OMPD_section: |
| 2153 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2154 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2155 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2156 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2157 | case OMPD_single: |
| 2158 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2159 | EndLoc); |
| 2160 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2161 | case OMPD_master: |
| 2162 | assert(ClausesWithImplicit.empty() && |
| 2163 | "No clauses are allowed for 'omp master' directive"); |
| 2164 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2165 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2166 | case OMPD_critical: |
| 2167 | assert(ClausesWithImplicit.empty() && |
| 2168 | "No clauses are allowed for 'omp critical' directive"); |
| 2169 | Res = ActOnOpenMPCriticalDirective(DirName, AStmt, StartLoc, EndLoc); |
| 2170 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2171 | case OMPD_parallel_for: |
| 2172 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2173 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2174 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2175 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2176 | case OMPD_parallel_for_simd: |
| 2177 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2178 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2179 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2180 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2181 | case OMPD_parallel_sections: |
| 2182 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2183 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2184 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2185 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2186 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2187 | Res = |
| 2188 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2189 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2190 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2191 | case OMPD_taskyield: |
| 2192 | assert(ClausesWithImplicit.empty() && |
| 2193 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2194 | assert(AStmt == nullptr && |
| 2195 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2196 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2197 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2198 | case OMPD_barrier: |
| 2199 | assert(ClausesWithImplicit.empty() && |
| 2200 | "No clauses are allowed for 'omp barrier' directive"); |
| 2201 | assert(AStmt == nullptr && |
| 2202 | "No associated statement allowed for 'omp barrier' directive"); |
| 2203 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2204 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2205 | case OMPD_taskwait: |
| 2206 | assert(ClausesWithImplicit.empty() && |
| 2207 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2208 | assert(AStmt == nullptr && |
| 2209 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2210 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2211 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2212 | case OMPD_taskgroup: |
| 2213 | assert(ClausesWithImplicit.empty() && |
| 2214 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2215 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2216 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2217 | case OMPD_flush: |
| 2218 | assert(AStmt == nullptr && |
| 2219 | "No associated statement allowed for 'omp flush' directive"); |
| 2220 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2221 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2222 | case OMPD_ordered: |
| 2223 | assert(ClausesWithImplicit.empty() && |
| 2224 | "No clauses are allowed for 'omp ordered' directive"); |
| 2225 | Res = ActOnOpenMPOrderedDirective(AStmt, StartLoc, EndLoc); |
| 2226 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2227 | case OMPD_atomic: |
| 2228 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2229 | EndLoc); |
| 2230 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2231 | case OMPD_teams: |
| 2232 | Res = |
| 2233 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2234 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2235 | case OMPD_target: |
| 2236 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2237 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2238 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2239 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2240 | case OMPD_cancellation_point: |
| 2241 | assert(ClausesWithImplicit.empty() && |
| 2242 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2243 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2244 | "cancellation point' directive"); |
| 2245 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2246 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2247 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2248 | assert(AStmt == nullptr && |
| 2249 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2250 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2251 | CancelRegion); |
| 2252 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2253 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2254 | case OMPD_target_data: |
| 2255 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2256 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2257 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2258 | break; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2259 | case OMPD_threadprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2260 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2261 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2262 | llvm_unreachable("Unknown OpenMP directive"); |
| 2263 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2264 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2265 | for (auto P : VarsWithInheritedDSA) { |
| 2266 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2267 | << P.first << P.second->getSourceRange(); |
| 2268 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2269 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2270 | |
| 2271 | if (!AllowedNameModifiers.empty()) |
| 2272 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2273 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2274 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2275 | if (ErrorFound) |
| 2276 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2277 | return Res; |
| 2278 | } |
| 2279 | |
| 2280 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2281 | Stmt *AStmt, |
| 2282 | SourceLocation StartLoc, |
| 2283 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2284 | if (!AStmt) |
| 2285 | return StmtError(); |
| 2286 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2287 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2288 | // 1.2.2 OpenMP Language Terminology |
| 2289 | // Structured block - An executable statement with a single entry at the |
| 2290 | // top and a single exit at the bottom. |
| 2291 | // The point of exit cannot be a branch out of the structured block. |
| 2292 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2293 | CS->getCapturedDecl()->setNothrow(); |
| 2294 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2295 | getCurFunction()->setHasBranchProtectedScope(); |
| 2296 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2297 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2298 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2301 | namespace { |
| 2302 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2303 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2304 | /// for IR generation. |
| 2305 | class OpenMPIterationSpaceChecker { |
| 2306 | /// \brief Reference to Sema. |
| 2307 | Sema &SemaRef; |
| 2308 | /// \brief A location for diagnostics (when there is no some better location). |
| 2309 | SourceLocation DefaultLoc; |
| 2310 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2311 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2312 | /// \brief A source location for referring to loop init later. |
| 2313 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2314 | /// \brief A source location for referring to condition later. |
| 2315 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2316 | /// \brief A source location for referring to increment later. |
| 2317 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2318 | /// \brief Loop variable. |
| 2319 | VarDecl *Var; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2320 | /// \brief Reference to loop variable. |
| 2321 | DeclRefExpr *VarRef; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2322 | /// \brief Lower bound (initializer for the var). |
| 2323 | Expr *LB; |
| 2324 | /// \brief Upper bound. |
| 2325 | Expr *UB; |
| 2326 | /// \brief Loop step (increment). |
| 2327 | Expr *Step; |
| 2328 | /// \brief This flag is true when condition is one of: |
| 2329 | /// Var < UB |
| 2330 | /// Var <= UB |
| 2331 | /// UB > Var |
| 2332 | /// UB >= Var |
| 2333 | bool TestIsLessOp; |
| 2334 | /// \brief This flag is true when condition is strict ( < or > ). |
| 2335 | bool TestIsStrictOp; |
| 2336 | /// \brief This flag is true when step is subtracted on each iteration. |
| 2337 | bool SubtractStep; |
| 2338 | |
| 2339 | public: |
| 2340 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
| 2341 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2342 | InitSrcRange(SourceRange()), ConditionSrcRange(SourceRange()), |
| 2343 | IncrementSrcRange(SourceRange()), Var(nullptr), VarRef(nullptr), |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2344 | LB(nullptr), UB(nullptr), Step(nullptr), TestIsLessOp(false), |
| 2345 | TestIsStrictOp(false), SubtractStep(false) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2346 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2347 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2348 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2349 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2350 | /// for less/greater and for strict/non-strict comparison. |
| 2351 | bool CheckCond(Expr *S); |
| 2352 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2353 | /// does not conform, otherwise save loop step (#Step). |
| 2354 | bool CheckInc(Expr *S); |
| 2355 | /// \brief Return the loop counter variable. |
| 2356 | VarDecl *GetLoopVar() const { return Var; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2357 | /// \brief Return the reference expression to loop counter variable. |
| 2358 | DeclRefExpr *GetLoopVarRefExpr() const { return VarRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2359 | /// \brief Source range of the loop init. |
| 2360 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2361 | /// \brief Source range of the loop condition. |
| 2362 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2363 | /// \brief Source range of the loop increment. |
| 2364 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2365 | /// \brief True if the step should be subtracted. |
| 2366 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2367 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2368 | Expr *BuildNumIterations(Scope *S, const bool LimitedType) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2369 | /// \brief Build the precondition expression for the loops. |
| 2370 | Expr *BuildPreCond(Scope *S, Expr *Cond) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2371 | /// \brief Build reference expression to the counter be used for codegen. |
| 2372 | Expr *BuildCounterVar() const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2373 | /// \brief Build reference expression to the private counter be used for |
| 2374 | /// codegen. |
| 2375 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2376 | /// \brief Build initization of the counter be used for codegen. |
| 2377 | Expr *BuildCounterInit() const; |
| 2378 | /// \brief Build step of the counter be used for codegen. |
| 2379 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2380 | /// \brief Return true if any expression is dependent. |
| 2381 | bool Dependent() const; |
| 2382 | |
| 2383 | private: |
| 2384 | /// \brief Check the right-hand side of an assignment in the increment |
| 2385 | /// expression. |
| 2386 | bool CheckIncRHS(Expr *RHS); |
| 2387 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2388 | bool SetVarAndLB(VarDecl *NewVar, DeclRefExpr *NewVarRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2389 | /// \brief Helper to set upper bound. |
| 2390 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, const SourceRange &SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame^] | 2391 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2392 | /// \brief Helper to set loop increment. |
| 2393 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2394 | }; |
| 2395 | |
| 2396 | bool OpenMPIterationSpaceChecker::Dependent() const { |
| 2397 | if (!Var) { |
| 2398 | assert(!LB && !UB && !Step); |
| 2399 | return false; |
| 2400 | } |
| 2401 | return Var->getType()->isDependentType() || (LB && LB->isValueDependent()) || |
| 2402 | (UB && UB->isValueDependent()) || (Step && Step->isValueDependent()); |
| 2403 | } |
| 2404 | |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2405 | template <typename T> |
| 2406 | static T *getExprAsWritten(T *E) { |
| 2407 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2408 | E = ExprTemp->getSubExpr(); |
| 2409 | |
| 2410 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2411 | E = MTE->GetTemporaryExpr(); |
| 2412 | |
| 2413 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2414 | E = Binder->getSubExpr(); |
| 2415 | |
| 2416 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2417 | E = ICE->getSubExprAsWritten(); |
| 2418 | return E->IgnoreParens(); |
| 2419 | } |
| 2420 | |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2421 | bool OpenMPIterationSpaceChecker::SetVarAndLB(VarDecl *NewVar, |
| 2422 | DeclRefExpr *NewVarRefExpr, |
| 2423 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2424 | // State consistency checking to ensure correct usage. |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2425 | assert(Var == nullptr && LB == nullptr && VarRef == nullptr && |
| 2426 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2427 | if (!NewVar || !NewLB) |
| 2428 | return true; |
| 2429 | Var = NewVar; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2430 | VarRef = NewVarRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2431 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2432 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2433 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2434 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2435 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2436 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2437 | LB = NewLB; |
| 2438 | return false; |
| 2439 | } |
| 2440 | |
| 2441 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
| 2442 | const SourceRange &SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame^] | 2443 | SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2444 | // State consistency checking to ensure correct usage. |
| 2445 | assert(Var != nullptr && LB != nullptr && UB == nullptr && Step == nullptr && |
| 2446 | !TestIsLessOp && !TestIsStrictOp); |
| 2447 | if (!NewUB) |
| 2448 | return true; |
| 2449 | UB = NewUB; |
| 2450 | TestIsLessOp = LessOp; |
| 2451 | TestIsStrictOp = StrictOp; |
| 2452 | ConditionSrcRange = SR; |
| 2453 | ConditionLoc = SL; |
| 2454 | return false; |
| 2455 | } |
| 2456 | |
| 2457 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2458 | // State consistency checking to ensure correct usage. |
| 2459 | assert(Var != nullptr && LB != nullptr && Step == nullptr); |
| 2460 | if (!NewStep) |
| 2461 | return true; |
| 2462 | if (!NewStep->isValueDependent()) { |
| 2463 | // Check that the step is integer expression. |
| 2464 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2465 | ExprResult Val = |
| 2466 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2467 | if (Val.isInvalid()) |
| 2468 | return true; |
| 2469 | NewStep = Val.get(); |
| 2470 | |
| 2471 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2472 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2473 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2474 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2475 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2476 | // the loop. |
| 2477 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2478 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2479 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2480 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2481 | // the loop. |
| 2482 | llvm::APSInt Result; |
| 2483 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2484 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2485 | bool IsConstNeg = |
| 2486 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2487 | bool IsConstPos = |
| 2488 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2489 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2490 | if (UB && (IsConstZero || |
| 2491 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2492 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2493 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2494 | diag::err_omp_loop_incr_not_compatible) |
| 2495 | << Var << TestIsLessOp << NewStep->getSourceRange(); |
| 2496 | SemaRef.Diag(ConditionLoc, |
| 2497 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 2498 | << TestIsLessOp << ConditionSrcRange; |
| 2499 | return true; |
| 2500 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2501 | if (TestIsLessOp == Subtract) { |
| 2502 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 2503 | NewStep).get(); |
| 2504 | Subtract = !Subtract; |
| 2505 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | Step = NewStep; |
| 2509 | SubtractStep = Subtract; |
| 2510 | return false; |
| 2511 | } |
| 2512 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2513 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2514 | // Check init-expr for canonical loop form and save loop counter |
| 2515 | // variable - #Var and its initialization value - #LB. |
| 2516 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 2517 | // var = lb |
| 2518 | // integer-type var = lb |
| 2519 | // random-access-iterator-type var = lb |
| 2520 | // pointer-type var = lb |
| 2521 | // |
| 2522 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2523 | if (EmitDiags) { |
| 2524 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 2525 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2526 | return true; |
| 2527 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2528 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2529 | if (Expr *E = dyn_cast<Expr>(S)) |
| 2530 | S = E->IgnoreParens(); |
| 2531 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2532 | if (BO->getOpcode() == BO_Assign) |
| 2533 | if (auto DRE = dyn_cast<DeclRefExpr>(BO->getLHS()->IgnoreParens())) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2534 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2535 | BO->getRHS()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2536 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 2537 | if (DS->isSingleDecl()) { |
| 2538 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2539 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2540 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2541 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2542 | SemaRef.Diag(S->getLocStart(), |
| 2543 | diag::ext_omp_loop_not_canonical_init) |
| 2544 | << S->getSourceRange(); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2545 | return SetVarAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | } |
| 2549 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) |
| 2550 | if (CE->getOperator() == OO_Equal) |
| 2551 | if (auto DRE = dyn_cast<DeclRefExpr>(CE->getArg(0))) |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2552 | return SetVarAndLB(dyn_cast<VarDecl>(DRE->getDecl()), DRE, |
| 2553 | CE->getArg(1)); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2554 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2555 | if (EmitDiags) { |
| 2556 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 2557 | << S->getSourceRange(); |
| 2558 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2559 | return true; |
| 2560 | } |
| 2561 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2562 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2563 | /// variable (which may be the loop variable) if possible. |
| 2564 | static const VarDecl *GetInitVarDecl(const Expr *E) { |
| 2565 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 2566 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2567 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2568 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 2569 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2570 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2571 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2572 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2573 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
| 2574 | auto DRE = dyn_cast_or_null<DeclRefExpr>(E); |
| 2575 | if (!DRE) |
| 2576 | return nullptr; |
| 2577 | return dyn_cast<VarDecl>(DRE->getDecl()); |
| 2578 | } |
| 2579 | |
| 2580 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 2581 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 2582 | // less/greater and for strict/non-strict comparison. |
| 2583 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2584 | // var relational-op b |
| 2585 | // b relational-op var |
| 2586 | // |
| 2587 | if (!S) { |
| 2588 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << Var; |
| 2589 | return true; |
| 2590 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2591 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2592 | SourceLocation CondLoc = S->getLocStart(); |
| 2593 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2594 | if (BO->isRelationalOp()) { |
| 2595 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2596 | return SetUB(BO->getRHS(), |
| 2597 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 2598 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2599 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2600 | if (GetInitVarDecl(BO->getRHS()) == Var) |
| 2601 | return SetUB(BO->getLHS(), |
| 2602 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 2603 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 2604 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 2605 | } |
| 2606 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2607 | if (CE->getNumArgs() == 2) { |
| 2608 | auto Op = CE->getOperator(); |
| 2609 | switch (Op) { |
| 2610 | case OO_Greater: |
| 2611 | case OO_GreaterEqual: |
| 2612 | case OO_Less: |
| 2613 | case OO_LessEqual: |
| 2614 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2615 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 2616 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2617 | CE->getOperatorLoc()); |
| 2618 | if (GetInitVarDecl(CE->getArg(1)) == Var) |
| 2619 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 2620 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 2621 | CE->getOperatorLoc()); |
| 2622 | break; |
| 2623 | default: |
| 2624 | break; |
| 2625 | } |
| 2626 | } |
| 2627 | } |
| 2628 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
| 2629 | << S->getSourceRange() << Var; |
| 2630 | return true; |
| 2631 | } |
| 2632 | |
| 2633 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 2634 | // RHS of canonical loop form increment can be: |
| 2635 | // var + incr |
| 2636 | // incr + var |
| 2637 | // var - incr |
| 2638 | // |
| 2639 | RHS = RHS->IgnoreParenImpCasts(); |
| 2640 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 2641 | if (BO->isAdditiveOp()) { |
| 2642 | bool IsAdd = BO->getOpcode() == BO_Add; |
| 2643 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2644 | return SetStep(BO->getRHS(), !IsAdd); |
| 2645 | if (IsAdd && GetInitVarDecl(BO->getRHS()) == Var) |
| 2646 | return SetStep(BO->getLHS(), false); |
| 2647 | } |
| 2648 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 2649 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 2650 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
| 2651 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2652 | return SetStep(CE->getArg(1), !IsAdd); |
| 2653 | if (IsAdd && GetInitVarDecl(CE->getArg(1)) == Var) |
| 2654 | return SetStep(CE->getArg(0), false); |
| 2655 | } |
| 2656 | } |
| 2657 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2658 | << RHS->getSourceRange() << Var; |
| 2659 | return true; |
| 2660 | } |
| 2661 | |
| 2662 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 2663 | // Check incr-expr for canonical loop form and return true if it |
| 2664 | // does not conform. |
| 2665 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 2666 | // ++var |
| 2667 | // var++ |
| 2668 | // --var |
| 2669 | // var-- |
| 2670 | // var += incr |
| 2671 | // var -= incr |
| 2672 | // var = var + incr |
| 2673 | // var = incr + var |
| 2674 | // var = var - incr |
| 2675 | // |
| 2676 | if (!S) { |
| 2677 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << Var; |
| 2678 | return true; |
| 2679 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2680 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2681 | S = S->IgnoreParens(); |
| 2682 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
| 2683 | if (UO->isIncrementDecrementOp() && GetInitVarDecl(UO->getSubExpr()) == Var) |
| 2684 | return SetStep( |
| 2685 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 2686 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 2687 | false); |
| 2688 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 2689 | switch (BO->getOpcode()) { |
| 2690 | case BO_AddAssign: |
| 2691 | case BO_SubAssign: |
| 2692 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2693 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 2694 | break; |
| 2695 | case BO_Assign: |
| 2696 | if (GetInitVarDecl(BO->getLHS()) == Var) |
| 2697 | return CheckIncRHS(BO->getRHS()); |
| 2698 | break; |
| 2699 | default: |
| 2700 | break; |
| 2701 | } |
| 2702 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 2703 | switch (CE->getOperator()) { |
| 2704 | case OO_PlusPlus: |
| 2705 | case OO_MinusMinus: |
| 2706 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2707 | return SetStep( |
| 2708 | SemaRef.ActOnIntegerConstant( |
| 2709 | CE->getLocStart(), |
| 2710 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 2711 | false); |
| 2712 | break; |
| 2713 | case OO_PlusEqual: |
| 2714 | case OO_MinusEqual: |
| 2715 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2716 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 2717 | break; |
| 2718 | case OO_Equal: |
| 2719 | if (GetInitVarDecl(CE->getArg(0)) == Var) |
| 2720 | return CheckIncRHS(CE->getArg(1)); |
| 2721 | break; |
| 2722 | default: |
| 2723 | break; |
| 2724 | } |
| 2725 | } |
| 2726 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
| 2727 | << S->getSourceRange() << Var; |
| 2728 | return true; |
| 2729 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2730 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2731 | namespace { |
| 2732 | // Transform variables declared in GNU statement expressions to new ones to |
| 2733 | // avoid crash on codegen. |
| 2734 | class TransformToNewDefs : public TreeTransform<TransformToNewDefs> { |
| 2735 | typedef TreeTransform<TransformToNewDefs> BaseTransform; |
| 2736 | |
| 2737 | public: |
| 2738 | TransformToNewDefs(Sema &SemaRef) : BaseTransform(SemaRef) {} |
| 2739 | |
| 2740 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 2741 | if (auto *VD = cast<VarDecl>(D)) |
| 2742 | if (!isa<ParmVarDecl>(D) && !isa<VarTemplateSpecializationDecl>(D) && |
| 2743 | !isa<ImplicitParamDecl>(D)) { |
| 2744 | auto *NewVD = VarDecl::Create( |
| 2745 | SemaRef.Context, VD->getDeclContext(), VD->getLocStart(), |
| 2746 | VD->getLocation(), VD->getIdentifier(), VD->getType(), |
| 2747 | VD->getTypeSourceInfo(), VD->getStorageClass()); |
| 2748 | NewVD->setTSCSpec(VD->getTSCSpec()); |
| 2749 | NewVD->setInit(VD->getInit()); |
| 2750 | NewVD->setInitStyle(VD->getInitStyle()); |
| 2751 | NewVD->setExceptionVariable(VD->isExceptionVariable()); |
| 2752 | NewVD->setNRVOVariable(VD->isNRVOVariable()); |
| 2753 | NewVD->setCXXForRangeDecl(VD->isInExternCXXContext()); |
| 2754 | NewVD->setConstexpr(VD->isConstexpr()); |
| 2755 | NewVD->setInitCapture(VD->isInitCapture()); |
| 2756 | NewVD->setPreviousDeclInSameBlockScope( |
| 2757 | VD->isPreviousDeclInSameBlockScope()); |
| 2758 | VD->getDeclContext()->addHiddenDecl(NewVD); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 2759 | if (VD->hasAttrs()) |
| 2760 | NewVD->setAttrs(VD->getAttrs()); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2761 | transformedLocalDecl(VD, NewVD); |
| 2762 | return NewVD; |
| 2763 | } |
| 2764 | return BaseTransform::TransformDefinition(Loc, D); |
| 2765 | } |
| 2766 | |
| 2767 | ExprResult TransformDeclRefExpr(DeclRefExpr *E) { |
| 2768 | if (auto *NewD = TransformDecl(E->getExprLoc(), E->getDecl())) |
| 2769 | if (E->getDecl() != NewD) { |
| 2770 | NewD->setReferenced(); |
| 2771 | NewD->markUsed(SemaRef.Context); |
| 2772 | return DeclRefExpr::Create( |
| 2773 | SemaRef.Context, E->getQualifierLoc(), E->getTemplateKeywordLoc(), |
| 2774 | cast<ValueDecl>(NewD), E->refersToEnclosingVariableOrCapture(), |
| 2775 | E->getNameInfo(), E->getType(), E->getValueKind()); |
| 2776 | } |
| 2777 | return BaseTransform::TransformDeclRefExpr(E); |
| 2778 | } |
| 2779 | }; |
| 2780 | } |
| 2781 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2782 | /// \brief Build the expression to calculate the number of iterations. |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2783 | Expr * |
| 2784 | OpenMPIterationSpaceChecker::BuildNumIterations(Scope *S, |
| 2785 | const bool LimitedType) const { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2786 | TransformToNewDefs Transform(SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2787 | ExprResult Diff; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2788 | auto VarType = Var->getType().getNonReferenceType(); |
| 2789 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2790 | SemaRef.getLangOpts().CPlusPlus) { |
| 2791 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2792 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 2793 | auto *LBExpr = TestIsLessOp ? LB : UB; |
| 2794 | Expr *Upper = Transform.TransformExpr(UBExpr).get(); |
| 2795 | Expr *Lower = Transform.TransformExpr(LBExpr).get(); |
| 2796 | if (!Upper || !Lower) |
| 2797 | return nullptr; |
| 2798 | Upper = SemaRef.PerformImplicitConversion(Upper, UBExpr->getType(), |
| 2799 | Sema::AA_Converting, |
| 2800 | /*AllowExplicit=*/true) |
| 2801 | .get(); |
| 2802 | Lower = SemaRef.PerformImplicitConversion(Lower, LBExpr->getType(), |
| 2803 | Sema::AA_Converting, |
| 2804 | /*AllowExplicit=*/true) |
| 2805 | .get(); |
| 2806 | if (!Upper || !Lower) |
| 2807 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2808 | |
| 2809 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 2810 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2811 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2812 | // BuildBinOp already emitted error, this one is to point user to upper |
| 2813 | // and lower bound, and to tell what is passed to 'operator-'. |
| 2814 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 2815 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 2816 | return nullptr; |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | if (!Diff.isUsable()) |
| 2821 | return nullptr; |
| 2822 | |
| 2823 | // Upper - Lower [- 1] |
| 2824 | if (TestIsStrictOp) |
| 2825 | Diff = SemaRef.BuildBinOp( |
| 2826 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 2827 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 2828 | if (!Diff.isUsable()) |
| 2829 | return nullptr; |
| 2830 | |
| 2831 | // Upper - Lower [- 1] + Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2832 | auto NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2833 | if (NewStep.isInvalid()) |
| 2834 | return nullptr; |
| 2835 | NewStep = SemaRef.PerformImplicitConversion( |
| 2836 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2837 | /*AllowExplicit=*/true); |
| 2838 | if (NewStep.isInvalid()) |
| 2839 | return nullptr; |
| 2840 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2841 | if (!Diff.isUsable()) |
| 2842 | return nullptr; |
| 2843 | |
| 2844 | // Parentheses (for dumping/debugging purposes only). |
| 2845 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 2846 | if (!Diff.isUsable()) |
| 2847 | return nullptr; |
| 2848 | |
| 2849 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2850 | NewStep = Transform.TransformExpr(Step->IgnoreImplicit()); |
| 2851 | if (NewStep.isInvalid()) |
| 2852 | return nullptr; |
| 2853 | NewStep = SemaRef.PerformImplicitConversion( |
| 2854 | NewStep.get(), Step->IgnoreImplicit()->getType(), Sema::AA_Converting, |
| 2855 | /*AllowExplicit=*/true); |
| 2856 | if (NewStep.isInvalid()) |
| 2857 | return nullptr; |
| 2858 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2859 | if (!Diff.isUsable()) |
| 2860 | return nullptr; |
| 2861 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2862 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2863 | QualType Type = Diff.get()->getType(); |
| 2864 | auto &C = SemaRef.Context; |
| 2865 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 2866 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 2867 | if (!Type->isIntegerType() || UseVarType) { |
| 2868 | unsigned NewSize = |
| 2869 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 2870 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 2871 | : Type->hasSignedIntegerRepresentation(); |
| 2872 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
| 2873 | Diff = SemaRef.PerformImplicitConversion( |
| 2874 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 2875 | if (!Diff.isUsable()) |
| 2876 | return nullptr; |
| 2877 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2878 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2879 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 2880 | if (NewSize != C.getTypeSize(Type)) { |
| 2881 | if (NewSize < C.getTypeSize(Type)) { |
| 2882 | assert(NewSize == 64 && "incorrect loop var size"); |
| 2883 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 2884 | << InitSrcRange << ConditionSrcRange; |
| 2885 | } |
| 2886 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2887 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 2888 | C.getTypeSize(Type) < NewSize); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 2889 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 2890 | Sema::AA_Converting, true); |
| 2891 | if (!Diff.isUsable()) |
| 2892 | return nullptr; |
| 2893 | } |
| 2894 | } |
| 2895 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2896 | return Diff.get(); |
| 2897 | } |
| 2898 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2899 | Expr *OpenMPIterationSpaceChecker::BuildPreCond(Scope *S, Expr *Cond) const { |
| 2900 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 2901 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 2902 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2903 | TransformToNewDefs Transform(SemaRef); |
| 2904 | |
| 2905 | auto NewLB = Transform.TransformExpr(LB); |
| 2906 | auto NewUB = Transform.TransformExpr(UB); |
| 2907 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 2908 | return Cond; |
| 2909 | NewLB = SemaRef.PerformImplicitConversion(NewLB.get(), LB->getType(), |
| 2910 | Sema::AA_Converting, |
| 2911 | /*AllowExplicit=*/true); |
| 2912 | NewUB = SemaRef.PerformImplicitConversion(NewUB.get(), UB->getType(), |
| 2913 | Sema::AA_Converting, |
| 2914 | /*AllowExplicit=*/true); |
| 2915 | if (NewLB.isInvalid() || NewUB.isInvalid()) |
| 2916 | return Cond; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2917 | auto CondExpr = SemaRef.BuildBinOp( |
| 2918 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 2919 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 2920 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2921 | if (CondExpr.isUsable()) { |
| 2922 | CondExpr = SemaRef.PerformImplicitConversion( |
| 2923 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 2924 | /*AllowExplicit=*/true); |
| 2925 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2926 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 2927 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 2928 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 2929 | } |
| 2930 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2931 | /// \brief Build reference expression to the counter be used for codegen. |
| 2932 | Expr *OpenMPIterationSpaceChecker::BuildCounterVar() const { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2933 | return buildDeclRefExpr(SemaRef, Var, Var->getType().getNonReferenceType(), |
| 2934 | DefaultLoc); |
| 2935 | } |
| 2936 | |
| 2937 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
| 2938 | if (Var && !Var->isInvalidDecl()) { |
| 2939 | auto Type = Var->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 2940 | auto *PrivateVar = |
| 2941 | buildVarDecl(SemaRef, DefaultLoc, Type, Var->getName(), |
| 2942 | Var->hasAttrs() ? &Var->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2943 | if (PrivateVar->isInvalidDecl()) |
| 2944 | return nullptr; |
| 2945 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 2946 | } |
| 2947 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
| 2950 | /// \brief Build initization of the counter be used for codegen. |
| 2951 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 2952 | |
| 2953 | /// \brief Build step of the counter be used for codegen. |
| 2954 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 2955 | |
| 2956 | /// \brief Iteration space of a single for loop. |
| 2957 | struct LoopIterationSpace { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2958 | /// \brief Condition of the loop. |
| 2959 | Expr *PreCond; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2960 | /// \brief This expression calculates the number of iterations in the loop. |
| 2961 | /// It is always possible to calculate it before starting the loop. |
| 2962 | Expr *NumIterations; |
| 2963 | /// \brief The loop counter variable. |
| 2964 | Expr *CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2965 | /// \brief Private loop counter variable. |
| 2966 | Expr *PrivateCounterVar; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2967 | /// \brief This is initializer for the initial value of #CounterVar. |
| 2968 | Expr *CounterInit; |
| 2969 | /// \brief This is step for the #CounterVar used to generate its update: |
| 2970 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
| 2971 | Expr *CounterStep; |
| 2972 | /// \brief Should step be subtracted? |
| 2973 | bool Subtract; |
| 2974 | /// \brief Source range of the loop init. |
| 2975 | SourceRange InitSrcRange; |
| 2976 | /// \brief Source range of the loop condition. |
| 2977 | SourceRange CondSrcRange; |
| 2978 | /// \brief Source range of the loop increment. |
| 2979 | SourceRange IncSrcRange; |
| 2980 | }; |
| 2981 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2982 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2983 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2984 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 2985 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 2986 | assert(Init && "Expected loop in canonical form."); |
| 2987 | unsigned CollapseIteration = DSAStack->getCollapseNumber(); |
| 2988 | if (CollapseIteration > 0 && |
| 2989 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 2990 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
| 2991 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 2992 | DSAStack->addLoopControlVariable(ISC.GetLoopVar()); |
| 2993 | } |
| 2994 | DSAStack->setCollapseNumber(CollapseIteration - 1); |
| 2995 | } |
| 2996 | } |
| 2997 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2998 | /// \brief Called on a for stmt to check and extract its iteration space |
| 2999 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3000 | static bool CheckOpenMPIterationSpace( |
| 3001 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3002 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3003 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3004 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
| 3005 | LoopIterationSpace &ResultIterSpace) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3006 | // OpenMP [2.6, Canonical Loop Form] |
| 3007 | // for (init-expr; test-expr; incr-expr) structured-block |
| 3008 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 3009 | if (!For) { |
| 3010 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3011 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3012 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3013 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3014 | if (NestedLoopCount > 1) { |
| 3015 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3016 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3017 | diag::note_omp_collapse_ordered_expr) |
| 3018 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3019 | << OrderedLoopCountExpr->getSourceRange(); |
| 3020 | else if (CollapseLoopCountExpr) |
| 3021 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3022 | diag::note_omp_collapse_ordered_expr) |
| 3023 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3024 | else |
| 3025 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3026 | diag::note_omp_collapse_ordered_expr) |
| 3027 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3028 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3029 | return true; |
| 3030 | } |
| 3031 | assert(For->getBody()); |
| 3032 | |
| 3033 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3034 | |
| 3035 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3036 | auto Init = For->getInit(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3037 | if (ISC.CheckInit(Init)) { |
| 3038 | return true; |
| 3039 | } |
| 3040 | |
| 3041 | bool HasErrors = false; |
| 3042 | |
| 3043 | // Check loop variable's type. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3044 | auto Var = ISC.GetLoopVar(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3045 | |
| 3046 | // OpenMP [2.6, Canonical Loop Form] |
| 3047 | // Var is one of the following: |
| 3048 | // A variable of signed or unsigned integer type. |
| 3049 | // For C++, a variable of a random access iterator type. |
| 3050 | // For C, a variable of a pointer type. |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3051 | auto VarType = Var->getType().getNonReferenceType(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3052 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3053 | !VarType->isPointerType() && |
| 3054 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3055 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3056 | << SemaRef.getLangOpts().CPlusPlus; |
| 3057 | HasErrors = true; |
| 3058 | } |
| 3059 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3060 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in a |
| 3061 | // Construct |
| 3062 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3063 | // parallel for construct is (are) private. |
| 3064 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3065 | // with just one associated for-loop is linear with a constant-linear-step |
| 3066 | // that is the increment of the associated for-loop. |
| 3067 | // Exclude loop var from the list of variables with implicitly defined data |
| 3068 | // sharing attributes. |
Benjamin Kramer | ad8e079 | 2014-10-10 15:32:48 +0000 | [diff] [blame] | 3069 | VarsWithImplicitDSA.erase(Var); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3070 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3071 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced in |
| 3072 | // a Construct, C/C++]. |
Alexey Bataev | cefffae | 2014-06-23 08:21:53 +0000 | [diff] [blame] | 3073 | // The loop iteration variable in the associated for-loop of a simd construct |
| 3074 | // with just one associated for-loop may be listed in a linear clause with a |
| 3075 | // constant-linear-step that is the increment of the associated for-loop. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3076 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3077 | // parallel for construct may be listed in a private or lastprivate clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3078 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(Var, false); |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3079 | auto LoopVarRefExpr = ISC.GetLoopVarRefExpr(); |
| 3080 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3081 | // declared in the loop and it is predetermined as a private. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3082 | auto PredeterminedCKind = |
| 3083 | isOpenMPSimdDirective(DKind) |
| 3084 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3085 | : OMPC_private; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3086 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3087 | DVar.CKind != OMPC_threadprivate && DVar.CKind != PredeterminedCKind) || |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3088 | (isOpenMPWorksharingDirective(DKind) && !isOpenMPSimdDirective(DKind) && |
| 3089 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private && |
Alexey Bataev | 0c024df | 2015-05-12 09:02:07 +0000 | [diff] [blame] | 3090 | DVar.CKind != OMPC_lastprivate && DVar.CKind != OMPC_threadprivate)) && |
| 3091 | ((DVar.CKind != OMPC_private && DVar.CKind != OMPC_threadprivate) || |
| 3092 | DVar.RefExpr != nullptr)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3093 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3094 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3095 | << getOpenMPClauseName(PredeterminedCKind); |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 3096 | if (DVar.RefExpr == nullptr) |
| 3097 | DVar.CKind = PredeterminedCKind; |
| 3098 | ReportOriginalDSA(SemaRef, &DSA, Var, DVar, /*IsLoopIterVar=*/true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3099 | HasErrors = true; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3100 | } else if (LoopVarRefExpr != nullptr) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3101 | // Make the loop iteration variable private (for worksharing constructs), |
| 3102 | // linear (for simd directives with the only one associated loop) or |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3103 | // lastprivate (for simd directives with several collapsed or ordered |
| 3104 | // loops). |
Alexey Bataev | 9aba41c | 2014-11-14 04:08:45 +0000 | [diff] [blame] | 3105 | if (DVar.CKind == OMPC_unknown) |
| 3106 | DVar = DSA.hasDSA(Var, isOpenMPPrivate, MatchesAlways(), |
| 3107 | /*FromParent=*/false); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3108 | DSA.addDSA(Var, LoopVarRefExpr, PredeterminedCKind); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3109 | } |
| 3110 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 3111 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 3112 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3113 | // Check test-expr. |
| 3114 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3115 | |
| 3116 | // Check incr-expr. |
| 3117 | HasErrors |= ISC.CheckInc(For->getInc()); |
| 3118 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3119 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3120 | return HasErrors; |
| 3121 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3122 | // Build the loop's iteration space representation. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3123 | ResultIterSpace.PreCond = ISC.BuildPreCond(DSA.getCurScope(), For->getCond()); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3124 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
| 3125 | DSA.getCurScope(), /* LimitedType */ isOpenMPWorksharingDirective(DKind)); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3126 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3127 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3128 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3129 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3130 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3131 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3132 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3133 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3134 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3135 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3136 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3137 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3138 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3139 | ResultIterSpace.CounterInit == nullptr || |
| 3140 | ResultIterSpace.CounterStep == nullptr); |
| 3141 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3142 | return HasErrors; |
| 3143 | } |
| 3144 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3145 | /// \brief Build 'VarRef = Start. |
| 3146 | static ExprResult BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3147 | ExprResult VarRef, ExprResult Start) { |
| 3148 | TransformToNewDefs Transform(SemaRef); |
| 3149 | // Build 'VarRef = Start. |
| 3150 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3151 | if (NewStart.isInvalid()) |
| 3152 | return ExprError(); |
| 3153 | NewStart = SemaRef.PerformImplicitConversion( |
| 3154 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3155 | Sema::AA_Converting, |
| 3156 | /*AllowExplicit=*/true); |
| 3157 | if (NewStart.isInvalid()) |
| 3158 | return ExprError(); |
| 3159 | NewStart = SemaRef.PerformImplicitConversion( |
| 3160 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3161 | /*AllowExplicit=*/true); |
| 3162 | if (!NewStart.isUsable()) |
| 3163 | return ExprError(); |
| 3164 | |
| 3165 | auto Init = |
| 3166 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3167 | return Init; |
| 3168 | } |
| 3169 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3170 | /// \brief Build 'VarRef = Start + Iter * Step'. |
| 3171 | static ExprResult BuildCounterUpdate(Sema &SemaRef, Scope *S, |
| 3172 | SourceLocation Loc, ExprResult VarRef, |
| 3173 | ExprResult Start, ExprResult Iter, |
| 3174 | ExprResult Step, bool Subtract) { |
| 3175 | // Add parentheses (for debugging purposes only). |
| 3176 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3177 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3178 | !Step.isUsable()) |
| 3179 | return ExprError(); |
| 3180 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3181 | TransformToNewDefs Transform(SemaRef); |
| 3182 | auto NewStep = Transform.TransformExpr(Step.get()->IgnoreImplicit()); |
| 3183 | if (NewStep.isInvalid()) |
| 3184 | return ExprError(); |
| 3185 | NewStep = SemaRef.PerformImplicitConversion( |
| 3186 | NewStep.get(), Step.get()->IgnoreImplicit()->getType(), |
| 3187 | Sema::AA_Converting, |
| 3188 | /*AllowExplicit=*/true); |
| 3189 | if (NewStep.isInvalid()) |
| 3190 | return ExprError(); |
| 3191 | ExprResult Update = |
| 3192 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3193 | if (!Update.isUsable()) |
| 3194 | return ExprError(); |
| 3195 | |
| 3196 | // Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3197 | auto NewStart = Transform.TransformExpr(Start.get()->IgnoreImplicit()); |
| 3198 | if (NewStart.isInvalid()) |
| 3199 | return ExprError(); |
| 3200 | NewStart = SemaRef.PerformImplicitConversion( |
| 3201 | NewStart.get(), Start.get()->IgnoreImplicit()->getType(), |
| 3202 | Sema::AA_Converting, |
| 3203 | /*AllowExplicit=*/true); |
| 3204 | if (NewStart.isInvalid()) |
| 3205 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3206 | Update = SemaRef.BuildBinOp(S, Loc, (Subtract ? BO_Sub : BO_Add), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3207 | NewStart.get(), Update.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3208 | if (!Update.isUsable()) |
| 3209 | return ExprError(); |
| 3210 | |
| 3211 | Update = SemaRef.PerformImplicitConversion( |
| 3212 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3213 | if (!Update.isUsable()) |
| 3214 | return ExprError(); |
| 3215 | |
| 3216 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3217 | return Update; |
| 3218 | } |
| 3219 | |
| 3220 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3221 | /// bits. |
| 3222 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 3223 | Sema &SemaRef) { |
| 3224 | if (E == nullptr) |
| 3225 | return ExprError(); |
| 3226 | auto &C = SemaRef.Context; |
| 3227 | QualType OldType = E->getType(); |
| 3228 | unsigned HasBits = C.getTypeSize(OldType); |
| 3229 | if (HasBits >= Bits) |
| 3230 | return ExprResult(E); |
| 3231 | // OK to convert to signed, because new type has more bits than old. |
| 3232 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3233 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3234 | true); |
| 3235 | } |
| 3236 | |
| 3237 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3238 | /// into \a Bits bits. |
| 3239 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3240 | if (E == nullptr) |
| 3241 | return false; |
| 3242 | llvm::APSInt Result; |
| 3243 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3244 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3245 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | /// \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] | 3249 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3250 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3251 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3252 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3253 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3254 | DSAStackTy &DSA, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3255 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3256 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3257 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3258 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3259 | // Found 'collapse' clause - calculate collapse number. |
| 3260 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3261 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 3262 | NestedLoopCount += Result.getLimitedValue() - 1; |
| 3263 | } |
| 3264 | if (OrderedLoopCountExpr) { |
| 3265 | // Found 'ordered' clause - calculate collapse number. |
| 3266 | llvm::APSInt Result; |
| 3267 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
| 3268 | NestedLoopCount += Result.getLimitedValue() - 1; |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3269 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3270 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3271 | // 'for simd', etc.). |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3272 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3273 | IterSpaces.resize(NestedLoopCount); |
| 3274 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3275 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3276 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3277 | NestedLoopCount, CollapseLoopCountExpr, |
| 3278 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
| 3279 | IterSpaces[Cnt])) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3280 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3281 | // 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] | 3282 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3283 | // All loops associated with the construct must be perfectly nested; that |
| 3284 | // is, there must be no intervening code nor any OpenMP directive between |
| 3285 | // any two loops. |
| 3286 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3289 | Built.clear(/* size */ NestedLoopCount); |
| 3290 | |
| 3291 | if (SemaRef.CurContext->isDependentContext()) |
| 3292 | return NestedLoopCount; |
| 3293 | |
| 3294 | // An example of what is generated for the following code: |
| 3295 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3296 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3297 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3298 | // for (k = 0; k < NK; ++k) |
| 3299 | // for (j = J0; j < NJ; j+=2) { |
| 3300 | // <loop body> |
| 3301 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3302 | // |
| 3303 | // We generate the code below. |
| 3304 | // Note: the loop body may be outlined in CodeGen. |
| 3305 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3306 | // iterations and operator+= to calculate counter value. |
| 3307 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3308 | // or i64 is currently supported). |
| 3309 | // |
| 3310 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3311 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3312 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3313 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3314 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3315 | // <loop body (using local i and j)> |
| 3316 | // } |
| 3317 | // i = NI; // assign final values of counters |
| 3318 | // j = NJ; |
| 3319 | // |
| 3320 | |
| 3321 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3322 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3323 | // Precondition tests if there is at least one iteration (all conditions are |
| 3324 | // true). |
| 3325 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3326 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3327 | ExprResult LastIteration32 = WidenIterationCount( |
| 3328 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3329 | N0->IgnoreImpCasts(), N0->getType(), |
| 3330 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3331 | .get(), |
| 3332 | SemaRef); |
| 3333 | ExprResult LastIteration64 = WidenIterationCount( |
| 3334 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 3335 | N0->IgnoreImpCasts(), N0->getType(), |
| 3336 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 3337 | .get(), |
| 3338 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3339 | |
| 3340 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3341 | return NestedLoopCount; |
| 3342 | |
| 3343 | auto &C = SemaRef.Context; |
| 3344 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3345 | |
| 3346 | Scope *CurScope = DSA.getCurScope(); |
| 3347 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3348 | if (PreCond.isUsable()) { |
| 3349 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 3350 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 3351 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3352 | auto N = IterSpaces[Cnt].NumIterations; |
| 3353 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3354 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3355 | LastIteration32 = SemaRef.BuildBinOp( |
| 3356 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 3357 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3358 | Sema::AA_Converting, |
| 3359 | /*AllowExplicit=*/true) |
| 3360 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3361 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3362 | LastIteration64 = SemaRef.BuildBinOp( |
| 3363 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 3364 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3365 | Sema::AA_Converting, |
| 3366 | /*AllowExplicit=*/true) |
| 3367 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | // Choose either the 32-bit or 64-bit version. |
| 3371 | ExprResult LastIteration = LastIteration64; |
| 3372 | if (LastIteration32.isUsable() && |
| 3373 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3374 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3375 | FitsInto( |
| 3376 | 32 /* Bits */, |
| 3377 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3378 | LastIteration64.get(), SemaRef))) |
| 3379 | LastIteration = LastIteration32; |
| 3380 | |
| 3381 | if (!LastIteration.isUsable()) |
| 3382 | return 0; |
| 3383 | |
| 3384 | // Save the number of iterations. |
| 3385 | ExprResult NumIterations = LastIteration; |
| 3386 | { |
| 3387 | LastIteration = SemaRef.BuildBinOp( |
| 3388 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 3389 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3390 | if (!LastIteration.isUsable()) |
| 3391 | return 0; |
| 3392 | } |
| 3393 | |
| 3394 | // Calculate the last iteration number beforehand instead of doing this on |
| 3395 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 3396 | llvm::APSInt Result; |
| 3397 | bool IsConstant = |
| 3398 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3399 | ExprResult CalcLastIteration; |
| 3400 | if (!IsConstant) { |
| 3401 | SourceLocation SaveLoc; |
| 3402 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3403 | buildVarDecl(SemaRef, SaveLoc, LastIteration.get()->getType(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3404 | ".omp.last.iteration"); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3405 | ExprResult SaveRef = buildDeclRefExpr( |
| 3406 | SemaRef, SaveVar, LastIteration.get()->getType(), SaveLoc); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3407 | CalcLastIteration = SemaRef.BuildBinOp(CurScope, SaveLoc, BO_Assign, |
| 3408 | SaveRef.get(), LastIteration.get()); |
| 3409 | LastIteration = SaveRef; |
| 3410 | |
| 3411 | // Prepare SaveRef + 1. |
| 3412 | NumIterations = SemaRef.BuildBinOp( |
| 3413 | CurScope, SaveLoc, BO_Add, SaveRef.get(), |
| 3414 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3415 | if (!NumIterations.isUsable()) |
| 3416 | return 0; |
| 3417 | } |
| 3418 | |
| 3419 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 3420 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3421 | QualType VType = LastIteration.get()->getType(); |
| 3422 | // Build variables passed into runtime, nesessary for worksharing directives. |
| 3423 | ExprResult LB, UB, IL, ST, EUB; |
| 3424 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3425 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3426 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 3427 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3428 | SemaRef.AddInitializerToDecl( |
| 3429 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3430 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3431 | |
| 3432 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3433 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 3434 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3435 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 3436 | /*DirectInit*/ false, |
| 3437 | /*TypeMayContainAuto*/ false); |
| 3438 | |
| 3439 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 3440 | // This will be used to implement clause 'lastprivate'. |
| 3441 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3442 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 3443 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3444 | SemaRef.AddInitializerToDecl( |
| 3445 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 3446 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3447 | |
| 3448 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3449 | VarDecl *STDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.stride"); |
| 3450 | ST = buildDeclRefExpr(SemaRef, STDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3451 | SemaRef.AddInitializerToDecl( |
| 3452 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 3453 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 3454 | |
| 3455 | // Build expression: UB = min(UB, LastIteration) |
| 3456 | // It is nesessary for CodeGen of directives with static scheduling. |
| 3457 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 3458 | UB.get(), LastIteration.get()); |
| 3459 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 3460 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 3461 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 3462 | CondOp.get()); |
| 3463 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
| 3464 | } |
| 3465 | |
| 3466 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3467 | ExprResult IV; |
| 3468 | ExprResult Init; |
| 3469 | { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3470 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.iv"); |
| 3471 | IV = buildDeclRefExpr(SemaRef, IVDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3472 | Expr *RHS = isOpenMPWorksharingDirective(DKind) |
| 3473 | ? LB.get() |
| 3474 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 3475 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 3476 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3477 | } |
| 3478 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3479 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3480 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3481 | ExprResult Cond = |
| 3482 | isOpenMPWorksharingDirective(DKind) |
| 3483 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 3484 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 3485 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3486 | |
| 3487 | // Loop increment (IV = IV + 1) |
| 3488 | SourceLocation IncLoc; |
| 3489 | ExprResult Inc = |
| 3490 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 3491 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 3492 | if (!Inc.isUsable()) |
| 3493 | return 0; |
| 3494 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3495 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 3496 | if (!Inc.isUsable()) |
| 3497 | return 0; |
| 3498 | |
| 3499 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 3500 | // Used for directives with static scheduling. |
| 3501 | ExprResult NextLB, NextUB; |
| 3502 | if (isOpenMPWorksharingDirective(DKind)) { |
| 3503 | // LB + ST |
| 3504 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 3505 | if (!NextLB.isUsable()) |
| 3506 | return 0; |
| 3507 | // LB = LB + ST |
| 3508 | NextLB = |
| 3509 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 3510 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 3511 | if (!NextLB.isUsable()) |
| 3512 | return 0; |
| 3513 | // UB + ST |
| 3514 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 3515 | if (!NextUB.isUsable()) |
| 3516 | return 0; |
| 3517 | // UB = UB + ST |
| 3518 | NextUB = |
| 3519 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 3520 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 3521 | if (!NextUB.isUsable()) |
| 3522 | return 0; |
| 3523 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3524 | |
| 3525 | // Build updates and final values of the loop counters. |
| 3526 | bool HasErrors = false; |
| 3527 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3528 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3529 | Built.Updates.resize(NestedLoopCount); |
| 3530 | Built.Finals.resize(NestedLoopCount); |
| 3531 | { |
| 3532 | ExprResult Div; |
| 3533 | // Go from inner nested loop to outer. |
| 3534 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 3535 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 3536 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 3537 | // Build: Iter = (IV / Div) % IS.NumIters |
| 3538 | // where Div is product of previous iterations' IS.NumIters. |
| 3539 | ExprResult Iter; |
| 3540 | if (Div.isUsable()) { |
| 3541 | Iter = |
| 3542 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 3543 | } else { |
| 3544 | Iter = IV; |
| 3545 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 3546 | "unusable div expected on first iteration only"); |
| 3547 | } |
| 3548 | |
| 3549 | if (Cnt != 0 && Iter.isUsable()) |
| 3550 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 3551 | IS.NumIterations); |
| 3552 | if (!Iter.isUsable()) { |
| 3553 | HasErrors = true; |
| 3554 | break; |
| 3555 | } |
| 3556 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3557 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
| 3558 | auto *CounterVar = buildDeclRefExpr( |
| 3559 | SemaRef, cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()), |
| 3560 | IS.CounterVar->getType(), IS.CounterVar->getExprLoc(), |
| 3561 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3562 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
| 3563 | IS.CounterInit); |
| 3564 | if (!Init.isUsable()) { |
| 3565 | HasErrors = true; |
| 3566 | break; |
| 3567 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3568 | ExprResult Update = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3569 | BuildCounterUpdate(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3570 | IS.CounterInit, Iter, IS.CounterStep, IS.Subtract); |
| 3571 | if (!Update.isUsable()) { |
| 3572 | HasErrors = true; |
| 3573 | break; |
| 3574 | } |
| 3575 | |
| 3576 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 3577 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 3578 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3579 | IS.NumIterations, IS.CounterStep, IS.Subtract); |
| 3580 | if (!Final.isUsable()) { |
| 3581 | HasErrors = true; |
| 3582 | break; |
| 3583 | } |
| 3584 | |
| 3585 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 3586 | if (Cnt != 0) { |
| 3587 | if (Div.isUnset()) |
| 3588 | Div = IS.NumIterations; |
| 3589 | else |
| 3590 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 3591 | IS.NumIterations); |
| 3592 | |
| 3593 | // Add parentheses (for debugging purposes only). |
| 3594 | if (Div.isUsable()) |
| 3595 | Div = SemaRef.ActOnParenExpr(UpdLoc, UpdLoc, Div.get()); |
| 3596 | if (!Div.isUsable()) { |
| 3597 | HasErrors = true; |
| 3598 | break; |
| 3599 | } |
| 3600 | } |
| 3601 | if (!Update.isUsable() || !Final.isUsable()) { |
| 3602 | HasErrors = true; |
| 3603 | break; |
| 3604 | } |
| 3605 | // Save results |
| 3606 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3607 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3608 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3609 | Built.Updates[Cnt] = Update.get(); |
| 3610 | Built.Finals[Cnt] = Final.get(); |
| 3611 | } |
| 3612 | } |
| 3613 | |
| 3614 | if (HasErrors) |
| 3615 | return 0; |
| 3616 | |
| 3617 | // Save results |
| 3618 | Built.IterationVarRef = IV.get(); |
| 3619 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3620 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3621 | Built.CalcLastIteration = |
| 3622 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3623 | Built.PreCond = PreCond.get(); |
| 3624 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3625 | Built.Init = Init.get(); |
| 3626 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3627 | Built.LB = LB.get(); |
| 3628 | Built.UB = UB.get(); |
| 3629 | Built.IL = IL.get(); |
| 3630 | Built.ST = ST.get(); |
| 3631 | Built.EUB = EUB.get(); |
| 3632 | Built.NLB = NextLB.get(); |
| 3633 | Built.NUB = NextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3634 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3635 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3636 | } |
| 3637 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3638 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3639 | auto CollapseClauses = |
| 3640 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 3641 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 3642 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3643 | return nullptr; |
| 3644 | } |
| 3645 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3646 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 3647 | auto OrderedClauses = |
| 3648 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 3649 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 3650 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3651 | return nullptr; |
| 3652 | } |
| 3653 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3654 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 3655 | const Expr *Safelen) { |
| 3656 | llvm::APSInt SimdlenRes, SafelenRes; |
| 3657 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 3658 | Simdlen->isInstantiationDependent() || |
| 3659 | Simdlen->containsUnexpandedParameterPack()) |
| 3660 | return false; |
| 3661 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 3662 | Safelen->isInstantiationDependent() || |
| 3663 | Safelen->containsUnexpandedParameterPack()) |
| 3664 | return false; |
| 3665 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 3666 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 3667 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3668 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3669 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3670 | if (SimdlenRes > SafelenRes) { |
| 3671 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 3672 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 3673 | return true; |
| 3674 | } |
| 3675 | return false; |
| 3676 | } |
| 3677 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3678 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 3679 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3680 | SourceLocation EndLoc, |
| 3681 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3682 | if (!AStmt) |
| 3683 | return StmtError(); |
| 3684 | |
| 3685 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3686 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3687 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3688 | // define the nested loops number. |
| 3689 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3690 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3691 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3692 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3693 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3694 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3695 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3696 | "omp simd loop exprs were not built"); |
| 3697 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 3698 | if (!CurContext->isDependentContext()) { |
| 3699 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3700 | for (auto C : Clauses) { |
| 3701 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3702 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3703 | B.NumIterations, *this, CurScope)) |
| 3704 | return StmtError(); |
| 3705 | } |
| 3706 | } |
| 3707 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3708 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3709 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3710 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3711 | OMPSafelenClause *Safelen = nullptr; |
| 3712 | OMPSimdlenClause *Simdlen = nullptr; |
| 3713 | for (auto *Clause : Clauses) { |
| 3714 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3715 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3716 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3717 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3718 | if (Safelen && Simdlen) |
| 3719 | break; |
| 3720 | } |
| 3721 | if (Simdlen && Safelen && |
| 3722 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3723 | Safelen->getSafelen())) |
| 3724 | return StmtError(); |
| 3725 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3726 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3727 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3728 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3729 | } |
| 3730 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3731 | StmtResult Sema::ActOnOpenMPForDirective( |
| 3732 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3733 | SourceLocation EndLoc, |
| 3734 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3735 | if (!AStmt) |
| 3736 | return StmtError(); |
| 3737 | |
| 3738 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3739 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3740 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3741 | // define the nested loops number. |
| 3742 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 3743 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 3744 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3745 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3746 | return StmtError(); |
| 3747 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3748 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3749 | "omp 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 | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3761 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3762 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3763 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3764 | } |
| 3765 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3766 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 3767 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3768 | SourceLocation EndLoc, |
| 3769 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3770 | if (!AStmt) |
| 3771 | return StmtError(); |
| 3772 | |
| 3773 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3774 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3775 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3776 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3777 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3778 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 3779 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3780 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3781 | if (NestedLoopCount == 0) |
| 3782 | return StmtError(); |
| 3783 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3784 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3785 | "omp for simd loop exprs were not built"); |
| 3786 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 3787 | if (!CurContext->isDependentContext()) { |
| 3788 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3789 | for (auto C : Clauses) { |
| 3790 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3791 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3792 | B.NumIterations, *this, CurScope)) |
| 3793 | return StmtError(); |
| 3794 | } |
| 3795 | } |
| 3796 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 3797 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 3798 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 3799 | // parameter must be less than or equal to the value of the safelen parameter. |
| 3800 | OMPSafelenClause *Safelen = nullptr; |
| 3801 | OMPSimdlenClause *Simdlen = nullptr; |
| 3802 | for (auto *Clause : Clauses) { |
| 3803 | if (Clause->getClauseKind() == OMPC_safelen) |
| 3804 | Safelen = cast<OMPSafelenClause>(Clause); |
| 3805 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 3806 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 3807 | if (Safelen && Simdlen) |
| 3808 | break; |
| 3809 | } |
| 3810 | if (Simdlen && Safelen && |
| 3811 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 3812 | Safelen->getSafelen())) |
| 3813 | return StmtError(); |
| 3814 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3815 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3816 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 3817 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3818 | } |
| 3819 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3820 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 3821 | Stmt *AStmt, |
| 3822 | SourceLocation StartLoc, |
| 3823 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3824 | if (!AStmt) |
| 3825 | return StmtError(); |
| 3826 | |
| 3827 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3828 | auto BaseStmt = AStmt; |
| 3829 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 3830 | BaseStmt = CS->getCapturedStmt(); |
| 3831 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 3832 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3833 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3834 | return StmtError(); |
| 3835 | // All associated statements must be '#pragma omp section' except for |
| 3836 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 3837 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3838 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 3839 | if (SectionStmt) |
| 3840 | Diag(SectionStmt->getLocStart(), |
| 3841 | diag::err_omp_sections_substmt_not_section); |
| 3842 | return StmtError(); |
| 3843 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3844 | cast<OMPSectionDirective>(SectionStmt) |
| 3845 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3846 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3847 | } else { |
| 3848 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 3849 | return StmtError(); |
| 3850 | } |
| 3851 | |
| 3852 | getCurFunction()->setHasBranchProtectedScope(); |
| 3853 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3854 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3855 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3858 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 3859 | SourceLocation StartLoc, |
| 3860 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3861 | if (!AStmt) |
| 3862 | return StmtError(); |
| 3863 | |
| 3864 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3865 | |
| 3866 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3867 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3868 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3869 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 3870 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3873 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 3874 | Stmt *AStmt, |
| 3875 | SourceLocation StartLoc, |
| 3876 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3877 | if (!AStmt) |
| 3878 | return StmtError(); |
| 3879 | |
| 3880 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3881 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3882 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 3883 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 3884 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 3885 | // The copyprivate clause must not be used with the nowait clause. |
| 3886 | OMPClause *Nowait = nullptr; |
| 3887 | OMPClause *Copyprivate = nullptr; |
| 3888 | for (auto *Clause : Clauses) { |
| 3889 | if (Clause->getClauseKind() == OMPC_nowait) |
| 3890 | Nowait = Clause; |
| 3891 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 3892 | Copyprivate = Clause; |
| 3893 | if (Copyprivate && Nowait) { |
| 3894 | Diag(Copyprivate->getLocStart(), |
| 3895 | diag::err_omp_single_copyprivate_with_nowait); |
| 3896 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 3897 | return StmtError(); |
| 3898 | } |
| 3899 | } |
| 3900 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3901 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 3902 | } |
| 3903 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3904 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 3905 | SourceLocation StartLoc, |
| 3906 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3907 | if (!AStmt) |
| 3908 | return StmtError(); |
| 3909 | |
| 3910 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3911 | |
| 3912 | getCurFunction()->setHasBranchProtectedScope(); |
| 3913 | |
| 3914 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 3915 | } |
| 3916 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3917 | StmtResult |
| 3918 | Sema::ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 3919 | Stmt *AStmt, SourceLocation StartLoc, |
| 3920 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3921 | if (!AStmt) |
| 3922 | return StmtError(); |
| 3923 | |
| 3924 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3925 | |
| 3926 | getCurFunction()->setHasBranchProtectedScope(); |
| 3927 | |
| 3928 | return OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 3929 | AStmt); |
| 3930 | } |
| 3931 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3932 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 3933 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3934 | SourceLocation EndLoc, |
| 3935 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3936 | if (!AStmt) |
| 3937 | return StmtError(); |
| 3938 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3939 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3940 | // 1.2.2 OpenMP Language Terminology |
| 3941 | // Structured block - An executable statement with a single entry at the |
| 3942 | // top and a single exit at the bottom. |
| 3943 | // The point of exit cannot be a branch out of the structured block. |
| 3944 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3945 | CS->getCapturedDecl()->setNothrow(); |
| 3946 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3947 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3948 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3949 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3950 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3951 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 3952 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3953 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3954 | if (NestedLoopCount == 0) |
| 3955 | return StmtError(); |
| 3956 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3957 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 3958 | "omp parallel for loop exprs were not built"); |
| 3959 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 3960 | if (!CurContext->isDependentContext()) { |
| 3961 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 3962 | for (auto C : Clauses) { |
| 3963 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 3964 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 3965 | B.NumIterations, *this, CurScope)) |
| 3966 | return StmtError(); |
| 3967 | } |
| 3968 | } |
| 3969 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3970 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3971 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3972 | NestedLoopCount, Clauses, AStmt, B, |
| 3973 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3974 | } |
| 3975 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3976 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 3977 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 3978 | SourceLocation EndLoc, |
| 3979 | llvm::DenseMap<VarDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3980 | if (!AStmt) |
| 3981 | return StmtError(); |
| 3982 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3983 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3984 | // 1.2.2 OpenMP Language Terminology |
| 3985 | // Structured block - An executable statement with a single entry at the |
| 3986 | // top and a single exit at the bottom. |
| 3987 | // The point of exit cannot be a branch out of the structured block. |
| 3988 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3989 | CS->getCapturedDecl()->setNothrow(); |
| 3990 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3991 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3992 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 3993 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3994 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3995 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 3996 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 3997 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3998 | if (NestedLoopCount == 0) |
| 3999 | return StmtError(); |
| 4000 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4001 | if (!CurContext->isDependentContext()) { |
| 4002 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4003 | for (auto C : Clauses) { |
| 4004 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 4005 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 4006 | B.NumIterations, *this, CurScope)) |
| 4007 | return StmtError(); |
| 4008 | } |
| 4009 | } |
| 4010 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4011 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 4012 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 4013 | // parameter must be less than or equal to the value of the safelen parameter. |
| 4014 | OMPSafelenClause *Safelen = nullptr; |
| 4015 | OMPSimdlenClause *Simdlen = nullptr; |
| 4016 | for (auto *Clause : Clauses) { |
| 4017 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4018 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4019 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4020 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4021 | if (Safelen && Simdlen) |
| 4022 | break; |
| 4023 | } |
| 4024 | if (Simdlen && Safelen && |
| 4025 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 4026 | Safelen->getSafelen())) |
| 4027 | return StmtError(); |
| 4028 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4029 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4030 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4031 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4032 | } |
| 4033 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4034 | StmtResult |
| 4035 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4036 | Stmt *AStmt, SourceLocation StartLoc, |
| 4037 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4038 | if (!AStmt) |
| 4039 | return StmtError(); |
| 4040 | |
| 4041 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4042 | auto BaseStmt = AStmt; |
| 4043 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 4044 | BaseStmt = CS->getCapturedStmt(); |
| 4045 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 4046 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4047 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4048 | return StmtError(); |
| 4049 | // All associated statements must be '#pragma omp section' except for |
| 4050 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4051 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4052 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4053 | if (SectionStmt) |
| 4054 | Diag(SectionStmt->getLocStart(), |
| 4055 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4056 | return StmtError(); |
| 4057 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4058 | cast<OMPSectionDirective>(SectionStmt) |
| 4059 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4060 | } |
| 4061 | } else { |
| 4062 | Diag(AStmt->getLocStart(), |
| 4063 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4064 | return StmtError(); |
| 4065 | } |
| 4066 | |
| 4067 | getCurFunction()->setHasBranchProtectedScope(); |
| 4068 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4069 | return OMPParallelSectionsDirective::Create( |
| 4070 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4071 | } |
| 4072 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4073 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4074 | Stmt *AStmt, SourceLocation StartLoc, |
| 4075 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4076 | if (!AStmt) |
| 4077 | return StmtError(); |
| 4078 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4079 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4080 | // 1.2.2 OpenMP Language Terminology |
| 4081 | // Structured block - An executable statement with a single entry at the |
| 4082 | // top and a single exit at the bottom. |
| 4083 | // The point of exit cannot be a branch out of the structured block. |
| 4084 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4085 | CS->getCapturedDecl()->setNothrow(); |
| 4086 | |
| 4087 | getCurFunction()->setHasBranchProtectedScope(); |
| 4088 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4089 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4090 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4091 | } |
| 4092 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4093 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4094 | SourceLocation EndLoc) { |
| 4095 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4096 | } |
| 4097 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4098 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4099 | SourceLocation EndLoc) { |
| 4100 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4101 | } |
| 4102 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4103 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4104 | SourceLocation EndLoc) { |
| 4105 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4106 | } |
| 4107 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4108 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4109 | SourceLocation StartLoc, |
| 4110 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4111 | if (!AStmt) |
| 4112 | return StmtError(); |
| 4113 | |
| 4114 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4115 | |
| 4116 | getCurFunction()->setHasBranchProtectedScope(); |
| 4117 | |
| 4118 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4119 | } |
| 4120 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4121 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4122 | SourceLocation StartLoc, |
| 4123 | SourceLocation EndLoc) { |
| 4124 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4125 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4126 | } |
| 4127 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4128 | StmtResult Sema::ActOnOpenMPOrderedDirective(Stmt *AStmt, |
| 4129 | SourceLocation StartLoc, |
| 4130 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4131 | if (!AStmt) |
| 4132 | return StmtError(); |
| 4133 | |
| 4134 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4135 | |
| 4136 | getCurFunction()->setHasBranchProtectedScope(); |
| 4137 | |
| 4138 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4139 | } |
| 4140 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4141 | namespace { |
| 4142 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4143 | /// construct. |
| 4144 | class OpenMPAtomicUpdateChecker { |
| 4145 | /// \brief Error results for atomic update expressions. |
| 4146 | enum ExprAnalysisErrorCode { |
| 4147 | /// \brief A statement is not an expression statement. |
| 4148 | NotAnExpression, |
| 4149 | /// \brief Expression is not builtin binary or unary operation. |
| 4150 | NotABinaryOrUnaryExpression, |
| 4151 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4152 | NotAnUnaryIncDecExpression, |
| 4153 | /// \brief An expression is not of scalar type. |
| 4154 | NotAScalarType, |
| 4155 | /// \brief A binary operation is not an assignment operation. |
| 4156 | NotAnAssignmentOp, |
| 4157 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4158 | NotABinaryExpression, |
| 4159 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4160 | /// expression. |
| 4161 | NotABinaryOperator, |
| 4162 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4163 | /// part. |
| 4164 | NotAnUpdateExpression, |
| 4165 | /// \brief No errors is found. |
| 4166 | NoError |
| 4167 | }; |
| 4168 | /// \brief Reference to Sema. |
| 4169 | Sema &SemaRef; |
| 4170 | /// \brief A location for note diagnostics (when error is found). |
| 4171 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4172 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4173 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4174 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4175 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4176 | /// \brief Helper expression of the form |
| 4177 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4178 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4179 | Expr *UpdateExpr; |
| 4180 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4181 | /// important for non-associative operations. |
| 4182 | bool IsXLHSInRHSPart; |
| 4183 | BinaryOperatorKind Op; |
| 4184 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4185 | /// \brief true if the source expression is a postfix unary operation, false |
| 4186 | /// if it is a prefix unary operation. |
| 4187 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4188 | |
| 4189 | public: |
| 4190 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4191 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4192 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4193 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4194 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4195 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4196 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4197 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4198 | /// \param NoteId Diagnostic note for the main error message. |
| 4199 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4200 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4201 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4202 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4203 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4204 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4205 | /// \brief Return the update expression used in calculation of the updated |
| 4206 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4207 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4208 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4209 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4210 | /// false otherwise. |
| 4211 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4212 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4213 | /// \brief true if the source expression is a postfix unary operation, false |
| 4214 | /// if it is a prefix unary operation. |
| 4215 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4216 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4217 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4218 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4219 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4220 | }; |
| 4221 | } // namespace |
| 4222 | |
| 4223 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 4224 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 4225 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4226 | SourceLocation ErrorLoc, NoteLoc; |
| 4227 | SourceRange ErrorRange, NoteRange; |
| 4228 | // Allowed constructs are: |
| 4229 | // x = x binop expr; |
| 4230 | // x = expr binop x; |
| 4231 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 4232 | X = AtomicBinOp->getLHS(); |
| 4233 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 4234 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 4235 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 4236 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 4237 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4238 | Op = AtomicInnerBinOp->getOpcode(); |
| 4239 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4240 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 4241 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 4242 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 4243 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 4244 | /*Canonical=*/true); |
| 4245 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 4246 | /*Canonical=*/true); |
| 4247 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 4248 | /*Canonical=*/true); |
| 4249 | if (XId == LHSId) { |
| 4250 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4251 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4252 | } else if (XId == RHSId) { |
| 4253 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4254 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4255 | } else { |
| 4256 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4257 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4258 | NoteLoc = X->getExprLoc(); |
| 4259 | NoteRange = X->getSourceRange(); |
| 4260 | ErrorFound = NotAnUpdateExpression; |
| 4261 | } |
| 4262 | } else { |
| 4263 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 4264 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 4265 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 4266 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4267 | ErrorFound = NotABinaryOperator; |
| 4268 | } |
| 4269 | } else { |
| 4270 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 4271 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 4272 | ErrorFound = NotABinaryExpression; |
| 4273 | } |
| 4274 | } else { |
| 4275 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4276 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4277 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 4278 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4279 | ErrorFound = NotAnAssignmentOp; |
| 4280 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4281 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4282 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4283 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4284 | return true; |
| 4285 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4286 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4287 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4288 | } |
| 4289 | |
| 4290 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 4291 | unsigned NoteId) { |
| 4292 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 4293 | SourceLocation ErrorLoc, NoteLoc; |
| 4294 | SourceRange ErrorRange, NoteRange; |
| 4295 | // Allowed constructs are: |
| 4296 | // x++; |
| 4297 | // x--; |
| 4298 | // ++x; |
| 4299 | // --x; |
| 4300 | // x binop= expr; |
| 4301 | // x = x binop expr; |
| 4302 | // x = expr binop x; |
| 4303 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 4304 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 4305 | if (AtomicBody->getType()->isScalarType() || |
| 4306 | AtomicBody->isInstantiationDependent()) { |
| 4307 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 4308 | AtomicBody->IgnoreParenImpCasts())) { |
| 4309 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4310 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4311 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4312 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4313 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4314 | X = AtomicCompAssignOp->getLHS(); |
| 4315 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4316 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 4317 | AtomicBody->IgnoreParenImpCasts())) { |
| 4318 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4319 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 4320 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4321 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4322 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 4323 | // Check for Unary Operation |
| 4324 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4325 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4326 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 4327 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4328 | X = AtomicUnaryOp->getSubExpr(); |
| 4329 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 4330 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4331 | } else { |
| 4332 | ErrorFound = NotAnUnaryIncDecExpression; |
| 4333 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 4334 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 4335 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 4336 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 4337 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4338 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4339 | ErrorFound = NotABinaryOrUnaryExpression; |
| 4340 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 4341 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 4342 | } |
| 4343 | } else { |
| 4344 | ErrorFound = NotAScalarType; |
| 4345 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 4346 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4347 | } |
| 4348 | } else { |
| 4349 | ErrorFound = NotAnExpression; |
| 4350 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 4351 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 4352 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4353 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4354 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 4355 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 4356 | return true; |
| 4357 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4358 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4359 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4360 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 4361 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 4362 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 4363 | auto *OVEX = new (SemaRef.getASTContext()) |
| 4364 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 4365 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 4366 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 4367 | auto Update = |
| 4368 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 4369 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 4370 | if (Update.isInvalid()) |
| 4371 | return true; |
| 4372 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 4373 | Sema::AA_Casting); |
| 4374 | if (Update.isInvalid()) |
| 4375 | return true; |
| 4376 | UpdateExpr = Update.get(); |
| 4377 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4378 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4379 | } |
| 4380 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4381 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 4382 | Stmt *AStmt, |
| 4383 | SourceLocation StartLoc, |
| 4384 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4385 | if (!AStmt) |
| 4386 | return StmtError(); |
| 4387 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4388 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4389 | // 1.2.2 OpenMP Language Terminology |
| 4390 | // Structured block - An executable statement with a single entry at the |
| 4391 | // top and a single exit at the bottom. |
| 4392 | // The point of exit cannot be a branch out of the structured block. |
| 4393 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4394 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 4395 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4396 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4397 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4398 | C->getClauseKind() == OMPC_update || |
| 4399 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4400 | if (AtomicKind != OMPC_unknown) { |
| 4401 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 4402 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 4403 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 4404 | << getOpenMPClauseName(AtomicKind); |
| 4405 | } else { |
| 4406 | AtomicKind = C->getClauseKind(); |
| 4407 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4408 | } |
| 4409 | } |
| 4410 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4411 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4412 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 4413 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 4414 | Body = EWC->getSubExpr(); |
| 4415 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4416 | Expr *X = nullptr; |
| 4417 | Expr *V = nullptr; |
| 4418 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4419 | Expr *UE = nullptr; |
| 4420 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4421 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4422 | // OpenMP [2.12.6, atomic Construct] |
| 4423 | // In the next expressions: |
| 4424 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 4425 | // * During the execution of an atomic region, multiple syntactic |
| 4426 | // occurrences of x must designate the same storage location. |
| 4427 | // * Neither of v and expr (as applicable) may access the storage location |
| 4428 | // designated by x. |
| 4429 | // * Neither of x and expr (as applicable) may access the storage location |
| 4430 | // designated by v. |
| 4431 | // * expr is an expression with scalar type. |
| 4432 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 4433 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 4434 | // * The expression x binop expr must be numerically equivalent to x binop |
| 4435 | // (expr). This requirement is satisfied if the operators in expr have |
| 4436 | // precedence greater than binop, or by using parentheses around expr or |
| 4437 | // subexpressions of expr. |
| 4438 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 4439 | // binop x. This requirement is satisfied if the operators in expr have |
| 4440 | // precedence equal to or greater than binop, or by using parentheses around |
| 4441 | // expr or subexpressions of expr. |
| 4442 | // * For forms that allow multiple occurrences of x, the number of times |
| 4443 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4444 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4445 | enum { |
| 4446 | NotAnExpression, |
| 4447 | NotAnAssignmentOp, |
| 4448 | NotAScalarType, |
| 4449 | NotAnLValue, |
| 4450 | NoError |
| 4451 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4452 | SourceLocation ErrorLoc, NoteLoc; |
| 4453 | SourceRange ErrorRange, NoteRange; |
| 4454 | // If clause is read: |
| 4455 | // v = x; |
| 4456 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4457 | auto AtomicBinOp = |
| 4458 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4459 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4460 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4461 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4462 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4463 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 4464 | if (!X->isLValue() || !V->isLValue()) { |
| 4465 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 4466 | ErrorFound = NotAnLValue; |
| 4467 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4468 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4469 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 4470 | NoteRange = NotLValueExpr->getSourceRange(); |
| 4471 | } |
| 4472 | } else if (!X->isInstantiationDependent() || |
| 4473 | !V->isInstantiationDependent()) { |
| 4474 | auto NotScalarExpr = |
| 4475 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4476 | ? V |
| 4477 | : X; |
| 4478 | ErrorFound = NotAScalarType; |
| 4479 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4480 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4481 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4482 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4483 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4484 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4485 | ErrorFound = NotAnAssignmentOp; |
| 4486 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4487 | ErrorRange = AtomicBody->getSourceRange(); |
| 4488 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4489 | : AtomicBody->getExprLoc(); |
| 4490 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4491 | : AtomicBody->getSourceRange(); |
| 4492 | } |
| 4493 | } else { |
| 4494 | ErrorFound = NotAnExpression; |
| 4495 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4496 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4497 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4498 | if (ErrorFound != NoError) { |
| 4499 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 4500 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4501 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4502 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4503 | return StmtError(); |
| 4504 | } else if (CurContext->isDependentContext()) |
| 4505 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4506 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4507 | enum { |
| 4508 | NotAnExpression, |
| 4509 | NotAnAssignmentOp, |
| 4510 | NotAScalarType, |
| 4511 | NotAnLValue, |
| 4512 | NoError |
| 4513 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4514 | SourceLocation ErrorLoc, NoteLoc; |
| 4515 | SourceRange ErrorRange, NoteRange; |
| 4516 | // If clause is write: |
| 4517 | // x = expr; |
| 4518 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 4519 | auto AtomicBinOp = |
| 4520 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4521 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 4522 | X = AtomicBinOp->getLHS(); |
| 4523 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4524 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 4525 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 4526 | if (!X->isLValue()) { |
| 4527 | ErrorFound = NotAnLValue; |
| 4528 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4529 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4530 | NoteLoc = X->getExprLoc(); |
| 4531 | NoteRange = X->getSourceRange(); |
| 4532 | } |
| 4533 | } else if (!X->isInstantiationDependent() || |
| 4534 | !E->isInstantiationDependent()) { |
| 4535 | auto NotScalarExpr = |
| 4536 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 4537 | ? E |
| 4538 | : X; |
| 4539 | ErrorFound = NotAScalarType; |
| 4540 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 4541 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 4542 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 4543 | NoteRange = NotScalarExpr->getSourceRange(); |
| 4544 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4545 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4546 | ErrorFound = NotAnAssignmentOp; |
| 4547 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4548 | ErrorRange = AtomicBody->getSourceRange(); |
| 4549 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4550 | : AtomicBody->getExprLoc(); |
| 4551 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4552 | : AtomicBody->getSourceRange(); |
| 4553 | } |
| 4554 | } else { |
| 4555 | ErrorFound = NotAnExpression; |
| 4556 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4557 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4558 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 4559 | if (ErrorFound != NoError) { |
| 4560 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 4561 | << ErrorRange; |
| 4562 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 4563 | << NoteRange; |
| 4564 | return StmtError(); |
| 4565 | } else if (CurContext->isDependentContext()) |
| 4566 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4567 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4568 | // If clause is update: |
| 4569 | // x++; |
| 4570 | // x--; |
| 4571 | // ++x; |
| 4572 | // --x; |
| 4573 | // x binop= expr; |
| 4574 | // x = x binop expr; |
| 4575 | // x = expr binop x; |
| 4576 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4577 | if (Checker.checkStatement( |
| 4578 | Body, (AtomicKind == OMPC_update) |
| 4579 | ? diag::err_omp_atomic_update_not_expression_statement |
| 4580 | : diag::err_omp_atomic_not_expression_statement, |
| 4581 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4582 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4583 | if (!CurContext->isDependentContext()) { |
| 4584 | E = Checker.getExpr(); |
| 4585 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4586 | UE = Checker.getUpdateExpr(); |
| 4587 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4588 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4589 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4590 | enum { |
| 4591 | NotAnAssignmentOp, |
| 4592 | NotACompoundStatement, |
| 4593 | NotTwoSubstatements, |
| 4594 | NotASpecificExpression, |
| 4595 | NoError |
| 4596 | } ErrorFound = NoError; |
| 4597 | SourceLocation ErrorLoc, NoteLoc; |
| 4598 | SourceRange ErrorRange, NoteRange; |
| 4599 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 4600 | // If clause is a capture: |
| 4601 | // v = x++; |
| 4602 | // v = x--; |
| 4603 | // v = ++x; |
| 4604 | // v = --x; |
| 4605 | // v = x binop= expr; |
| 4606 | // v = x = x binop expr; |
| 4607 | // v = x = expr binop x; |
| 4608 | auto *AtomicBinOp = |
| 4609 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 4610 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 4611 | V = AtomicBinOp->getLHS(); |
| 4612 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4613 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4614 | if (Checker.checkStatement( |
| 4615 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 4616 | diag::note_omp_atomic_update)) |
| 4617 | return StmtError(); |
| 4618 | E = Checker.getExpr(); |
| 4619 | X = Checker.getX(); |
| 4620 | UE = Checker.getUpdateExpr(); |
| 4621 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 4622 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4623 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4624 | ErrorLoc = AtomicBody->getExprLoc(); |
| 4625 | ErrorRange = AtomicBody->getSourceRange(); |
| 4626 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 4627 | : AtomicBody->getExprLoc(); |
| 4628 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 4629 | : AtomicBody->getSourceRange(); |
| 4630 | ErrorFound = NotAnAssignmentOp; |
| 4631 | } |
| 4632 | if (ErrorFound != NoError) { |
| 4633 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 4634 | << ErrorRange; |
| 4635 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4636 | return StmtError(); |
| 4637 | } else if (CurContext->isDependentContext()) { |
| 4638 | UE = V = E = X = nullptr; |
| 4639 | } |
| 4640 | } else { |
| 4641 | // If clause is a capture: |
| 4642 | // { v = x; x = expr; } |
| 4643 | // { v = x; x++; } |
| 4644 | // { v = x; x--; } |
| 4645 | // { v = x; ++x; } |
| 4646 | // { v = x; --x; } |
| 4647 | // { v = x; x binop= expr; } |
| 4648 | // { v = x; x = x binop expr; } |
| 4649 | // { v = x; x = expr binop x; } |
| 4650 | // { x++; v = x; } |
| 4651 | // { x--; v = x; } |
| 4652 | // { ++x; v = x; } |
| 4653 | // { --x; v = x; } |
| 4654 | // { x binop= expr; v = x; } |
| 4655 | // { x = x binop expr; v = x; } |
| 4656 | // { x = expr binop x; v = x; } |
| 4657 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 4658 | // Check that this is { expr1; expr2; } |
| 4659 | if (CS->size() == 2) { |
| 4660 | auto *First = CS->body_front(); |
| 4661 | auto *Second = CS->body_back(); |
| 4662 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 4663 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4664 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 4665 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 4666 | // Need to find what subexpression is 'v' and what is 'x'. |
| 4667 | OpenMPAtomicUpdateChecker Checker(*this); |
| 4668 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 4669 | BinaryOperator *BinOp = nullptr; |
| 4670 | if (IsUpdateExprFound) { |
| 4671 | BinOp = dyn_cast<BinaryOperator>(First); |
| 4672 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4673 | } |
| 4674 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4675 | // { v = x; x++; } |
| 4676 | // { v = x; x--; } |
| 4677 | // { v = x; ++x; } |
| 4678 | // { v = x; --x; } |
| 4679 | // { v = x; x binop= expr; } |
| 4680 | // { v = x; x = x binop expr; } |
| 4681 | // { v = x; x = expr binop x; } |
| 4682 | // Check that the first expression has form v = x. |
| 4683 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4684 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4685 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4686 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4687 | IsUpdateExprFound = XId == PossibleXId; |
| 4688 | if (IsUpdateExprFound) { |
| 4689 | V = BinOp->getLHS(); |
| 4690 | X = Checker.getX(); |
| 4691 | E = Checker.getExpr(); |
| 4692 | UE = Checker.getUpdateExpr(); |
| 4693 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4694 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4695 | } |
| 4696 | } |
| 4697 | if (!IsUpdateExprFound) { |
| 4698 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 4699 | BinOp = nullptr; |
| 4700 | if (IsUpdateExprFound) { |
| 4701 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 4702 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 4703 | } |
| 4704 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 4705 | // { x++; v = x; } |
| 4706 | // { x--; v = x; } |
| 4707 | // { ++x; v = x; } |
| 4708 | // { --x; v = x; } |
| 4709 | // { x binop= expr; v = x; } |
| 4710 | // { x = x binop expr; v = x; } |
| 4711 | // { x = expr binop x; v = x; } |
| 4712 | // Check that the second expression has form v = x. |
| 4713 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 4714 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 4715 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 4716 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 4717 | IsUpdateExprFound = XId == PossibleXId; |
| 4718 | if (IsUpdateExprFound) { |
| 4719 | V = BinOp->getLHS(); |
| 4720 | X = Checker.getX(); |
| 4721 | E = Checker.getExpr(); |
| 4722 | UE = Checker.getUpdateExpr(); |
| 4723 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 4724 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4725 | } |
| 4726 | } |
| 4727 | } |
| 4728 | if (!IsUpdateExprFound) { |
| 4729 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4730 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 4731 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 4732 | if (!FirstExpr || !SecondExpr || |
| 4733 | !(FirstExpr->isInstantiationDependent() || |
| 4734 | SecondExpr->isInstantiationDependent())) { |
| 4735 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 4736 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4737 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4738 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 4739 | : First->getLocStart(); |
| 4740 | NoteRange = ErrorRange = FirstBinOp |
| 4741 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4742 | : SourceRange(ErrorLoc, ErrorLoc); |
| 4743 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4744 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 4745 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 4746 | ErrorFound = NotAnAssignmentOp; |
| 4747 | NoteLoc = ErrorLoc = SecondBinOp |
| 4748 | ? SecondBinOp->getOperatorLoc() |
| 4749 | : Second->getLocStart(); |
| 4750 | NoteRange = ErrorRange = |
| 4751 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 4752 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4753 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 4754 | auto *PossibleXRHSInFirst = |
| 4755 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 4756 | auto *PossibleXLHSInSecond = |
| 4757 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 4758 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 4759 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 4760 | /*Canonical=*/true); |
| 4761 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 4762 | /*Canonical=*/true); |
| 4763 | IsUpdateExprFound = X1Id == X2Id; |
| 4764 | if (IsUpdateExprFound) { |
| 4765 | V = FirstBinOp->getLHS(); |
| 4766 | X = SecondBinOp->getLHS(); |
| 4767 | E = SecondBinOp->getRHS(); |
| 4768 | UE = nullptr; |
| 4769 | IsXLHSInRHSPart = false; |
| 4770 | IsPostfixUpdate = true; |
| 4771 | } else { |
| 4772 | ErrorFound = NotASpecificExpression; |
| 4773 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 4774 | ErrorRange = FirstBinOp->getSourceRange(); |
| 4775 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 4776 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 4777 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4778 | } |
| 4779 | } |
| 4780 | } |
| 4781 | } |
| 4782 | } else { |
| 4783 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4784 | NoteRange = ErrorRange = |
| 4785 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4786 | ErrorFound = NotTwoSubstatements; |
| 4787 | } |
| 4788 | } else { |
| 4789 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 4790 | NoteRange = ErrorRange = |
| 4791 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 4792 | ErrorFound = NotACompoundStatement; |
| 4793 | } |
| 4794 | if (ErrorFound != NoError) { |
| 4795 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 4796 | << ErrorRange; |
| 4797 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 4798 | return StmtError(); |
| 4799 | } else if (CurContext->isDependentContext()) { |
| 4800 | UE = V = E = X = nullptr; |
| 4801 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4802 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4803 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4804 | |
| 4805 | getCurFunction()->setHasBranchProtectedScope(); |
| 4806 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 4807 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4808 | X, V, E, UE, IsXLHSInRHSPart, |
| 4809 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 4810 | } |
| 4811 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4812 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 4813 | Stmt *AStmt, |
| 4814 | SourceLocation StartLoc, |
| 4815 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4816 | if (!AStmt) |
| 4817 | return StmtError(); |
| 4818 | |
| 4819 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4820 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4821 | // OpenMP [2.16, Nesting of Regions] |
| 4822 | // If specified, a teams construct must be contained within a target |
| 4823 | // construct. That target construct must contain no statements or directives |
| 4824 | // outside of the teams construct. |
| 4825 | if (DSAStack->hasInnerTeamsRegion()) { |
| 4826 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 4827 | bool OMPTeamsFound = true; |
| 4828 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 4829 | auto I = CS->body_begin(); |
| 4830 | while (I != CS->body_end()) { |
| 4831 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 4832 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 4833 | OMPTeamsFound = false; |
| 4834 | break; |
| 4835 | } |
| 4836 | ++I; |
| 4837 | } |
| 4838 | assert(I != CS->body_end() && "Not found statement"); |
| 4839 | S = *I; |
| 4840 | } |
| 4841 | if (!OMPTeamsFound) { |
| 4842 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 4843 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 4844 | diag::note_omp_nested_teams_construct_here); |
| 4845 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 4846 | << isa<OMPExecutableDirective>(S); |
| 4847 | return StmtError(); |
| 4848 | } |
| 4849 | } |
| 4850 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 4851 | getCurFunction()->setHasBranchProtectedScope(); |
| 4852 | |
| 4853 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4854 | } |
| 4855 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4856 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 4857 | Stmt *AStmt, |
| 4858 | SourceLocation StartLoc, |
| 4859 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4860 | if (!AStmt) |
| 4861 | return StmtError(); |
| 4862 | |
| 4863 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4864 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 4865 | getCurFunction()->setHasBranchProtectedScope(); |
| 4866 | |
| 4867 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 4868 | AStmt); |
| 4869 | } |
| 4870 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4871 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 4872 | Stmt *AStmt, SourceLocation StartLoc, |
| 4873 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4874 | if (!AStmt) |
| 4875 | return StmtError(); |
| 4876 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 4877 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4878 | // 1.2.2 OpenMP Language Terminology |
| 4879 | // Structured block - An executable statement with a single entry at the |
| 4880 | // top and a single exit at the bottom. |
| 4881 | // The point of exit cannot be a branch out of the structured block. |
| 4882 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4883 | CS->getCapturedDecl()->setNothrow(); |
| 4884 | |
| 4885 | getCurFunction()->setHasBranchProtectedScope(); |
| 4886 | |
| 4887 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4888 | } |
| 4889 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 4890 | StmtResult |
| 4891 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 4892 | SourceLocation EndLoc, |
| 4893 | OpenMPDirectiveKind CancelRegion) { |
| 4894 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4895 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4896 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4897 | << getOpenMPDirectiveName(CancelRegion); |
| 4898 | return StmtError(); |
| 4899 | } |
| 4900 | if (DSAStack->isParentNowaitRegion()) { |
| 4901 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 4902 | return StmtError(); |
| 4903 | } |
| 4904 | if (DSAStack->isParentOrderedRegion()) { |
| 4905 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 4906 | return StmtError(); |
| 4907 | } |
| 4908 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 4909 | CancelRegion); |
| 4910 | } |
| 4911 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 4912 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 4913 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4914 | SourceLocation EndLoc, |
| 4915 | OpenMPDirectiveKind CancelRegion) { |
| 4916 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 4917 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 4918 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 4919 | << getOpenMPDirectiveName(CancelRegion); |
| 4920 | return StmtError(); |
| 4921 | } |
| 4922 | if (DSAStack->isParentNowaitRegion()) { |
| 4923 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 4924 | return StmtError(); |
| 4925 | } |
| 4926 | if (DSAStack->isParentOrderedRegion()) { |
| 4927 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 4928 | return StmtError(); |
| 4929 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4930 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 4931 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 4932 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 4933 | } |
| 4934 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 4935 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4936 | SourceLocation StartLoc, |
| 4937 | SourceLocation LParenLoc, |
| 4938 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 4939 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4940 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 4941 | case OMPC_final: |
| 4942 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4943 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 4944 | case OMPC_num_threads: |
| 4945 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4946 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 4947 | case OMPC_safelen: |
| 4948 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4949 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4950 | case OMPC_simdlen: |
| 4951 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4952 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 4953 | case OMPC_collapse: |
| 4954 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4955 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4956 | case OMPC_ordered: |
| 4957 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 4958 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 4959 | case OMPC_device: |
| 4960 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 4961 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4962 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4963 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 4964 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 4965 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4966 | case OMPC_private: |
| 4967 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 4968 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4969 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 4970 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 4971 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 4972 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 4973 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 4974 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 4975 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 4976 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 4977 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4978 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4979 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 4980 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 4981 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 4982 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 4983 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 4984 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 4985 | case OMPC_depend: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4986 | case OMPC_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4987 | llvm_unreachable("Clause is not allowed."); |
| 4988 | } |
| 4989 | return Res; |
| 4990 | } |
| 4991 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4992 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 4993 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4994 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4995 | SourceLocation NameModifierLoc, |
| 4996 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 4997 | SourceLocation EndLoc) { |
| 4998 | Expr *ValExpr = Condition; |
| 4999 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5000 | !Condition->isInstantiationDependent() && |
| 5001 | !Condition->containsUnexpandedParameterPack()) { |
| 5002 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5003 | Condition->getExprLoc(), Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5004 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5005 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5006 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5007 | ValExpr = Val.get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5008 | } |
| 5009 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5010 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 5011 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5012 | } |
| 5013 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5014 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 5015 | SourceLocation StartLoc, |
| 5016 | SourceLocation LParenLoc, |
| 5017 | SourceLocation EndLoc) { |
| 5018 | Expr *ValExpr = Condition; |
| 5019 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 5020 | !Condition->isInstantiationDependent() && |
| 5021 | !Condition->containsUnexpandedParameterPack()) { |
| 5022 | ExprResult Val = ActOnBooleanCondition(DSAStack->getCurScope(), |
| 5023 | Condition->getExprLoc(), Condition); |
| 5024 | if (Val.isInvalid()) |
| 5025 | return nullptr; |
| 5026 | |
| 5027 | ValExpr = Val.get(); |
| 5028 | } |
| 5029 | |
| 5030 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 5031 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5032 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 5033 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5034 | if (!Op) |
| 5035 | return ExprError(); |
| 5036 | |
| 5037 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 5038 | public: |
| 5039 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5040 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 5041 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 5042 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5043 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 5044 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5045 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 5046 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5047 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 5048 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5049 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 5050 | QualType T, |
| 5051 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5052 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 5053 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5054 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 5055 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5056 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5057 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5058 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5059 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 5060 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5061 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 5062 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5063 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 5064 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5065 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5066 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5067 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5068 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 5069 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5070 | llvm_unreachable("conversion functions are permitted"); |
| 5071 | } |
| 5072 | } ConvertDiagnoser; |
| 5073 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 5074 | } |
| 5075 | |
| 5076 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 5077 | SourceLocation StartLoc, |
| 5078 | SourceLocation LParenLoc, |
| 5079 | SourceLocation EndLoc) { |
| 5080 | Expr *ValExpr = NumThreads; |
| 5081 | if (!NumThreads->isValueDependent() && !NumThreads->isTypeDependent() && |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5082 | !NumThreads->containsUnexpandedParameterPack()) { |
| 5083 | SourceLocation NumThreadsLoc = NumThreads->getLocStart(); |
| 5084 | ExprResult Val = |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5085 | PerformOpenMPImplicitIntegerConversion(NumThreadsLoc, NumThreads); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5086 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5087 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5088 | |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5089 | ValExpr = Val.get(); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5090 | |
| 5091 | // OpenMP [2.5, Restrictions] |
| 5092 | // The num_threads expression must evaluate to a positive integer value. |
| 5093 | llvm::APSInt Result; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5094 | if (ValExpr->isIntegerConstantExpr(Result, Context) && Result.isSigned() && |
| 5095 | !Result.isStrictlyPositive()) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5096 | Diag(NumThreadsLoc, diag::err_omp_negative_expression_in_clause) |
| 5097 | << "num_threads" << NumThreads->getSourceRange(); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5098 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5099 | } |
| 5100 | } |
| 5101 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5102 | return new (Context) |
| 5103 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5104 | } |
| 5105 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5106 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
| 5107 | OpenMPClauseKind CKind) { |
| 5108 | if (!E) |
| 5109 | return ExprError(); |
| 5110 | if (E->isValueDependent() || E->isTypeDependent() || |
| 5111 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 5112 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5113 | llvm::APSInt Result; |
| 5114 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 5115 | if (ICE.isInvalid()) |
| 5116 | return ExprError(); |
| 5117 | if (!Result.isStrictlyPositive()) { |
| 5118 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
| 5119 | << getOpenMPClauseName(CKind) << E->getSourceRange(); |
| 5120 | return ExprError(); |
| 5121 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 5122 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 5123 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 5124 | << E->getSourceRange(); |
| 5125 | return ExprError(); |
| 5126 | } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5127 | if (CKind == OMPC_collapse) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5128 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 5129 | Result.getExtValue()); |
| 5130 | } else if (CKind == OMPC_ordered) { |
| 5131 | DSAStack->setCollapseNumber(DSAStack->getCollapseNumber() - 1 + |
| 5132 | Result.getExtValue()); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 5133 | } |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5134 | return ICE; |
| 5135 | } |
| 5136 | |
| 5137 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 5138 | SourceLocation LParenLoc, |
| 5139 | SourceLocation EndLoc) { |
| 5140 | // OpenMP [2.8.1, simd construct, Description] |
| 5141 | // The parameter of the safelen clause must be a constant |
| 5142 | // positive integer expression. |
| 5143 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 5144 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5145 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5146 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 5147 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5148 | } |
| 5149 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5150 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 5151 | SourceLocation LParenLoc, |
| 5152 | SourceLocation EndLoc) { |
| 5153 | // OpenMP [2.8.1, simd construct, Description] |
| 5154 | // The parameter of the simdlen clause must be a constant |
| 5155 | // positive integer expression. |
| 5156 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 5157 | if (Simdlen.isInvalid()) |
| 5158 | return nullptr; |
| 5159 | return new (Context) |
| 5160 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 5161 | } |
| 5162 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5163 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 5164 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5165 | SourceLocation LParenLoc, |
| 5166 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5167 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5168 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5169 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5170 | // The parameter of the collapse clause must be a constant |
| 5171 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5172 | ExprResult NumForLoopsResult = |
| 5173 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 5174 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5175 | return nullptr; |
| 5176 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 5177 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5178 | } |
| 5179 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5180 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 5181 | SourceLocation EndLoc, |
| 5182 | SourceLocation LParenLoc, |
| 5183 | Expr *NumForLoops) { |
| 5184 | DSAStack->setOrderedRegion(); |
| 5185 | // OpenMP [2.7.1, loop construct, Description] |
| 5186 | // OpenMP [2.8.1, simd construct, Description] |
| 5187 | // OpenMP [2.9.6, distribute construct, Description] |
| 5188 | // The parameter of the ordered clause must be a constant |
| 5189 | // positive integer expression if any. |
| 5190 | if (NumForLoops && LParenLoc.isValid()) { |
| 5191 | ExprResult NumForLoopsResult = |
| 5192 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 5193 | if (NumForLoopsResult.isInvalid()) |
| 5194 | return nullptr; |
| 5195 | NumForLoops = NumForLoopsResult.get(); |
| 5196 | } |
| 5197 | return new (Context) |
| 5198 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 5199 | } |
| 5200 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5201 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 5202 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 5203 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5204 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5205 | switch (Kind) { |
| 5206 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5207 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5208 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 5209 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5210 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5211 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5212 | Res = ActOnOpenMPProcBindClause( |
| 5213 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 5214 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5215 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5216 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5217 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5218 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5219 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5220 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5221 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5222 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5223 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5224 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5225 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5226 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5227 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5228 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5229 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5230 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5231 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5232 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5233 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5234 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5235 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5236 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5237 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5238 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5239 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5240 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5241 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5242 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5243 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5244 | case OMPC_device: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5245 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5246 | llvm_unreachable("Clause is not allowed."); |
| 5247 | } |
| 5248 | return Res; |
| 5249 | } |
| 5250 | |
| 5251 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 5252 | SourceLocation KindKwLoc, |
| 5253 | SourceLocation StartLoc, |
| 5254 | SourceLocation LParenLoc, |
| 5255 | SourceLocation EndLoc) { |
| 5256 | if (Kind == OMPC_DEFAULT_unknown) { |
| 5257 | std::string Values; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5258 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 5259 | "OMPC_DEFAULT_unknown not greater than 0"); |
Ted Kremenek | 725a097 | 2014-03-21 17:34:28 +0000 | [diff] [blame] | 5260 | std::string Sep(", "); |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5261 | for (unsigned i = 0; i < OMPC_DEFAULT_unknown; ++i) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5262 | Values += "'"; |
| 5263 | Values += getOpenMPSimpleClauseTypeName(OMPC_default, i); |
| 5264 | Values += "'"; |
| 5265 | switch (i) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5266 | case OMPC_DEFAULT_unknown - 2: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5267 | Values += " or "; |
| 5268 | break; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 5269 | case OMPC_DEFAULT_unknown - 1: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5270 | break; |
| 5271 | default: |
| 5272 | Values += Sep; |
| 5273 | break; |
| 5274 | } |
| 5275 | } |
| 5276 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5277 | << Values << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5278 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5279 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5280 | switch (Kind) { |
| 5281 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5282 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5283 | break; |
| 5284 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5285 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5286 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5287 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5288 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5289 | break; |
| 5290 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5291 | return new (Context) |
| 5292 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5293 | } |
| 5294 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5295 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 5296 | SourceLocation KindKwLoc, |
| 5297 | SourceLocation StartLoc, |
| 5298 | SourceLocation LParenLoc, |
| 5299 | SourceLocation EndLoc) { |
| 5300 | if (Kind == OMPC_PROC_BIND_unknown) { |
| 5301 | std::string Values; |
| 5302 | std::string Sep(", "); |
| 5303 | for (unsigned i = 0; i < OMPC_PROC_BIND_unknown; ++i) { |
| 5304 | Values += "'"; |
| 5305 | Values += getOpenMPSimpleClauseTypeName(OMPC_proc_bind, i); |
| 5306 | Values += "'"; |
| 5307 | switch (i) { |
| 5308 | case OMPC_PROC_BIND_unknown - 2: |
| 5309 | Values += " or "; |
| 5310 | break; |
| 5311 | case OMPC_PROC_BIND_unknown - 1: |
| 5312 | break; |
| 5313 | default: |
| 5314 | Values += Sep; |
| 5315 | break; |
| 5316 | } |
| 5317 | } |
| 5318 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5319 | << Values << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5320 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5321 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5322 | return new (Context) |
| 5323 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5324 | } |
| 5325 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5326 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
| 5327 | OpenMPClauseKind Kind, unsigned Argument, Expr *Expr, |
| 5328 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5329 | SourceLocation ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5330 | SourceLocation EndLoc) { |
| 5331 | OMPClause *Res = nullptr; |
| 5332 | switch (Kind) { |
| 5333 | case OMPC_schedule: |
| 5334 | Res = ActOnOpenMPScheduleClause( |
| 5335 | static_cast<OpenMPScheduleClauseKind>(Argument), Expr, StartLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5336 | LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5337 | break; |
| 5338 | case OMPC_if: |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5339 | Res = |
| 5340 | ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument), Expr, |
| 5341 | StartLoc, LParenLoc, ArgumentLoc, DelimLoc, EndLoc); |
| 5342 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5343 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5344 | case OMPC_num_threads: |
| 5345 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5346 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5347 | case OMPC_collapse: |
| 5348 | case OMPC_default: |
| 5349 | case OMPC_proc_bind: |
| 5350 | case OMPC_private: |
| 5351 | case OMPC_firstprivate: |
| 5352 | case OMPC_lastprivate: |
| 5353 | case OMPC_shared: |
| 5354 | case OMPC_reduction: |
| 5355 | case OMPC_linear: |
| 5356 | case OMPC_aligned: |
| 5357 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5358 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5359 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5360 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5361 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5362 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5363 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5364 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5365 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5366 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5367 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5368 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5369 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5370 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5371 | case OMPC_device: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5372 | case OMPC_unknown: |
| 5373 | llvm_unreachable("Clause is not allowed."); |
| 5374 | } |
| 5375 | return Res; |
| 5376 | } |
| 5377 | |
| 5378 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
| 5379 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 5380 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 5381 | SourceLocation EndLoc) { |
| 5382 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 5383 | std::string Values; |
| 5384 | std::string Sep(", "); |
| 5385 | for (unsigned i = 0; i < OMPC_SCHEDULE_unknown; ++i) { |
| 5386 | Values += "'"; |
| 5387 | Values += getOpenMPSimpleClauseTypeName(OMPC_schedule, i); |
| 5388 | Values += "'"; |
| 5389 | switch (i) { |
| 5390 | case OMPC_SCHEDULE_unknown - 2: |
| 5391 | Values += " or "; |
| 5392 | break; |
| 5393 | case OMPC_SCHEDULE_unknown - 1: |
| 5394 | break; |
| 5395 | default: |
| 5396 | Values += Sep; |
| 5397 | break; |
| 5398 | } |
| 5399 | } |
| 5400 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 5401 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 5402 | return nullptr; |
| 5403 | } |
| 5404 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5405 | Expr *HelperValExpr = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5406 | if (ChunkSize) { |
| 5407 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 5408 | !ChunkSize->isInstantiationDependent() && |
| 5409 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 5410 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 5411 | ExprResult Val = |
| 5412 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 5413 | if (Val.isInvalid()) |
| 5414 | return nullptr; |
| 5415 | |
| 5416 | ValExpr = Val.get(); |
| 5417 | |
| 5418 | // OpenMP [2.7.1, Restrictions] |
| 5419 | // chunk_size must be a loop invariant integer expression with a positive |
| 5420 | // value. |
| 5421 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5422 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 5423 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 5424 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 5425 | << "schedule" << ChunkSize->getSourceRange(); |
| 5426 | return nullptr; |
| 5427 | } |
| 5428 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 5429 | auto *ImpVar = buildVarDecl(*this, ChunkSize->getExprLoc(), |
| 5430 | ChunkSize->getType(), ".chunk."); |
| 5431 | auto *ImpVarRef = buildDeclRefExpr(*this, ImpVar, ChunkSize->getType(), |
| 5432 | ChunkSize->getExprLoc(), |
| 5433 | /*RefersToCapture=*/true); |
| 5434 | HelperValExpr = ImpVarRef; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5435 | } |
| 5436 | } |
| 5437 | } |
| 5438 | |
| 5439 | return new (Context) OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 5440 | EndLoc, Kind, ValExpr, HelperValExpr); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5441 | } |
| 5442 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5443 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 5444 | SourceLocation StartLoc, |
| 5445 | SourceLocation EndLoc) { |
| 5446 | OMPClause *Res = nullptr; |
| 5447 | switch (Kind) { |
| 5448 | case OMPC_ordered: |
| 5449 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 5450 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5451 | case OMPC_nowait: |
| 5452 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 5453 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5454 | case OMPC_untied: |
| 5455 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 5456 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5457 | case OMPC_mergeable: |
| 5458 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 5459 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5460 | case OMPC_read: |
| 5461 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 5462 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5463 | case OMPC_write: |
| 5464 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 5465 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5466 | case OMPC_update: |
| 5467 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 5468 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5469 | case OMPC_capture: |
| 5470 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 5471 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5472 | case OMPC_seq_cst: |
| 5473 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 5474 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5475 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5476 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5477 | case OMPC_num_threads: |
| 5478 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5479 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5480 | case OMPC_collapse: |
| 5481 | case OMPC_schedule: |
| 5482 | case OMPC_private: |
| 5483 | case OMPC_firstprivate: |
| 5484 | case OMPC_lastprivate: |
| 5485 | case OMPC_shared: |
| 5486 | case OMPC_reduction: |
| 5487 | case OMPC_linear: |
| 5488 | case OMPC_aligned: |
| 5489 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5490 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5491 | case OMPC_default: |
| 5492 | case OMPC_proc_bind: |
| 5493 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5494 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5495 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5496 | case OMPC_device: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5497 | case OMPC_unknown: |
| 5498 | llvm_unreachable("Clause is not allowed."); |
| 5499 | } |
| 5500 | return Res; |
| 5501 | } |
| 5502 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5503 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 5504 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5505 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5506 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 5507 | } |
| 5508 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5509 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 5510 | SourceLocation EndLoc) { |
| 5511 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 5512 | } |
| 5513 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5514 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 5515 | SourceLocation EndLoc) { |
| 5516 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 5517 | } |
| 5518 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5519 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 5520 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5521 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 5522 | } |
| 5523 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5524 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 5525 | SourceLocation EndLoc) { |
| 5526 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 5527 | } |
| 5528 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5529 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 5530 | SourceLocation EndLoc) { |
| 5531 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 5532 | } |
| 5533 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5534 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 5535 | SourceLocation EndLoc) { |
| 5536 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 5537 | } |
| 5538 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5539 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 5540 | SourceLocation EndLoc) { |
| 5541 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 5542 | } |
| 5543 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5544 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 5545 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 5546 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 5547 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5548 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5549 | OpenMPLinearClauseKind LinKind, SourceLocation DepLinLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 5550 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5551 | switch (Kind) { |
| 5552 | case OMPC_private: |
| 5553 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5554 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5555 | case OMPC_firstprivate: |
| 5556 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5557 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5558 | case OMPC_lastprivate: |
| 5559 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5560 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5561 | case OMPC_shared: |
| 5562 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5563 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5564 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 5565 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 5566 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 5567 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5568 | case OMPC_linear: |
| 5569 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5570 | LinKind, DepLinLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 5571 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 5572 | case OMPC_aligned: |
| 5573 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 5574 | ColonLoc, EndLoc); |
| 5575 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 5576 | case OMPC_copyin: |
| 5577 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5578 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 5579 | case OMPC_copyprivate: |
| 5580 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5581 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5582 | case OMPC_flush: |
| 5583 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 5584 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5585 | case OMPC_depend: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 5586 | Res = ActOnOpenMPDependClause(DepKind, DepLinLoc, ColonLoc, VarList, StartLoc, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 5587 | LParenLoc, EndLoc); |
| 5588 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 5589 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 5590 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 5591 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 5592 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5593 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 5594 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5595 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 5596 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 5597 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 5598 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 5599 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 5600 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 5601 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5602 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5603 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5604 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5605 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5606 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 5607 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 5608 | case OMPC_device: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5609 | case OMPC_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5610 | llvm_unreachable("Clause is not allowed."); |
| 5611 | } |
| 5612 | return Res; |
| 5613 | } |
| 5614 | |
| 5615 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 5616 | SourceLocation StartLoc, |
| 5617 | SourceLocation LParenLoc, |
| 5618 | SourceLocation EndLoc) { |
| 5619 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5620 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5621 | for (auto &RefExpr : VarList) { |
| 5622 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
| 5623 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5624 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5625 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5626 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5627 | continue; |
| 5628 | } |
| 5629 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5630 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5631 | // OpenMP [2.1, C/C++] |
| 5632 | // A list item is a variable name. |
| 5633 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5634 | // A variable that is part of another variable (as an array or |
| 5635 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5636 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5637 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5638 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5639 | continue; |
| 5640 | } |
| 5641 | Decl *D = DE->getDecl(); |
| 5642 | VarDecl *VD = cast<VarDecl>(D); |
| 5643 | |
| 5644 | QualType Type = VD->getType(); |
| 5645 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5646 | // It will be analyzed later. |
| 5647 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5648 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5649 | continue; |
| 5650 | } |
| 5651 | |
| 5652 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5653 | // A variable that appears in a private clause must not have an incomplete |
| 5654 | // type or a reference type. |
| 5655 | if (RequireCompleteType(ELoc, Type, |
| 5656 | diag::err_omp_private_incomplete_type)) { |
| 5657 | continue; |
| 5658 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5659 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5660 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5661 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5662 | // in a Construct] |
| 5663 | // Variables with the predetermined data-sharing attributes may not be |
| 5664 | // listed in data-sharing attributes clauses, except for the cases |
| 5665 | // listed below. For these exceptions only, listing a predetermined |
| 5666 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5667 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5668 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5669 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5670 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 5671 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5672 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5673 | continue; |
| 5674 | } |
| 5675 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5676 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5677 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5678 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5679 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5680 | << getOpenMPClauseName(OMPC_private) << Type |
| 5681 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5682 | bool IsDecl = |
| 5683 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5684 | Diag(VD->getLocation(), |
| 5685 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5686 | << VD; |
| 5687 | continue; |
| 5688 | } |
| 5689 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5690 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 5691 | // A variable of class type (or array thereof) that appears in a private |
| 5692 | // clause requires an accessible, unambiguous default constructor for the |
| 5693 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5694 | // Generate helper private variable and initialize it with the default |
| 5695 | // value. The address of the original variable is replaced by the address of |
| 5696 | // the new private variable in CodeGen. This new variable is not added to |
| 5697 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 5698 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5699 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 5700 | auto VDPrivate = buildVarDecl(*this, DE->getExprLoc(), Type, VD->getName(), |
| 5701 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5702 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5703 | if (VDPrivate->isInvalidDecl()) |
| 5704 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5705 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5706 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5707 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 5708 | DSAStack->addDSA(VD, DE, OMPC_private); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5709 | Vars.push_back(DE); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5710 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5711 | } |
| 5712 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5713 | if (Vars.empty()) |
| 5714 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5715 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 5716 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 5717 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 5718 | } |
| 5719 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5720 | namespace { |
| 5721 | class DiagsUninitializedSeveretyRAII { |
| 5722 | private: |
| 5723 | DiagnosticsEngine &Diags; |
| 5724 | SourceLocation SavedLoc; |
| 5725 | bool IsIgnored; |
| 5726 | |
| 5727 | public: |
| 5728 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 5729 | bool IsIgnored) |
| 5730 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 5731 | if (!IsIgnored) { |
| 5732 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 5733 | /*Map*/ diag::Severity::Ignored, Loc); |
| 5734 | } |
| 5735 | } |
| 5736 | ~DiagsUninitializedSeveretyRAII() { |
| 5737 | if (!IsIgnored) |
| 5738 | Diags.popMappings(SavedLoc); |
| 5739 | } |
| 5740 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 5741 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5742 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5743 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 5744 | SourceLocation StartLoc, |
| 5745 | SourceLocation LParenLoc, |
| 5746 | SourceLocation EndLoc) { |
| 5747 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5748 | SmallVector<Expr *, 8> PrivateCopies; |
| 5749 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5750 | bool IsImplicitClause = |
| 5751 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 5752 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 5753 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5754 | for (auto &RefExpr : VarList) { |
| 5755 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
| 5756 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5757 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5758 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5759 | PrivateCopies.push_back(nullptr); |
| 5760 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5761 | continue; |
| 5762 | } |
| 5763 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5764 | SourceLocation ELoc = |
| 5765 | IsImplicitClause ? ImplicitClauseLoc : RefExpr->getExprLoc(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5766 | // OpenMP [2.1, C/C++] |
| 5767 | // A list item is a variable name. |
| 5768 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 5769 | // A variable that is part of another variable (as an array or |
| 5770 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5771 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5772 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5773 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5774 | continue; |
| 5775 | } |
| 5776 | Decl *D = DE->getDecl(); |
| 5777 | VarDecl *VD = cast<VarDecl>(D); |
| 5778 | |
| 5779 | QualType Type = VD->getType(); |
| 5780 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5781 | // It will be analyzed later. |
| 5782 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5783 | PrivateCopies.push_back(nullptr); |
| 5784 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5785 | continue; |
| 5786 | } |
| 5787 | |
| 5788 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 5789 | // A variable that appears in a private clause must not have an incomplete |
| 5790 | // type or a reference type. |
| 5791 | if (RequireCompleteType(ELoc, Type, |
| 5792 | diag::err_omp_firstprivate_incomplete_type)) { |
| 5793 | continue; |
| 5794 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 5795 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5796 | |
| 5797 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 5798 | // 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] | 5799 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5800 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5801 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5802 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5803 | // If an implicit firstprivate variable found it was checked already. |
| 5804 | if (!IsImplicitClause) { |
| 5805 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5806 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5807 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 5808 | // A list item that specifies a given variable may not appear in more |
| 5809 | // than one clause on the same directive, except that a variable may be |
| 5810 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5811 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5812 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5813 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5814 | << getOpenMPClauseName(DVar.CKind) |
| 5815 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5816 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5817 | continue; |
| 5818 | } |
| 5819 | |
| 5820 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5821 | // in a Construct] |
| 5822 | // Variables with the predetermined data-sharing attributes may not be |
| 5823 | // listed in data-sharing attributes clauses, except for the cases |
| 5824 | // listed below. For these exceptions only, listing a predetermined |
| 5825 | // variable in a data-sharing attribute clause is allowed and overrides |
| 5826 | // the variable's predetermined data-sharing attributes. |
| 5827 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 5828 | // in a Construct, C/C++, p.2] |
| 5829 | // Variables with const-qualified type having no mutable member may be |
| 5830 | // listed in a firstprivate clause, even if they are static data members. |
| 5831 | if (!(IsConstant || VD->isStaticDataMember()) && !DVar.RefExpr && |
| 5832 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 5833 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5834 | << getOpenMPClauseName(DVar.CKind) |
| 5835 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5836 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5837 | continue; |
| 5838 | } |
| 5839 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5840 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5841 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 5842 | // A list item that is private within a parallel region must not appear |
| 5843 | // in a firstprivate clause on a worksharing construct if any of the |
| 5844 | // worksharing regions arising from the worksharing construct ever bind |
| 5845 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 5846 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 5847 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5848 | DVar = DSAStack->getImplicitDSA(VD, true); |
| 5849 | if (DVar.CKind != OMPC_shared && |
| 5850 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5851 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5852 | Diag(ELoc, diag::err_omp_required_access) |
| 5853 | << getOpenMPClauseName(OMPC_firstprivate) |
| 5854 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 5855 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5856 | continue; |
| 5857 | } |
| 5858 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5859 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 5860 | // A list item that appears in a reduction clause of a parallel construct |
| 5861 | // must not appear in a firstprivate clause on a worksharing or task |
| 5862 | // construct if any of the worksharing or task regions arising from the |
| 5863 | // worksharing or task construct ever bind to any of the parallel regions |
| 5864 | // arising from the parallel construct. |
| 5865 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 5866 | // A list item that appears in a reduction clause in worksharing |
| 5867 | // construct must not appear in a firstprivate clause in a task construct |
| 5868 | // encountered during execution of any of the worksharing regions arising |
| 5869 | // from the worksharing construct. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5870 | if (CurrDir == OMPD_task) { |
| 5871 | DVar = |
| 5872 | DSAStack->hasInnermostDSA(VD, MatchesAnyClause(OMPC_reduction), |
| 5873 | [](OpenMPDirectiveKind K) -> bool { |
| 5874 | return isOpenMPParallelDirective(K) || |
| 5875 | isOpenMPWorksharingDirective(K); |
| 5876 | }, |
| 5877 | false); |
| 5878 | if (DVar.CKind == OMPC_reduction && |
| 5879 | (isOpenMPParallelDirective(DVar.DKind) || |
| 5880 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 5881 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 5882 | << getOpenMPDirectiveName(DVar.DKind); |
| 5883 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 5884 | continue; |
| 5885 | } |
| 5886 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5887 | } |
| 5888 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5889 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 5890 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 5891 | DSAStack->getCurrentDirective() == OMPD_task) { |
| 5892 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 5893 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 5894 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 5895 | bool IsDecl = |
| 5896 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 5897 | Diag(VD->getLocation(), |
| 5898 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 5899 | << VD; |
| 5900 | continue; |
| 5901 | } |
| 5902 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5903 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 5904 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 5905 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5906 | // Generate helper private variable and initialize it with the value of the |
| 5907 | // original variable. The address of the original variable is replaced by |
| 5908 | // the address of the new private variable in the CodeGen. This new variable |
| 5909 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 5910 | // original variable for proper diagnostics and variable capturing. |
| 5911 | Expr *VDInitRefExpr = nullptr; |
| 5912 | // For arrays generate initializer for single element and replace it by the |
| 5913 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5914 | if (Type->isArrayType()) { |
| 5915 | auto VDInit = |
| 5916 | buildVarDecl(*this, DE->getExprLoc(), ElemType, VD->getName()); |
| 5917 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5918 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5919 | ElemType = ElemType.getUnqualifiedType(); |
| 5920 | auto *VDInitTemp = buildVarDecl(*this, DE->getLocStart(), ElemType, |
| 5921 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5922 | InitializedEntity Entity = |
| 5923 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5924 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 5925 | |
| 5926 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 5927 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 5928 | if (Result.isInvalid()) |
| 5929 | VDPrivate->setInvalidDecl(); |
| 5930 | else |
| 5931 | VDPrivate->setInit(Result.getAs<Expr>()); |
| 5932 | } else { |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5933 | auto *VDInit = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5934 | buildVarDecl(*this, DE->getLocStart(), Type, ".firstprivate.temp"); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 5935 | VDInitRefExpr = |
| 5936 | buildDeclRefExpr(*this, VDInit, DE->getType(), DE->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 5937 | AddInitializerToDecl(VDPrivate, |
| 5938 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 5939 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5940 | } |
| 5941 | if (VDPrivate->isInvalidDecl()) { |
| 5942 | if (IsImplicitClause) { |
| 5943 | Diag(DE->getExprLoc(), |
| 5944 | diag::note_omp_task_predetermined_firstprivate_here); |
| 5945 | } |
| 5946 | continue; |
| 5947 | } |
| 5948 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5949 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 5950 | *this, VDPrivate, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5951 | DSAStack->addDSA(VD, DE, OMPC_firstprivate); |
| 5952 | Vars.push_back(DE); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5953 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 5954 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5955 | } |
| 5956 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 5957 | if (Vars.empty()) |
| 5958 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5959 | |
| 5960 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 5961 | Vars, PrivateCopies, Inits); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 5962 | } |
| 5963 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5964 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 5965 | SourceLocation StartLoc, |
| 5966 | SourceLocation LParenLoc, |
| 5967 | SourceLocation EndLoc) { |
| 5968 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5969 | SmallVector<Expr *, 8> SrcExprs; |
| 5970 | SmallVector<Expr *, 8> DstExprs; |
| 5971 | SmallVector<Expr *, 8> AssignmentOps; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5972 | for (auto &RefExpr : VarList) { |
| 5973 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
| 5974 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 5975 | // It will be analyzed later. |
| 5976 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 5977 | SrcExprs.push_back(nullptr); |
| 5978 | DstExprs.push_back(nullptr); |
| 5979 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 5980 | continue; |
| 5981 | } |
| 5982 | |
| 5983 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 5984 | // OpenMP [2.1, C/C++] |
| 5985 | // A list item is a variable name. |
| 5986 | // OpenMP [2.14.3.5, Restrictions, p.1] |
| 5987 | // A variable that is part of another variable (as an array or structure |
| 5988 | // element) cannot appear in a lastprivate clause. |
| 5989 | DeclRefExpr *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 5990 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 5991 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 5992 | continue; |
| 5993 | } |
| 5994 | Decl *D = DE->getDecl(); |
| 5995 | VarDecl *VD = cast<VarDecl>(D); |
| 5996 | |
| 5997 | QualType Type = VD->getType(); |
| 5998 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 5999 | // It will be analyzed later. |
| 6000 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6001 | SrcExprs.push_back(nullptr); |
| 6002 | DstExprs.push_back(nullptr); |
| 6003 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6004 | continue; |
| 6005 | } |
| 6006 | |
| 6007 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 6008 | // A variable that appears in a lastprivate clause must not have an |
| 6009 | // incomplete type or a reference type. |
| 6010 | if (RequireCompleteType(ELoc, Type, |
| 6011 | diag::err_omp_lastprivate_incomplete_type)) { |
| 6012 | continue; |
| 6013 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6014 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6015 | |
| 6016 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6017 | // in a Construct] |
| 6018 | // Variables with the predetermined data-sharing attributes may not be |
| 6019 | // listed in data-sharing attributes clauses, except for the cases |
| 6020 | // listed below. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6021 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6022 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 6023 | DVar.CKind != OMPC_firstprivate && |
| 6024 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 6025 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6026 | << getOpenMPClauseName(DVar.CKind) |
| 6027 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6028 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6029 | continue; |
| 6030 | } |
| 6031 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6032 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 6033 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 6034 | // A list item that is private within a parallel region, or that appears in |
| 6035 | // the reduction clause of a parallel construct, must not appear in a |
| 6036 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 6037 | // worksharing regions ever binds to any of the corresponding parallel |
| 6038 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6039 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6040 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6041 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6042 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6043 | if (DVar.CKind != OMPC_shared) { |
| 6044 | Diag(ELoc, diag::err_omp_required_access) |
| 6045 | << getOpenMPClauseName(OMPC_lastprivate) |
| 6046 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6047 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6048 | continue; |
| 6049 | } |
| 6050 | } |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6051 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6052 | // A variable of class type (or array thereof) that appears in a |
| 6053 | // lastprivate clause requires an accessible, unambiguous default |
| 6054 | // constructor for the class type, unless the list item is also specified |
| 6055 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6056 | // A variable of class type (or array thereof) that appears in a |
| 6057 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 6058 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6059 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6060 | auto *SrcVD = buildVarDecl(*this, DE->getLocStart(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6061 | Type.getUnqualifiedType(), ".lastprivate.src", |
| 6062 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6063 | auto *PseudoSrcExpr = buildDeclRefExpr( |
| 6064 | *this, SrcVD, Type.getUnqualifiedType(), DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6065 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6066 | buildVarDecl(*this, DE->getLocStart(), Type, ".lastprivate.dst", |
| 6067 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6068 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6069 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6070 | // For arrays generate assignment operation for single element and replace |
| 6071 | // it by the original array element in CodeGen. |
| 6072 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6073 | PseudoDstExpr, PseudoSrcExpr); |
| 6074 | if (AssignmentOp.isInvalid()) |
| 6075 | continue; |
| 6076 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6077 | /*DiscardedValue=*/true); |
| 6078 | if (AssignmentOp.isInvalid()) |
| 6079 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6080 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6081 | if (TopDVar.CKind != OMPC_firstprivate) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6082 | DSAStack->addDSA(VD, DE, OMPC_lastprivate); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6083 | Vars.push_back(DE); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6084 | SrcExprs.push_back(PseudoSrcExpr); |
| 6085 | DstExprs.push_back(PseudoDstExpr); |
| 6086 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6087 | } |
| 6088 | |
| 6089 | if (Vars.empty()) |
| 6090 | return nullptr; |
| 6091 | |
| 6092 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 6093 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6094 | } |
| 6095 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6096 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 6097 | SourceLocation StartLoc, |
| 6098 | SourceLocation LParenLoc, |
| 6099 | SourceLocation EndLoc) { |
| 6100 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6101 | for (auto &RefExpr : VarList) { |
| 6102 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 6103 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6104 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6105 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6106 | continue; |
| 6107 | } |
| 6108 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6109 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6110 | // OpenMP [2.1, C/C++] |
| 6111 | // A list item is a variable name. |
Alexey Bataev | d4dbdf5 | 2014-03-06 12:27:56 +0000 | [diff] [blame] | 6112 | // OpenMP [2.14.3.2, Restrictions, p.1] |
| 6113 | // A variable that is part of another variable (as an array or structure |
| 6114 | // element) cannot appear in a shared unless it is a static data member |
| 6115 | // of a C++ class. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6116 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6117 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6118 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6119 | continue; |
| 6120 | } |
| 6121 | Decl *D = DE->getDecl(); |
| 6122 | VarDecl *VD = cast<VarDecl>(D); |
| 6123 | |
| 6124 | QualType Type = VD->getType(); |
| 6125 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6126 | // It will be analyzed later. |
| 6127 | Vars.push_back(DE); |
| 6128 | continue; |
| 6129 | } |
| 6130 | |
| 6131 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6132 | // in a Construct] |
| 6133 | // Variables with the predetermined data-sharing attributes may not be |
| 6134 | // listed in data-sharing attributes clauses, except for the cases |
| 6135 | // listed below. For these exceptions only, listing a predetermined |
| 6136 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6137 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6138 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6139 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 6140 | DVar.RefExpr) { |
| 6141 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6142 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6143 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6144 | continue; |
| 6145 | } |
| 6146 | |
| 6147 | DSAStack->addDSA(VD, DE, OMPC_shared); |
| 6148 | Vars.push_back(DE); |
| 6149 | } |
| 6150 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6151 | if (Vars.empty()) |
| 6152 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6153 | |
| 6154 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 6155 | } |
| 6156 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6157 | namespace { |
| 6158 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 6159 | DSAStackTy *Stack; |
| 6160 | |
| 6161 | public: |
| 6162 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 6163 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6164 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6165 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 6166 | return false; |
| 6167 | if (DVar.CKind != OMPC_unknown) |
| 6168 | return true; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6169 | DSAStackTy::DSAVarData DVarPrivate = |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6170 | Stack->hasDSA(VD, isOpenMPPrivate, MatchesAlways(), false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6171 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6172 | return true; |
| 6173 | return false; |
| 6174 | } |
| 6175 | return false; |
| 6176 | } |
| 6177 | bool VisitStmt(Stmt *S) { |
| 6178 | for (auto Child : S->children()) { |
| 6179 | if (Child && Visit(Child)) |
| 6180 | return true; |
| 6181 | } |
| 6182 | return false; |
| 6183 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6184 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6185 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6186 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6187 | |
| 6188 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 6189 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 6190 | SourceLocation ColonLoc, SourceLocation EndLoc, |
| 6191 | CXXScopeSpec &ReductionIdScopeSpec, |
| 6192 | const DeclarationNameInfo &ReductionId) { |
| 6193 | // TODO: Allow scope specification search when 'declare reduction' is |
| 6194 | // supported. |
| 6195 | assert(ReductionIdScopeSpec.isEmpty() && |
| 6196 | "No support for scoped reduction identifiers yet."); |
| 6197 | |
| 6198 | auto DN = ReductionId.getName(); |
| 6199 | auto OOK = DN.getCXXOverloadedOperator(); |
| 6200 | BinaryOperatorKind BOK = BO_Comma; |
| 6201 | |
| 6202 | // OpenMP [2.14.3.6, reduction clause] |
| 6203 | // C |
| 6204 | // reduction-identifier is either an identifier or one of the following |
| 6205 | // operators: +, -, *, &, |, ^, && and || |
| 6206 | // C++ |
| 6207 | // reduction-identifier is either an id-expression or one of the following |
| 6208 | // operators: +, -, *, &, |, ^, && and || |
| 6209 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 6210 | switch (OOK) { |
| 6211 | case OO_Plus: |
| 6212 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6213 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6214 | break; |
| 6215 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6216 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6217 | break; |
| 6218 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6219 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6220 | break; |
| 6221 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6222 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6223 | break; |
| 6224 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6225 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6226 | break; |
| 6227 | case OO_AmpAmp: |
| 6228 | BOK = BO_LAnd; |
| 6229 | break; |
| 6230 | case OO_PipePipe: |
| 6231 | BOK = BO_LOr; |
| 6232 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6233 | case OO_New: |
| 6234 | case OO_Delete: |
| 6235 | case OO_Array_New: |
| 6236 | case OO_Array_Delete: |
| 6237 | case OO_Slash: |
| 6238 | case OO_Percent: |
| 6239 | case OO_Tilde: |
| 6240 | case OO_Exclaim: |
| 6241 | case OO_Equal: |
| 6242 | case OO_Less: |
| 6243 | case OO_Greater: |
| 6244 | case OO_LessEqual: |
| 6245 | case OO_GreaterEqual: |
| 6246 | case OO_PlusEqual: |
| 6247 | case OO_MinusEqual: |
| 6248 | case OO_StarEqual: |
| 6249 | case OO_SlashEqual: |
| 6250 | case OO_PercentEqual: |
| 6251 | case OO_CaretEqual: |
| 6252 | case OO_AmpEqual: |
| 6253 | case OO_PipeEqual: |
| 6254 | case OO_LessLess: |
| 6255 | case OO_GreaterGreater: |
| 6256 | case OO_LessLessEqual: |
| 6257 | case OO_GreaterGreaterEqual: |
| 6258 | case OO_EqualEqual: |
| 6259 | case OO_ExclaimEqual: |
| 6260 | case OO_PlusPlus: |
| 6261 | case OO_MinusMinus: |
| 6262 | case OO_Comma: |
| 6263 | case OO_ArrowStar: |
| 6264 | case OO_Arrow: |
| 6265 | case OO_Call: |
| 6266 | case OO_Subscript: |
| 6267 | case OO_Conditional: |
| 6268 | case NUM_OVERLOADED_OPERATORS: |
| 6269 | llvm_unreachable("Unexpected reduction identifier"); |
| 6270 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6271 | if (auto II = DN.getAsIdentifierInfo()) { |
| 6272 | if (II->isStr("max")) |
| 6273 | BOK = BO_GT; |
| 6274 | else if (II->isStr("min")) |
| 6275 | BOK = BO_LT; |
| 6276 | } |
| 6277 | break; |
| 6278 | } |
| 6279 | SourceRange ReductionIdRange; |
| 6280 | if (ReductionIdScopeSpec.isValid()) { |
| 6281 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
| 6282 | } |
| 6283 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
| 6284 | if (BOK == BO_Comma) { |
| 6285 | // Not allowed reduction identifier is found. |
| 6286 | Diag(ReductionId.getLocStart(), diag::err_omp_unknown_reduction_identifier) |
| 6287 | << ReductionIdRange; |
| 6288 | return nullptr; |
| 6289 | } |
| 6290 | |
| 6291 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6292 | SmallVector<Expr *, 8> LHSs; |
| 6293 | SmallVector<Expr *, 8> RHSs; |
| 6294 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6295 | for (auto RefExpr : VarList) { |
| 6296 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
| 6297 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6298 | // It will be analyzed later. |
| 6299 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6300 | LHSs.push_back(nullptr); |
| 6301 | RHSs.push_back(nullptr); |
| 6302 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6303 | continue; |
| 6304 | } |
| 6305 | |
| 6306 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 6307 | RefExpr->isInstantiationDependent() || |
| 6308 | RefExpr->containsUnexpandedParameterPack()) { |
| 6309 | // It will be analyzed later. |
| 6310 | Vars.push_back(RefExpr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6311 | LHSs.push_back(nullptr); |
| 6312 | RHSs.push_back(nullptr); |
| 6313 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6314 | continue; |
| 6315 | } |
| 6316 | |
| 6317 | auto ELoc = RefExpr->getExprLoc(); |
| 6318 | auto ERange = RefExpr->getSourceRange(); |
| 6319 | // OpenMP [2.1, C/C++] |
| 6320 | // A list item is a variable or array section, subject to the restrictions |
| 6321 | // specified in Section 2.4 on page 42 and in each of the sections |
| 6322 | // describing clauses and directives for which a list appears. |
| 6323 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6324 | // A variable that is part of another variable (as an array or |
| 6325 | // structure element) cannot appear in a private clause. |
| 6326 | auto DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6327 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6328 | Diag(ELoc, diag::err_omp_expected_var_name) << ERange; |
| 6329 | continue; |
| 6330 | } |
| 6331 | auto D = DE->getDecl(); |
| 6332 | auto VD = cast<VarDecl>(D); |
| 6333 | auto Type = VD->getType(); |
| 6334 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 6335 | // A variable that appears in a private clause must not have an incomplete |
| 6336 | // type or a reference type. |
| 6337 | if (RequireCompleteType(ELoc, Type, |
| 6338 | diag::err_omp_reduction_incomplete_type)) |
| 6339 | continue; |
| 6340 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6341 | // Arrays may not appear in a reduction clause. |
| 6342 | if (Type.getNonReferenceType()->isArrayType()) { |
| 6343 | Diag(ELoc, diag::err_omp_reduction_type_array) << Type << ERange; |
| 6344 | bool IsDecl = |
| 6345 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6346 | Diag(VD->getLocation(), |
| 6347 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6348 | << VD; |
| 6349 | continue; |
| 6350 | } |
| 6351 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6352 | // A list item that appears in a reduction clause must not be |
| 6353 | // const-qualified. |
| 6354 | if (Type.getNonReferenceType().isConstant(Context)) { |
| 6355 | Diag(ELoc, diag::err_omp_const_variable) |
| 6356 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
| 6357 | bool IsDecl = |
| 6358 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6359 | Diag(VD->getLocation(), |
| 6360 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6361 | << VD; |
| 6362 | continue; |
| 6363 | } |
| 6364 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 6365 | // If a list-item is a reference type then it must bind to the same object |
| 6366 | // for all threads of the team. |
| 6367 | VarDecl *VDDef = VD->getDefinition(); |
| 6368 | if (Type->isReferenceType() && VDDef) { |
| 6369 | DSARefChecker Check(DSAStack); |
| 6370 | if (Check.Visit(VDDef->getInit())) { |
| 6371 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 6372 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 6373 | continue; |
| 6374 | } |
| 6375 | } |
| 6376 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 6377 | // The type of a list item that appears in a reduction clause must be valid |
| 6378 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 6379 | // of the list item must be an allowed arithmetic data type: char, int, |
| 6380 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 6381 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 6382 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 6383 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 6384 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 6385 | !(Type->isScalarType() || |
| 6386 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 6387 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 6388 | << getLangOpts().CPlusPlus; |
| 6389 | bool IsDecl = |
| 6390 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6391 | Diag(VD->getLocation(), |
| 6392 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6393 | << VD; |
| 6394 | continue; |
| 6395 | } |
| 6396 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 6397 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 6398 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 6399 | bool IsDecl = |
| 6400 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6401 | Diag(VD->getLocation(), |
| 6402 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6403 | << VD; |
| 6404 | continue; |
| 6405 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6406 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 6407 | // in a Construct] |
| 6408 | // Variables with the predetermined data-sharing attributes may not be |
| 6409 | // listed in data-sharing attributes clauses, except for the cases |
| 6410 | // listed below. For these exceptions only, listing a predetermined |
| 6411 | // variable in a data-sharing attribute clause is allowed and overrides |
| 6412 | // the variable's predetermined data-sharing attributes. |
| 6413 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 6414 | // Any number of reduction clauses can be specified on the directive, |
| 6415 | // but a list item can appear only once in the reduction clauses for that |
| 6416 | // directive. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6417 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6418 | if (DVar.CKind == OMPC_reduction) { |
| 6419 | Diag(ELoc, diag::err_omp_once_referenced) |
| 6420 | << getOpenMPClauseName(OMPC_reduction); |
| 6421 | if (DVar.RefExpr) { |
| 6422 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
| 6423 | } |
| 6424 | } else if (DVar.CKind != OMPC_unknown) { |
| 6425 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 6426 | << getOpenMPClauseName(DVar.CKind) |
| 6427 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6428 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6429 | continue; |
| 6430 | } |
| 6431 | |
| 6432 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 6433 | // A list item that appears in a reduction clause of a worksharing |
| 6434 | // construct must be shared in the parallel regions to which any of the |
| 6435 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6436 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 6437 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 6438 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6439 | DVar = DSAStack->getImplicitDSA(VD, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6440 | if (DVar.CKind != OMPC_shared) { |
| 6441 | Diag(ELoc, diag::err_omp_required_access) |
| 6442 | << getOpenMPClauseName(OMPC_reduction) |
| 6443 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6444 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 6445 | continue; |
| 6446 | } |
| 6447 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6448 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6449 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
| 6450 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
| 6451 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, VD->getName(), |
| 6452 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6453 | // Add initializer for private variable. |
| 6454 | Expr *Init = nullptr; |
| 6455 | switch (BOK) { |
| 6456 | case BO_Add: |
| 6457 | case BO_Xor: |
| 6458 | case BO_Or: |
| 6459 | case BO_LOr: |
| 6460 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 6461 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6462 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6463 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6464 | break; |
| 6465 | case BO_Mul: |
| 6466 | case BO_LAnd: |
| 6467 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 6468 | // '*' and '&&' reduction ops - initializer is '1'. |
| 6469 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
| 6470 | } |
| 6471 | break; |
| 6472 | case BO_And: { |
| 6473 | // '&' reduction op - initializer is '~0'. |
| 6474 | QualType OrigType = Type; |
| 6475 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) { |
| 6476 | Type = ComplexTy->getElementType(); |
| 6477 | } |
| 6478 | if (Type->isRealFloatingType()) { |
| 6479 | llvm::APFloat InitValue = |
| 6480 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 6481 | /*isIEEE=*/true); |
| 6482 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6483 | Type, ELoc); |
| 6484 | } else if (Type->isScalarType()) { |
| 6485 | auto Size = Context.getTypeSize(Type); |
| 6486 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 6487 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 6488 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6489 | } |
| 6490 | if (Init && OrigType->isAnyComplexType()) { |
| 6491 | // Init = 0xFFFF + 0xFFFFi; |
| 6492 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 6493 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 6494 | } |
| 6495 | Type = OrigType; |
| 6496 | break; |
| 6497 | } |
| 6498 | case BO_LT: |
| 6499 | case BO_GT: { |
| 6500 | // 'min' reduction op - initializer is 'Largest representable number in |
| 6501 | // the reduction list item type'. |
| 6502 | // 'max' reduction op - initializer is 'Least representable number in |
| 6503 | // the reduction list item type'. |
| 6504 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 6505 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 6506 | auto Size = Context.getTypeSize(Type); |
| 6507 | QualType IntTy = |
| 6508 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 6509 | llvm::APInt InitValue = |
| 6510 | (BOK != BO_LT) |
| 6511 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 6512 | : llvm::APInt::getMinValue(Size) |
| 6513 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 6514 | : llvm::APInt::getMaxValue(Size); |
| 6515 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 6516 | if (Type->isPointerType()) { |
| 6517 | // Cast to pointer type. |
| 6518 | auto CastExpr = BuildCStyleCastExpr( |
| 6519 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 6520 | SourceLocation(), Init); |
| 6521 | if (CastExpr.isInvalid()) |
| 6522 | continue; |
| 6523 | Init = CastExpr.get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6524 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6525 | } else if (Type->isRealFloatingType()) { |
| 6526 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 6527 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 6528 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 6529 | Type, ELoc); |
| 6530 | } |
| 6531 | break; |
| 6532 | } |
| 6533 | case BO_PtrMemD: |
| 6534 | case BO_PtrMemI: |
| 6535 | case BO_MulAssign: |
| 6536 | case BO_Div: |
| 6537 | case BO_Rem: |
| 6538 | case BO_Sub: |
| 6539 | case BO_Shl: |
| 6540 | case BO_Shr: |
| 6541 | case BO_LE: |
| 6542 | case BO_GE: |
| 6543 | case BO_EQ: |
| 6544 | case BO_NE: |
| 6545 | case BO_AndAssign: |
| 6546 | case BO_XorAssign: |
| 6547 | case BO_OrAssign: |
| 6548 | case BO_Assign: |
| 6549 | case BO_AddAssign: |
| 6550 | case BO_SubAssign: |
| 6551 | case BO_DivAssign: |
| 6552 | case BO_RemAssign: |
| 6553 | case BO_ShlAssign: |
| 6554 | case BO_ShrAssign: |
| 6555 | case BO_Comma: |
| 6556 | llvm_unreachable("Unexpected reduction operation"); |
| 6557 | } |
| 6558 | if (Init) { |
| 6559 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 6560 | /*TypeMayContainAuto=*/false); |
| 6561 | } else { |
| 6562 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
| 6563 | } |
| 6564 | if (!RHSVD->hasInit()) { |
| 6565 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 6566 | << ReductionIdRange; |
| 6567 | bool IsDecl = |
| 6568 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6569 | Diag(VD->getLocation(), |
| 6570 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6571 | << VD; |
| 6572 | continue; |
| 6573 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6574 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 6575 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6576 | ExprResult ReductionOp = |
| 6577 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), BOK, |
| 6578 | LHSDRE, RHSDRE); |
| 6579 | if (ReductionOp.isUsable()) { |
Alexey Bataev | 69a4779 | 2015-05-07 03:54:03 +0000 | [diff] [blame] | 6580 | if (BOK != BO_LT && BOK != BO_GT) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6581 | ReductionOp = |
| 6582 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6583 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 6584 | } else { |
| 6585 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 6586 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 6587 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 6588 | ReductionOp = |
| 6589 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 6590 | BO_Assign, LHSDRE, ConditionalOp); |
| 6591 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6592 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6593 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6594 | if (ReductionOp.isInvalid()) |
| 6595 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6596 | |
| 6597 | DSAStack->addDSA(VD, DE, OMPC_reduction); |
| 6598 | Vars.push_back(DE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6599 | LHSs.push_back(LHSDRE); |
| 6600 | RHSs.push_back(RHSDRE); |
| 6601 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6602 | } |
| 6603 | |
| 6604 | if (Vars.empty()) |
| 6605 | return nullptr; |
| 6606 | |
| 6607 | return OMPReductionClause::Create( |
| 6608 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 6609 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, LHSs, |
| 6610 | RHSs, ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6611 | } |
| 6612 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6613 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 6614 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 6615 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 6616 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6617 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6618 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6619 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6620 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 6621 | LinKind == OMPC_LINEAR_unknown) { |
| 6622 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 6623 | LinKind = OMPC_LINEAR_val; |
| 6624 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6625 | for (auto &RefExpr : VarList) { |
| 6626 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 6627 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6628 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6629 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6630 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6631 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6632 | continue; |
| 6633 | } |
| 6634 | |
| 6635 | // OpenMP [2.14.3.7, linear clause] |
| 6636 | // A list item that appears in a linear clause is subject to the private |
| 6637 | // clause semantics described in Section 2.14.3.3 on page 159 except as |
| 6638 | // noted. In addition, the value of the new list item on each iteration |
| 6639 | // of the associated loop(s) corresponds to the value of the original |
| 6640 | // list item before entering the construct plus the logical number of |
| 6641 | // the iteration times linear-step. |
| 6642 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6643 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6644 | // OpenMP [2.1, C/C++] |
| 6645 | // A list item is a variable name. |
| 6646 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 6647 | // A variable that is part of another variable (as an array or |
| 6648 | // structure element) cannot appear in a private clause. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6649 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6650 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6651 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6652 | continue; |
| 6653 | } |
| 6654 | |
| 6655 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6656 | |
| 6657 | // OpenMP [2.14.3.7, linear clause] |
| 6658 | // A list-item cannot appear in more than one linear clause. |
| 6659 | // A list-item that appears in a linear clause cannot appear in any |
| 6660 | // other data-sharing attribute clause. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6661 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(VD, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6662 | if (DVar.RefExpr) { |
| 6663 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 6664 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 6665 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6666 | continue; |
| 6667 | } |
| 6668 | |
| 6669 | QualType QType = VD->getType(); |
| 6670 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 6671 | // It will be analyzed later. |
| 6672 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6673 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6674 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6675 | continue; |
| 6676 | } |
| 6677 | |
| 6678 | // A variable must not have an incomplete type or a reference type. |
| 6679 | if (RequireCompleteType(ELoc, QType, |
| 6680 | diag::err_omp_linear_incomplete_type)) { |
| 6681 | continue; |
| 6682 | } |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 6683 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 6684 | !QType->isReferenceType()) { |
| 6685 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 6686 | << QType << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 6687 | continue; |
| 6688 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6689 | QType = QType.getNonReferenceType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6690 | |
| 6691 | // A list item must not be const-qualified. |
| 6692 | if (QType.isConstant(Context)) { |
| 6693 | Diag(ELoc, diag::err_omp_const_variable) |
| 6694 | << getOpenMPClauseName(OMPC_linear); |
| 6695 | bool IsDecl = |
| 6696 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6697 | Diag(VD->getLocation(), |
| 6698 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6699 | << VD; |
| 6700 | continue; |
| 6701 | } |
| 6702 | |
| 6703 | // A list item must be of integral or pointer type. |
| 6704 | QType = QType.getUnqualifiedType().getCanonicalType(); |
| 6705 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6706 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 6707 | !Ty->isPointerType())) { |
| 6708 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << QType; |
| 6709 | bool IsDecl = |
| 6710 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6711 | Diag(VD->getLocation(), |
| 6712 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6713 | << VD; |
| 6714 | continue; |
| 6715 | } |
| 6716 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6717 | // Build private copy of original var. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6718 | auto *Private = buildVarDecl(*this, ELoc, QType, VD->getName(), |
| 6719 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6720 | auto *PrivateRef = buildDeclRefExpr( |
| 6721 | *this, Private, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6722 | // Build var to save initial value. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6723 | VarDecl *Init = buildVarDecl(*this, ELoc, QType, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6724 | Expr *InitExpr; |
| 6725 | if (LinKind == OMPC_LINEAR_uval) |
| 6726 | InitExpr = VD->getInit(); |
| 6727 | else |
| 6728 | InitExpr = DE; |
| 6729 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6730 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6731 | auto InitRef = buildDeclRefExpr( |
| 6732 | *this, Init, DE->getType().getUnqualifiedType(), DE->getExprLoc()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6733 | DSAStack->addDSA(VD, DE, OMPC_linear); |
| 6734 | Vars.push_back(DE); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6735 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6736 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6737 | } |
| 6738 | |
| 6739 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6740 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6741 | |
| 6742 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6743 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6744 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 6745 | !Step->isInstantiationDependent() && |
| 6746 | !Step->containsUnexpandedParameterPack()) { |
| 6747 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6748 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6749 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6750 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6751 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6752 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6753 | // Build var to save the step value. |
| 6754 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6755 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6756 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6757 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6758 | ExprResult CalcStep = |
| 6759 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6760 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6761 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6762 | // Warn about zero linear step (it would be probably better specified as |
| 6763 | // making corresponding variables 'const'). |
| 6764 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6765 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 6766 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6767 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 6768 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6769 | if (!IsConstant && CalcStep.isUsable()) { |
| 6770 | // Calculate the step beforehand instead of doing this on each iteration. |
| 6771 | // (This is not used if the number of iterations may be kfold-ed). |
| 6772 | CalcStepExpr = CalcStep.get(); |
| 6773 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6774 | } |
| 6775 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 6776 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 6777 | ColonLoc, EndLoc, Vars, Privates, Inits, |
| 6778 | StepExpr, CalcStepExpr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6779 | } |
| 6780 | |
| 6781 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 6782 | Expr *NumIterations, Sema &SemaRef, |
| 6783 | Scope *S) { |
| 6784 | // Walk the vars and build update/final expressions for the CodeGen. |
| 6785 | SmallVector<Expr *, 8> Updates; |
| 6786 | SmallVector<Expr *, 8> Finals; |
| 6787 | Expr *Step = Clause.getStep(); |
| 6788 | Expr *CalcStep = Clause.getCalcStep(); |
| 6789 | // OpenMP [2.14.3.7, linear clause] |
| 6790 | // If linear-step is not specified it is assumed to be 1. |
| 6791 | if (Step == nullptr) |
| 6792 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
| 6793 | else if (CalcStep) |
| 6794 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
| 6795 | bool HasErrors = false; |
| 6796 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6797 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6798 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6799 | for (auto &RefExpr : Clause.varlists()) { |
| 6800 | Expr *InitExpr = *CurInit; |
| 6801 | |
| 6802 | // Build privatized reference to the current linear var. |
| 6803 | auto DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 6804 | Expr *CapturedRef; |
| 6805 | if (LinKind == OMPC_LINEAR_uval) |
| 6806 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 6807 | else |
| 6808 | CapturedRef = |
| 6809 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 6810 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 6811 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6812 | |
| 6813 | // Build update: Var = InitExpr + IV * Step |
| 6814 | ExprResult Update = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6815 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6816 | InitExpr, IV, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6817 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 6818 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6819 | |
| 6820 | // Build final: Var = InitExpr + NumIterations * Step |
| 6821 | ExprResult Final = |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6822 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6823 | InitExpr, NumIterations, Step, /* Subtract */ false); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6824 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 6825 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6826 | if (!Update.isUsable() || !Final.isUsable()) { |
| 6827 | Updates.push_back(nullptr); |
| 6828 | Finals.push_back(nullptr); |
| 6829 | HasErrors = true; |
| 6830 | } else { |
| 6831 | Updates.push_back(Update.get()); |
| 6832 | Finals.push_back(Final.get()); |
| 6833 | } |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 6834 | ++CurInit, ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 6835 | } |
| 6836 | Clause.setUpdates(Updates); |
| 6837 | Clause.setFinals(Finals); |
| 6838 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6839 | } |
| 6840 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6841 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 6842 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 6843 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 6844 | |
| 6845 | SmallVector<Expr *, 8> Vars; |
| 6846 | for (auto &RefExpr : VarList) { |
| 6847 | assert(RefExpr && "NULL expr in OpenMP aligned clause."); |
| 6848 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 6849 | // It will be analyzed later. |
| 6850 | Vars.push_back(RefExpr); |
| 6851 | continue; |
| 6852 | } |
| 6853 | |
| 6854 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 6855 | // OpenMP [2.1, C/C++] |
| 6856 | // A list item is a variable name. |
| 6857 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 6858 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 6859 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 6860 | continue; |
| 6861 | } |
| 6862 | |
| 6863 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 6864 | |
| 6865 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6866 | // The type of list items appearing in the aligned clause must be |
| 6867 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6868 | QualType QType = VD->getType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6869 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6870 | const Type *Ty = QType.getTypePtrOrNull(); |
| 6871 | if (!Ty || (!Ty->isDependentType() && !Ty->isArrayType() && |
| 6872 | !Ty->isPointerType())) { |
| 6873 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
| 6874 | << QType << getLangOpts().CPlusPlus << RefExpr->getSourceRange(); |
| 6875 | bool IsDecl = |
| 6876 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 6877 | Diag(VD->getLocation(), |
| 6878 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 6879 | << VD; |
| 6880 | continue; |
| 6881 | } |
| 6882 | |
| 6883 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 6884 | // A list-item cannot appear in more than one aligned clause. |
| 6885 | if (DeclRefExpr *PrevRef = DSAStack->addUniqueAligned(VD, DE)) { |
| 6886 | Diag(ELoc, diag::err_omp_aligned_twice) << RefExpr->getSourceRange(); |
| 6887 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 6888 | << getOpenMPClauseName(OMPC_aligned); |
| 6889 | continue; |
| 6890 | } |
| 6891 | |
| 6892 | Vars.push_back(DE); |
| 6893 | } |
| 6894 | |
| 6895 | // OpenMP [2.8.1, simd construct, Description] |
| 6896 | // The parameter of the aligned clause, alignment, must be a constant |
| 6897 | // positive integer expression. |
| 6898 | // If no optional parameter is specified, implementation-defined default |
| 6899 | // alignments for SIMD instructions on the target platforms are assumed. |
| 6900 | if (Alignment != nullptr) { |
| 6901 | ExprResult AlignResult = |
| 6902 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 6903 | if (AlignResult.isInvalid()) |
| 6904 | return nullptr; |
| 6905 | Alignment = AlignResult.get(); |
| 6906 | } |
| 6907 | if (Vars.empty()) |
| 6908 | return nullptr; |
| 6909 | |
| 6910 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 6911 | EndLoc, Vars, Alignment); |
| 6912 | } |
| 6913 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6914 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 6915 | SourceLocation StartLoc, |
| 6916 | SourceLocation LParenLoc, |
| 6917 | SourceLocation EndLoc) { |
| 6918 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6919 | SmallVector<Expr *, 8> SrcExprs; |
| 6920 | SmallVector<Expr *, 8> DstExprs; |
| 6921 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6922 | for (auto &RefExpr : VarList) { |
| 6923 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 6924 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6925 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6926 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6927 | SrcExprs.push_back(nullptr); |
| 6928 | DstExprs.push_back(nullptr); |
| 6929 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6930 | continue; |
| 6931 | } |
| 6932 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6933 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6934 | // OpenMP [2.1, C/C++] |
| 6935 | // A list item is a variable name. |
| 6936 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 6937 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6938 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6939 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6940 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6941 | continue; |
| 6942 | } |
| 6943 | |
| 6944 | Decl *D = DE->getDecl(); |
| 6945 | VarDecl *VD = cast<VarDecl>(D); |
| 6946 | |
| 6947 | QualType Type = VD->getType(); |
| 6948 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 6949 | // It will be analyzed later. |
| 6950 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6951 | SrcExprs.push_back(nullptr); |
| 6952 | DstExprs.push_back(nullptr); |
| 6953 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6954 | continue; |
| 6955 | } |
| 6956 | |
| 6957 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 6958 | // A list item that appears in a copyin clause must be threadprivate. |
| 6959 | if (!DSAStack->isThreadPrivate(VD)) { |
| 6960 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6961 | << getOpenMPClauseName(OMPC_copyin) |
| 6962 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6963 | continue; |
| 6964 | } |
| 6965 | |
| 6966 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 6967 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 6968 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6969 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6970 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6971 | auto *SrcVD = |
| 6972 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 6973 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 6974 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6975 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 6976 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 6977 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 6978 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6979 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 6980 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6981 | // For arrays generate assignment operation for single element and replace |
| 6982 | // it by the original array element in CodeGen. |
| 6983 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 6984 | PseudoDstExpr, PseudoSrcExpr); |
| 6985 | if (AssignmentOp.isInvalid()) |
| 6986 | continue; |
| 6987 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 6988 | /*DiscardedValue=*/true); |
| 6989 | if (AssignmentOp.isInvalid()) |
| 6990 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6991 | |
| 6992 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 6993 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 6994 | SrcExprs.push_back(PseudoSrcExpr); |
| 6995 | DstExprs.push_back(PseudoDstExpr); |
| 6996 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6997 | } |
| 6998 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6999 | if (Vars.empty()) |
| 7000 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7001 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 7002 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7003 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7004 | } |
| 7005 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7006 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 7007 | SourceLocation StartLoc, |
| 7008 | SourceLocation LParenLoc, |
| 7009 | SourceLocation EndLoc) { |
| 7010 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7011 | SmallVector<Expr *, 8> SrcExprs; |
| 7012 | SmallVector<Expr *, 8> DstExprs; |
| 7013 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7014 | for (auto &RefExpr : VarList) { |
| 7015 | assert(RefExpr && "NULL expr in OpenMP copyprivate clause."); |
| 7016 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7017 | // It will be analyzed later. |
| 7018 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7019 | SrcExprs.push_back(nullptr); |
| 7020 | DstExprs.push_back(nullptr); |
| 7021 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7022 | continue; |
| 7023 | } |
| 7024 | |
| 7025 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7026 | // OpenMP [2.1, C/C++] |
| 7027 | // A list item is a variable name. |
| 7028 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 7029 | // A list item that appears in a copyin clause must be threadprivate. |
| 7030 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
| 7031 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
| 7032 | Diag(ELoc, diag::err_omp_expected_var_name) << RefExpr->getSourceRange(); |
| 7033 | continue; |
| 7034 | } |
| 7035 | |
| 7036 | Decl *D = DE->getDecl(); |
| 7037 | VarDecl *VD = cast<VarDecl>(D); |
| 7038 | |
| 7039 | QualType Type = VD->getType(); |
| 7040 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 7041 | // It will be analyzed later. |
| 7042 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7043 | SrcExprs.push_back(nullptr); |
| 7044 | DstExprs.push_back(nullptr); |
| 7045 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7046 | continue; |
| 7047 | } |
| 7048 | |
| 7049 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 7050 | // A list item that appears in a copyprivate clause may not appear in a |
| 7051 | // private or firstprivate clause on the single construct. |
| 7052 | if (!DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7053 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7054 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 7055 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7056 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7057 | << getOpenMPClauseName(DVar.CKind) |
| 7058 | << getOpenMPClauseName(OMPC_copyprivate); |
| 7059 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7060 | continue; |
| 7061 | } |
| 7062 | |
| 7063 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 7064 | // All list items that appear in a copyprivate clause must be either |
| 7065 | // threadprivate or private in the enclosing context. |
| 7066 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7067 | DVar = DSAStack->getImplicitDSA(VD, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7068 | if (DVar.CKind == OMPC_shared) { |
| 7069 | Diag(ELoc, diag::err_omp_required_access) |
| 7070 | << getOpenMPClauseName(OMPC_copyprivate) |
| 7071 | << "threadprivate or private in the enclosing context"; |
| 7072 | ReportOriginalDSA(*this, DSAStack, VD, DVar); |
| 7073 | continue; |
| 7074 | } |
| 7075 | } |
| 7076 | } |
| 7077 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7078 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7079 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7080 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7081 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 7082 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 7083 | bool IsDecl = |
| 7084 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 7085 | Diag(VD->getLocation(), |
| 7086 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 7087 | << VD; |
| 7088 | continue; |
| 7089 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7090 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7091 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 7092 | // A variable of class type (or array thereof) that appears in a |
| 7093 | // copyin clause requires an accessible, unambiguous copy assignment |
| 7094 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7095 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 7096 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7097 | auto *SrcVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7098 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.src", |
| 7099 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7100 | auto *PseudoSrcExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7101 | buildDeclRefExpr(*this, SrcVD, Type, DE->getExprLoc()); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7102 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 7103 | buildVarDecl(*this, DE->getLocStart(), Type, ".copyprivate.dst", |
| 7104 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 7105 | auto *PseudoDstExpr = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7106 | buildDeclRefExpr(*this, DstVD, Type, DE->getExprLoc()); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7107 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 7108 | PseudoDstExpr, PseudoSrcExpr); |
| 7109 | if (AssignmentOp.isInvalid()) |
| 7110 | continue; |
| 7111 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 7112 | /*DiscardedValue=*/true); |
| 7113 | if (AssignmentOp.isInvalid()) |
| 7114 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7115 | |
| 7116 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 7117 | // implicitly private. |
| 7118 | Vars.push_back(DE); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7119 | SrcExprs.push_back(PseudoSrcExpr); |
| 7120 | DstExprs.push_back(PseudoDstExpr); |
| 7121 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7122 | } |
| 7123 | |
| 7124 | if (Vars.empty()) |
| 7125 | return nullptr; |
| 7126 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 7127 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 7128 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7129 | } |
| 7130 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7131 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 7132 | SourceLocation StartLoc, |
| 7133 | SourceLocation LParenLoc, |
| 7134 | SourceLocation EndLoc) { |
| 7135 | if (VarList.empty()) |
| 7136 | return nullptr; |
| 7137 | |
| 7138 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 7139 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7140 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7141 | OMPClause * |
| 7142 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 7143 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 7144 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 7145 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 7146 | if (DepKind == OMPC_DEPEND_unknown) { |
| 7147 | std::string Values; |
| 7148 | std::string Sep(", "); |
| 7149 | for (unsigned i = 0; i < OMPC_DEPEND_unknown; ++i) { |
| 7150 | Values += "'"; |
| 7151 | Values += getOpenMPSimpleClauseTypeName(OMPC_depend, i); |
| 7152 | Values += "'"; |
| 7153 | switch (i) { |
| 7154 | case OMPC_DEPEND_unknown - 2: |
| 7155 | Values += " or "; |
| 7156 | break; |
| 7157 | case OMPC_DEPEND_unknown - 1: |
| 7158 | break; |
| 7159 | default: |
| 7160 | Values += Sep; |
| 7161 | break; |
| 7162 | } |
| 7163 | } |
| 7164 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
| 7165 | << Values << getOpenMPClauseName(OMPC_depend); |
| 7166 | return nullptr; |
| 7167 | } |
| 7168 | SmallVector<Expr *, 8> Vars; |
| 7169 | for (auto &RefExpr : VarList) { |
| 7170 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
| 7171 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
| 7172 | // It will be analyzed later. |
| 7173 | Vars.push_back(RefExpr); |
| 7174 | continue; |
| 7175 | } |
| 7176 | |
| 7177 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 7178 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 7179 | // A variable that is part of another variable (such as a field of a |
| 7180 | // structure) but is not an array element or an array section cannot appear |
| 7181 | // in a depend clause. |
| 7182 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7183 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 7184 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 7185 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 7186 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 7187 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7188 | (ASE && !ASE->getBase()->getType()->isAnyPointerType() && |
| 7189 | !ASE->getBase()->getType()->isArrayType())) { |
| 7190 | Diag(ELoc, diag::err_omp_expected_var_name_or_array_item) |
| 7191 | << RefExpr->getSourceRange(); |
| 7192 | continue; |
| 7193 | } |
| 7194 | |
| 7195 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 7196 | } |
| 7197 | |
| 7198 | if (Vars.empty()) |
| 7199 | return nullptr; |
| 7200 | |
| 7201 | return OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, DepKind, |
| 7202 | DepLoc, ColonLoc, Vars); |
| 7203 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7204 | |
| 7205 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 7206 | SourceLocation LParenLoc, |
| 7207 | SourceLocation EndLoc) { |
| 7208 | Expr *ValExpr = Device; |
| 7209 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7210 | !ValExpr->isInstantiationDependent()) { |
| 7211 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7212 | ExprResult Value = PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7213 | if (Value.isInvalid()) |
| 7214 | return nullptr; |
| 7215 | |
| 7216 | // OpenMP [2.9.1, Restrictions] |
| 7217 | // The device expression must evaluate to a non-negative integer value. |
| 7218 | llvm::APSInt Result; |
| 7219 | if (Value.get()->isIntegerConstantExpr(Result, Context) && |
| 7220 | Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7221 | Diag(Loc, diag::err_omp_negative_expression_in_clause) |
| 7222 | << "device" << ValExpr->getSourceRange(); |
| 7223 | return nullptr; |
| 7224 | } |
| 7225 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7226 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7227 | } |